1)roc_auc_score 获取AUC score
用法:
from sklearn import metrics
auc = metrics.roc_auc_score(y_true, y_score)
常见问题:
Data is not binary and pos_label is not specified
原因:y_true必须是0 1 array,如果不是0,1可以有两种方式解决。
方式一:将y_true转为0,1 array
方式二:y_true可以不是0,1 但是需要指定pos_label
fpr, tpr, thresholds = metrics.roc_curve(y_true, y_score, pos_label='T')
auc = metrics.auc(fpr, tpr)
2) LabelEncoder 将category转换成数值型(0 ~ class_range-1)
用法:
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
for col in X.columns.values:
# Encoding only categorical variables
if X[col].dtypes != float:
data=X[col]
data = data.factorize()[0]
le.fit(data)
X[col]=le.transform(data)
3) sklearn.model_selection.
KFold K折交叉验证
http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html