Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 交叉评分的准确性差_Python_Python 3.x_Machine Learning_Cross Validation - Fatal编程技术网

Python 交叉评分的准确性差

Python 交叉评分的准确性差,python,python-3.x,machine-learning,cross-validation,Python,Python 3.x,Machine Learning,Cross Validation,对于机器学习分类,我使用10倍的交叉验证: kfold = StratifiedKFold(n_splits=10) I分离列车/试验数据: X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, y, test_size=0.3 ) 对于分类器,获得10倍精度平均值: cross_val_score(classifier, X_train, y=Y_train, scoring='accuracy', c

对于机器学习分类,我使用10倍的交叉验证:

kfold = StratifiedKFold(n_splits=10)
I分离列车/试验数据:

X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, y, test_size=0.3 )
对于分类器,获得10倍精度平均值:

cross_val_score(classifier, X_train, y=Y_train, scoring='accuracy', cv=kfold, n_jobs=4))
这给了我一个0,62的准确平均值

为了确认精度值,我启动了一个预测:

Y_pred_train = classifier.predict(X_train)

print(metrics.classification_report(Y_train, Y_pred_train))
我得到: 精确回忆f1分数支持

       0       0.92      0.96      0.94      2523
       1       0.95      0.89      0.92      1923

accuracy                           0.93      4446
宏平均值0.93 0.93 0.93 4446 加权平均值0.93 0.93 0.93 4446

这个精度与上面的不匹配。 怎么解释呢? 谢谢。
Théo

这里的问题是,您在
X_train
上训练模型,然后在完全相同的数据集上运行预测:

Y\u pred\u train=分类器。预测(X\u train)
你显然得到了一个很好的分数,因为模型可以很好地适应训练数据。机器学习的重点是处理以前看不见的数据,即在训练时已知数据之间进行概括。要解决此问题,只需对测试数据运行预测和报告:

Y_pred_test=分类器.预测(X_test)
打印(度量。分类报告(Y_测试,Y_预测测试))
谢谢你。 事实上,我想比较cross_val_score()和.predict()函数得到的精度值。 对我来说,在同一个火车数据集上,两者应该是相同的

但cross_val_score()函数和predict()分类器函数得到的精度值不同

看,我在同一个火车数据集上训练cross_val_score()和predict()。 交叉值得分的准确度值(,X\u列,y=y\u列,得分='准确度',cv=kfold,n\u作业=4)) =>给我0,62

预测精度值(X_列) =>给我0.92(在我搜索分类器的最佳超参数之后)

当我调用时,cross_val_分数的低精度值是否可以用默认的超参数来解释 交叉评分(,X\u列,y=y\u列,评分=准确度,cv=kfold,n\u作业=4))

非常感谢。 提奥