我想将带有10倍分层交叉验证的Naive Bayes应用到我的数据中,然后我想看看模型如何处理我最初设置的测试数据。
然而,我得到的结果(即预测结果和概率值y_pred_nb2
和y_score_nb2
)与我在没有任何交叉验证的情况下运行代码时相同。
问题:我该如何纠正?
代码如下,其中X_train
包含整个数据集的75%,而X_test
包含25%。
from sklearn.model_selection import StratifiedKFold
params = {}
#gridsearch searches for the best hyperparameters and keeps the classifier with the highest recall score
skf = StratifiedKFold(n_splits=10)
nb2 = GridSearchCV(GaussianNB(), cv=skf, param_grid=params)
%time nb2.fit(X_train, y_train)
# predict values on the test set
y_pred_nb2 = nb2.predict(X_test)
print(y_pred_nb2)
# predicted probabilities on the test set
y_scores_nb2 = nb2.predict_proba(X_test)[:, 1]
print(y_scores_nb2)
目前没有回答
相关问题 更多 >
编程相关推荐