简体   繁体   English

如何在机器学习中使用 cross_val_score 进行预测

[英]how use cross_val_score to predict in machine learning

in my course i learned how to use cross validation to increase the accuracy of my model, everything looks beautiful in training.在我的课程中,我学习了如何使用交叉验证来提高模型的准确性,训练中的一切看起来都很漂亮。 But when I go to practice in training I find that I can't use the models trained with cross-validation, follow my code:但是当我去实践训练时我发现我不能使用经过交叉验证训练的模型,请按照我的代码:

X = array[:,0:8]
Y = array[:,8]


num_folds = 10
seed = 7


kfold = KFold(num_folds, True, random_state = seed)


modelo = LogisticRegression()


resultado = cross_val_score(modelo, X, Y, cv = kfold)


print("Acurácia: %.3f" % (resultado.mean() * 100))

in this cross-validation logic how can i use the model trained in my test data?在这个交叉验证逻辑中,我如何使用在我的测试数据中训练的模型?

I'm trying something like modelo.predict(X_test) but not success我正在尝试类似modelo.predict(X_test)但没有成功

can anyone help me?谁能帮我?

You need to fit the model to the data before you can use the .predict function.您需要先将模型与数据拟合,然后才能使用.predict函数。 I believe you're using scikit learn, so:我相信你正在使用 scikit learn,所以:

clf = LogisticRegression()
clf = clf.fit(X, y)
clf.predict(X[:2, :])

From scikit documentation here.来自此处的 scikit 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM