import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn.tree import DecisionTreeClassifier as DT
from sklearn.model_selection import cross_validate
from sklearn.model_selection import GridSearchCV
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
sample = pd.read_csv('submit_sample.csv',header=None)
trainX = train.iloc[:,0:17]
y = train["y"]
testX = test.copy()
trainX = pd.get_dummies(trainX)
testX = pd.get_dummies(testX)
clf1 = DT(max_depth=2,min_samples_leaf=500)
cross_validate(clf1,trainX,y,cv=5,scoring="roc_auc",n_jobs=-1)
clf2 = DT(max_depth=10,min_samples_leaf=500)
cross_validate(clf2,trainX,y,cv=5,scoring="roc_auc",n_jobs=-1)
clf3 = DT()
parameters = {"max_depth":[2,3,4,5,6,7,8,9,10]}
gcv = GridSearchCV(clf3,parameters,cv=5,scoring="roc_auc",n_jobs=-1)
gcv.fit(trainX,y)
gcv.cv_results_
train_score = gcv.cv_results_["mean_train_score"]
以下のようなエラーが出ました。
KeyError Traceback (most recent call last)
<ipython-input-43-b3bb969dc90c> in <module>
----> 1 train_score = gcv.cv_results_["mean_train_score"]
KeyError: 'mean_train_score'
確かに gcv.cv_results_ を入力した際、
下記のように mean_train_score がありませんでした。
しかしなぜ無いのかも分からず困っております。
どなたかご教授頂けると幸いです。
よろしくお願いします。
{'mean_fit_time': array([0.08389435, 0.13443012, 0.14998302, 0.18367682, 0.18703508,
0.20690317, 0.24240103, 0.2491293 , 0.18208938]),
'std_fit_time': array([0.00422696, 0.00403041, 0.01040782, 0.0360382 , 0.00519773,
0.00277816, 0.00701869, 0.0066485 , 0.01300495]),
'mean_score_time': array([0.01356187, 0.01266398, 0.01108303, 0.0101934 , 0.010778 ,
0.00913434, 0.01175599, 0.00746617, 0.00570955]),
'std_score_time': array([0.0057787 , 0.00090742, 0.00112114, 0.000899 , 0.00187392,
0.00082436, 0.0018807 , 0.00083461, 0.00060316]),
'param_max_depth': masked_array(data=[2, 3, 4, 5, 6, 7, 8, 9, 10],
mask=[False, False, False, False, False, False, False, False,
False],
fill_value='?',
dtype=object),
'params': [{'max_depth': 2},
{'max_depth': 3},
{'max_depth': 4},
{'max_depth': 5},
{'max_depth': 6},
{'max_depth': 7},
{'max_depth': 8},
{'max_depth': 9},
{'max_depth': 10}],
'split0_test_score': array([0.74657601, 0.82360265, 0.73033016, 0.74058989, 0.74369939,
0.73096899, 0.73088978, 0.72196441, 0.7018703 ]),
'split1_test_score': array([0.76182968, 0.82214585, 0.843183 , 0.8534447 , 0.85827215,
0.86008609, 0.85743019, 0.85625804, 0.83862935]),
'split2_test_score': array([0.73117591, 0.8075016 , 0.83351987, 0.84181298, 0.83918979,
0.8470071 , 0.83373994, 0.82917544, 0.80750209]),
'split3_test_score': array([0.73707281, 0.75196604, 0.80556935, 0.81563658, 0.82971726,
0.85192346, 0.85226851, 0.84123272, 0.81741621]),
'split4_test_score': array([0.75910043, 0.83206798, 0.85796137, 0.86203561, 0.86213026,
0.84621336, 0.76093385, 0.72858103, 0.71790644]),
'mean_test_score': array([0.74715097, 0.80745683, 0.81411275, 0.82270395, 0.82660177,
0.8272398 , 0.80705245, 0.79544233, 0.77666488]),
'std_test_score': array([0.01196124, 0.02884924, 0.04524805, 0.0439313 , 0.04314222,
0.04838796, 0.05142433, 0.05797012, 0.05567402]),
'rank_test_score': array([9, 5, 4, 3, 2, 1, 6, 7, 8], dtype=int32)}
回答1件
あなたの回答
tips
プレビュー