【发布时间】:2018-08-15 13:42:43
【问题描述】:
我目前使用的是 Scikit-Learn 版本 0.19.2 和 Python 3.6.3
由于某种原因,我无法从我的GridSearchCV 访问cv_results_ 属性。
这是我正在使用的代码:
df = pd.read_csv(input_file, sep = ";", header=None)
numpy_array = df.as_matrix()
y=numpy_array[:,1]
y[y=='RR']=1
y[y=='AIRR']=0
print(y)
y=y.astype('int')
vectorizer = TfidfVectorizer(sublinear_tf=True, max_df=0.5, stop_words=stopwords)
X=numpy_array[:,0]
X=vectorizer.fit_transform(X)
param_grid = {"base_estimator__criterion" : ["gini", "entropy"],
"base_estimator__splitter" : ["best", "random"],
"n_estimators": [1, 2]
}
DTC = DecisionTreeClassifier(random_state = 11, max_features = "auto", class_weight = "balanced",max_depth = None)
# Create and fit an AdaBoosted decision tree
bdt = AdaBoostClassifier(base_estimator = DTC)
grid_search_ABC = GridSearchCV(bdt, param_grid=param_grid, scoring = 'roc_auc', cv=5, refit=True)
pred = grid_search_ABC.fit(X,y)
print(metrics.confusion_matrix(y, pred))
mean=grid_search_ABC.cv_results_['mean_test_score']
std=grid_search_ABC.cv_results_['std_test_score']
我读到这主要与 GridSearchCV 可能没有安装有关,但我完全可以用它来预测新实例等。
请指教一下?
【问题讨论】:
-
那么在你
grid_search_ABC.fit(X,y)之后,如果你做grid_search_ABC.cv_results_,属性就没有了吗?你有return_train_score=True或return_train_score='warn'所以这应该不是问题。 -
你正在这样做
pred = grid_search_ABC.fit(X,y)。所以 pred 实际上是一个 GridSearchCV 对象,而不是预测。你确定你在下一行没有收到任何错误:print(metrics.confusion_matrix(y, pred))?发布错误的完整堆栈跟踪。
标签: python pandas scikit-learn