python - pandas_ml 中的 cross_validation 问题

标签 python python-2.7 pandas machine-learning scikit-learn

我尝试使用 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

这里有什么技巧吗?

最佳答案

这是因为accuracy指标仅用于对分类模型进行评分。它衡量正确预测的比例。在回归中,您想知道的不是您的预测中有多少是正确的,而是您的预测与正确答案相距多远 - 它们中的任何一个都不可能完全正确,因此这不是一个有意义的指标。

Regression metrics包括r2mean_squared_errormean_absolute_error

你可以使用类似的东西:

scores = df.cross_validation.cross_val_score(estimator=estimator, cv=7, scoring='r2')

关于python - pandas_ml 中的 cross_validation 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34502662/

相关文章:

python - 使用 For 循环修改 Pandas 中的 DataFrame 字典

python - 在 Python 中创建具有嵌套属性的空对象

python - 通过理解避免将重复项插入 Python 列表

python - 有没有办法判断用 Mechanize 打开的页面是否没有返回 "search results"?

python - “ float ”对象没有属性 'strip'

python - 使用 Pandas 时 dateutil.tz 包显然丢失了?

python - 我无法在 for 循环中增加列表中的特定值

python - 合并不同长度的python列表

python - Django:高效的模板/字符串分离和覆盖

python - 找到满足 A + B =C + D 的值的索引