乱序
from sklearn.model_selection import ShuffleSplit
K折交叉验证
from sklearn.model_selection import cross_val_score
cross_val = cross_val_score(KNN, iris.data, iris.target, cv=4,scoring='neg_mean_squared_error')
拆分数据集
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(iris.data, iris.target, test_size=0.3)
评价函数
from sklearn.metrics import precision_score, recall_score, f1_score, roc_auc_score, confusion_matrix, roc_curve, precision_recall_curve
accuracy_value = accuracy_score(Y_test, Y_predict)
precision_value=precision_score(Y_test, Y_predict,average="micro")
recall_value=recall_score(Y_test, Y_predict,average="micro")
f1_value = f1_score(Y_test, Y_predict,average="micro")
roc_auc_value=roc_auc_score(Y_test, Y_predict, average="micro")
#sklearn.metrics.precision_score(y_true, y_pred, labels=None, pos_label=1, average='binary'', sample_weight=None)
#roc_auc_score() got an unexpected keyword argument 'labels', 'pos_label' average has to be one of (None, 'micro', 'macro', 'weighted', 'samples')
#lr = LogisticRegressionCV(multi_class="ovr",fit_intercept=True,Cs=np.logspace(-2,2,20),cv=2,penalty="l2",solver="lbfgs",tol=0.01)