好的,针对您的问题,以下是一份逻辑回归预测模型的代码示例:
```python
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_auc_score, roc_curve
import matplotlib.pyplot as plt
# 1. 数据读取与处理
data = pd.read_csv('data.csv')
X = data.drop('target', axis=1)
y = data['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 2. 模型训练
model = LogisticRegression()
model.fit(X_train, y_train)
# 3. 模型预测
y_pred = model.predict(X_test)
y_prob = model.predict_proba(X_test)[:, 1]
# 4. 模型评价
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)
auc = roc_auc_score(y_test, y_prob)
# 5. ROC曲线绘制
fpr, tpr, thresholds = roc_curve(y_test, y_prob)
plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % auc)
plt.plot([0, 1], [0, 1], 'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC Curve')
plt.legend(loc="lower right")
plt.show()
# 6. 输出结果
print('Accuracy:', accuracy)
print('Precision:', precision)
print('Recall:', recall)
print('F1-score:', f1)
print('AUC:', auc)
```
这份代码使用了Pandas库读取了名为"data.csv"的数据集,并将其分成训练集和测试集,使用Scikit-learn库中的LogisticRegression类进行模型训练和预测,最后通过Scikit-learn库中的指标函数计算了预测结果的准确率、精确率、召回率、F1-score和AUC指标,同时绘制了ROC曲线。
需要注意的是,上述代码仅作为示例,具体实现需要根据实际情况进行调整。