【多选】分类正确率、混淆矩阵是评价分类模型效果的重要依据,下列编程语句有错误的是()(其中x , y是训练集和训练集标签,分别为DataFrame对象和Series对象) from sklearn.model_selection import train_test_split train_x, test_x, train_y, test_y = train_test_split(x,y, test_size=0.20,random_state=1e) from sklearn.linear_model import LogisticRegression 模型构建 clf = LogisticRegression(random_state=10,penalty='l1' ,solver='liblinear ') ####(1)#### 模型训练 clf.fit(train_x, train_y) 模型预测y_pred = clf.predict(test_x) print("分类正确率: " , round(clf.score(test_x, test_y),4))####(2)#### from sklearn.metrics import classification_report 输出主要分类指标的文本报告 print(classification_report(test_x,test_y)) ####(3)#### from sklearn.metrics import confusion_matrix import seaborn as sns 设置正常显示中文 sns.set(font='SimHei ')绘制热力图 ax = sns.heatmap(plot(test_y, y_pred), ####(4)#### annot=True,fmt= 'd ') ax.set_ylabel('真实') ax.set_xlabel('预测') ax.set_title('混淆矩阵热力图')
时间: 2023-07-16 13:14:19 浏览: 96
小程序实现分类页
5星 · 资源好评率100%
以下是错误的编程语句:
- 第一行代码中,test_size=0.20,random_state=1e 中的逗号应该改为小数点,即test_size=0.20,random_state=1e-1。
- 第二个错误在于print(classification_report(test_x,test_y)),应该是print(classification_report(test_y, y_pred))。
修改后的代码如下:
```
from sklearn.model_selection import train_test_split
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.20, random_state=1e-1)
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(random_state=10, penalty='l1', solver='liblinear')
clf.fit(train_x, train_y)
y_pred = clf.predict(test_x)
print("分类正确率: ", round(clf.score(test_x, test_y), 4))
from sklearn.metrics import classification_report
print(classification_report(test_y, y_pred))
from sklearn.metrics import confusion_matrix
import seaborn as sns
sns.set(font='SimHei')
ax = sns.heatmap(confusion_matrix(test_y, y_pred), annot=True, fmt='d')
ax.set_ylabel('真实')
ax.set_xlabel('预测')
ax.set_title('混淆矩阵热力图')
```
阅读全文