X_train,X_test,y_train,y_test=train_test_split(X ,y,test_size=0.2,random_state=1);reg = 0.01 LogRegModel = LogisticRegression(C=1/reg, solver = 'liblinear').fit(X_train, y_train) preds = LogRegModel.predict(X_test) print('accuracy', metrics.accuracy_score(y_test, preds)) print('recall', metrics.recall_score(y_test, preds)) print('precision', metrics.precision_score(y_test, preds)) print('f1-score', metrics.f1_score(y_test, preds));from sklearn. metrics import classification_report print(classification_report(y_test, preds));from sklearn.metrics import roc_curve from sklearn.metrics import confusion_matrix import matplotlib import matplotlib.pyplot as plt %matplotlib inline y_scores = LogRegModel.predict_proba(X_test) print(y_scores) # calculate ROC curve fpr, tpr, thresholds = roc_curve(y_test, y_scores[:,1]) # plot ROC curve fig = plt.figure(figsize=(6, 6)) # Plot the diagonal 50% line plt.plot([0, 1], [0, 1], 'k--') # Plot the FPR and TPR achieved by our model plt.plot(fpr, tpr) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('ROC Curve') plt.show()
时间: 2024-04-01 09:38:40 浏览: 59
linux基础进阶笔记
这是一个二分类问题的逻辑回归模型的评估过程,其中使用了 train_test_split 进行数据集的划分,然后使用 LogisticRegression 进行模型的训练,并对测试集进行预测,使用了多个评价指标,如准确率、召回率、精确率、F1-score 和分类报告等;此外还使用了 ROC 曲线和 AUC 值来评估模型的性能。
阅读全文