clw*_*wen 25 python regression scikit-learn
如何使用cross_val_score
回归?默认评分似乎是准确性,这对回归来说没有多大意义.据说我想使用均方误差,是否可以指定cross_val_score
?
试过以下两个但不起作用:
scores = cross_validation.cross_val_score(svr, diabetes.data, diabetes.target, cv=5, scoring='mean_squared_error')
Run Code Online (Sandbox Code Playgroud)
和
scores = cross_validation.cross_val_score(svr, diabetes.data, diabetes.target, cv=5, scoring=metrics.mean_squared_error)
Run Code Online (Sandbox Code Playgroud)
第一个生成负数列表,而均方误差应始终为非负数.第二个抱怨说:
mean_squared_error() takes exactly 2 arguments (3 given)
Run Code Online (Sandbox Code Playgroud)
Sir*_*rah 35
我没有评论的声誉,但我想为你和/或一个路人提供这个链接,其中讨论了scikit中MSE的负面输出 - https://github.com/scikit-learn/scikit-learn/问题/ 2439
另外(为了使这个真正的答案)你的第一个选项是正确的,因为MSE不仅是你想要用来比较模型的度量,而且R ^ 2不能根据(我认为)对于你的交叉类型来计算正在使用.
如果您选择MSE作为记分员,它会输出一个错误列表,然后您可以采用它们的平均值,如下所示:
# Doing linear regression with leave one out cross val
from sklearn import cross_validation, linear_model
import numpy as np
# Including this to remind you that it is necessary to use numpy arrays rather
# than lists otherwise you will get an error
X_digits = np.array(x)
Y_digits = np.array(y)
loo = cross_validation.LeaveOneOut(len(Y_digits))
regr = linear_model.LinearRegression()
scores = cross_validation.cross_val_score(regr, X_digits, Y_digits, scoring='mean_squared_error', cv=loo,)
# This will print the mean of the list of errors that were output and
# provide your metric for evaluation
print scores.mean()
Run Code Online (Sandbox Code Playgroud)
And*_*ler 10
第一个是正确的.它输出MSE的负数,因为它总是试图最大化得分.请通过建议改进文档来帮助我们.