2、决策树
from sklearn import tree
clf = tree.DecisionTreeClassifier(criterion="gini",max_depth=5,min_samples_split=2,min_samples_leaf=52)
clf.fit(x_train, y_train)
p=clf.predict_proba(x_test)
m=pd.DataFrame(p)
n=m.iloc[:,1:]
from sklearn.metrics import roc_curve
label=y_test
score=n
fpr,tpr,thresholds= roc_curve(label,score)
ks_value = max(abs(fpr-tpr))
画图,画出曲线
plt.plot(fpr, label='bad')
plt.plot(tpr, label='good')
plt.plot(abs(fpr-tpr), label='diff')
标记ks
x = np.argwhere(abs(fpr-tpr) == ks_value)[0, 0]
plt.plot((x, x), (0, ks_value), label='ks - {:.2f}'.format(ks_value), color='r', marker='o', markerfacecolor='r', markersize=5)
plt.scatter((x, x), (0, ks_value), color='r')
plt.legend()
plt.show()
2.2调参
from sklearn.model_selection import GridSearchCV
model = LogisticRegression()
grid={'min_samples_leaf':[40,45,50,52,53,54,55,56]}
gs=GridSearchCV(clf,grid,cv=10)
gs.fit(x_train,y_train)
gs.best_score_
gs.best_params_
标签:plt,value,label,ks,tpr,fpr,决策树 From: https://www.cnblogs.com/chenqianguan/p/17890914.html