![](/img/trans.png)
[英]GridSearch over RegressorChain using Scikit-Learn?
[英]Model help using Scikit-learn when using GridSearch
作為安然項目的一部分,構建了附加模型,下面是步驟的摘要,
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查找分數並對功能進行排序並嘗試更高和更低分數的組合。
使用StratifiedShuffle將SVM與GridSearch一起使用
使用best_estimator_來預測和計算精度和召回率。
問題是估算器正在吐出完美的分數,在某些情況下是1
但是當我在訓練數據上重新設置最佳分類器時,運行測試會得到合理的分數。
我的疑問/問題是GridSearch在使用我們發送給它的Shuffle拆分對象進行拆分后對測試數據做了什么。 我認為它不適合測試數據,如果確實如此,那么當我預測使用相同的測試數據時,它不應該給出這么高的分數。 因為我使用了random_state值,所以shufflesplit應該為Grid適合和預測創建相同的副本。
那么,是否使用相同的Shufflesplit兩個錯誤?
GridSearchCV為@ Gauthier Feuillen說,用於搜索給定數據的估計器的最佳參數。 GridSearchCV的描述: -
gcv = GridSearchCV(pipe, clf_params,cv=cv)
gcv.fit(features,labels)
clf_params
以使用ParameterGrid分離所有可能的組合。 features
現在將使用cv
分為features_train
和features_test
。 labels
features_train
和labels_inner
進行訓練,並使用features_test
和labels_test
。 cv_iterations
重復步驟4和5 。 將計算cv迭代中的平均得分,其將被分配給該參數組合。 這可以使用cv_results_
屬性訪問。 由於上一步,您在第一和第二種方法中獲得不同的分數 。 因為在第一種方法中,所有數據都用於訓練,並且您僅預測該數據。 第二種方法對先前看不見的數據進行預測。
基本上網格搜索將:
所以你的第二個案例是好的。 否則,您實際上是在預測您訓練過的數據(在第二個選項中不是這種情況,您只保留gridsearch中的最佳參數)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.