我尝试使用pandas_ml
库完成交叉验证
df = pdml.ModelFrame(features, target)estimators = {'SVM: SVR': df.svm.SVR(), 'SVM: LinearSVR': df.svm.LinearSVR()}for label, estimator in estimators.iteritems(): scores = df.cross_validation.cross_val_score(estimator=estimator, cv=7, scoring='accuracy') print("Accuracy: %0.2f (+/- %0.2f) [%s]" % (scores.mean(), scores.std(), label))
然而,我得到了意外的错误
raise ValueError(“{0} is not supported”.format(y_type))
ValueError: continuous is not supported
有什么技巧吗?
回答:
这是因为准确率指标仅用于评分分类模型。它测量正确预测的比例。在回归中,你不关心预测的正确比例,而是想知道你的预测与正确答案相差多远——因为不太可能有任何预测会完全正确,所以这不是一个有意义的指标。
回归指标包括r2
、mean_squared_error
、mean_absolute_error
等。
你可以使用如下代码:
scores = df.cross_validation.cross_val_score(estimator=estimator, cv=7, scoring='r2')