【发布时间】:2017-07-10 18:19:06
【问题描述】:
作为安然项目的一部分,构建了附加模型,以下是步骤摘要,
以下模型给出了非常完美的分数
cv = StratifiedShuffleSplit(n_splits = 100, test_size = 0.2, random_state = 42)
gcv = GridSearchCV(pipe, clf_params,cv=cv)
gcv.fit(features,labels) ---> with the full dataset
for train_ind, test_ind in cv.split(features,labels):
x_train, x_test = features[train_ind], features[test_ind]
y_train, y_test = labels[train_ind],labels[test_ind]
gcv.best_estimator_.predict(x_test)
以下模型给出的分数更合理但分数较低
cv = StratifiedShuffleSplit(n_splits = 100, test_size = 0.2, random_state = 42)
gcv = GridSearchCV(pipe, clf_params,cv=cv)
gcv.fit(features,labels) ---> with the full dataset
for train_ind, test_ind in cv.split(features,labels):
x_train, x_test = features[train_ind], features[test_ind]
y_train, y_test = labels[train_ind],labels[test_ind]
gcv.best_estimator_.fit(x_train,y_train)
gcv.best_estimator_.predict(x_test)
使用 Kbest 找出分数并对特征进行排序并尝试高低分数的组合。
将 SVM 与使用 StratifiedShuffle 的 GridSearch 结合使用
使用 best_estimator_ 预测和计算准确率和召回率。
问题是估算器给出了完美的分数,在某些情况下是 1
但是,当我根据训练数据重新拟合最佳分类器然后运行测试时,它会给出合理的分数。
我的疑问/问题是 GridSearch 在使用我们发送给它的 Shuffle 拆分对象拆分后对测试数据做了什么。我认为它不适合测试数据,如果这是真的,那么当我预测使用相同的测试数据时,它不应该给出这么高的分数。?因为我使用了 random_state 值,所以 shufflesplit 应该为网格拟合和预测创建了相同的副本。
那么,对两个错误使用相同的 Shufflesplit 吗?
【问题讨论】:
标签: python machine-learning scikit-learn cross-validation grid-search