2017-07-24 58 views
0

我正在通過sklearn使用GridSearchCV調整我的RandomForestClassifier。 我只調整了兩個參數:隨機森林:網格搜索運行時錯誤

「n_estimators」和「min_samples_leaf」。

這是一段代碼:

RFC=RandomForestClassifier(criterion='entropy', random_state=42, max_features='log2', warm_start=True, oob_score=True, n_jobs=-1) 
our_param_grid = [ {'n_estimators':[400, 500, 600, 700]}, {'min_samples_leaf':[50, 70, 90, 110, 130, 150, 170, 190]} ] 
grid = GridSearchCV(estimator = RFC, param_grid = our_param_grid, cv=3) 
grid.fit(X, Y) 
print grid.best_params_ 

我得到警告,關於OOB_Score錯誤。

這是我得到的警告。

Warning: Some inputs do not have OOB scores. This probably means too few trees where used to compute any reliable oob estimators.                             
warn("Some inputs do not have OOB scores. " 

然後彈出一個錯誤,導致程序終止。這是我得到的確切的錯誤。

RuntimeWarning: invalid value encountered in true_divide predictions[k].sum(axis=1)[:, np.newaxis]) 
{'n_estimators': 700} 

我在設置RFC模型時設置了oob_score = True。任何人都可以幫助我理解,我哪裏出錯了。

+0

你可以上傳你的X,Y數據嗎? – sera

+0

Hi @sera,我的X包含2lac樣本,每個樣本都有263個特徵,所以它是(2lac * 263)的矩陣。在擬合到RandomForestClassifier之前,我縮放了這個矩陣(平均值= 0,標準偏差= 1)。我的「Y」是一個零和一個數值的數組(1個lac零和1個lac)。我無法在SO上傳一個csv文件。感謝您的幫助。 – Blessy

+0

你可以檢查你的數據中是否有NaNs?這可能會導致問題。另外,嘗試減少估計器的數量,例如使用100,並讓我知道,如果警告仍然存在 – sera

回答

0

要繼續我的意見......

你可以用下面並嘗試運行GridSearchCV?

our_param_grid = {'n_estimators':[400, 500, 600, 700] , 'min_samples_leaf':[50, 70, 90, 110, 130, 150, 170, 190]} 

說明:

我覺得這是問題,因爲GridSearchCV預計param_grid是一個字典。

在你的情況下,你有一個清單,看起來在n_estimator = 700之後,它看起來並不能「看到」min_samples_leaf