main.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:coursera-machine-learning-yandex 作者: dstarcev 项目源码 文件源码
def calculate(X, y):
    best_p, best_score = 0, -float('inf')
    kf = KFold(len(y), n_folds=5, shuffle=True, random_state=42)
    for p in numpy.linspace(1, 10, num=200):
        knr = KNeighborsRegressor(n_neighbors=5, weights='distance', p=p)
        score = max(cross_val_score(knr, X, y, cv=kf, scoring='mean_squared_error'))
        if score > best_score:
            best_score = score
            best_p = p

    return best_p, best_score
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号