2017-11-04 12 views
0

feature_importances_ 오류가 나는거야? 문서에 따르면이 속성이 있어야합니까?RandomForestRegressor 내가 내 RandomForestRegressor의 기능 importances을 꺼내 고군분투

전체 코드 :

from sklearn.ensemble import RandomForestRegressor 
from sklearn.model_selection import GridSearchCV 

#Running a RandomForestRegressor GridSearchCV to tune the model. 
parameter_candidates = { 
    'n_estimators' : [650, 700, 750, 800], 
    'min_samples_leaf' : [1, 2, 3], 
    'max_depth' : [10, 11, 12], 
    'min_samples_split' : [2, 3, 4, 5, 6] 
} 

RFR_regr = RandomForestRegressor() 
CV_RFR_regr = GridSearchCV(estimator=RFR_regr, param_grid=parameter_candidates, n_jobs=5, verbose=2) 
CV_RFR_regr.fit(X_train, y_train) 

#Predict with testing set 
y_pred = CV_RFR_regr.predict(X_test) 

#Extract feature importances 
importances = CV_RFR_regr.feature_importances_ 

답변

1

당신은 GridSearchCV 개체의 속성을 사용하려고합니다. 거기에 존재하지 않습니다. 실제로 수행해야 할 작업은 그리드 검색이 수행되는 평가기에 액세스하는 것입니다.

액세스하여 속성 :

importances = CV_RFR_regr.best_estimator_.feature_importances_