生成分类器评估指标报告
包括精确率,召回率,F1分数 、
support表示每个分类中样本的数量
# 生成评估指标报告
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# load data
iris = datasets.load_iris()
# create feature matrix
features = iris.data
# create target vector
target = iris.target
# 创建目标分类吗列表
class_names = iris.target_names
# create training and test set
# 创建训练集和测试集
features_train, features_test, target_train, target_test = train_test_split(features, target, random_state=1)
# create logistic regression
# 创建逻辑回归对象
classifier = LogisticRegression()
# train model and make predictions
# 训练模型并预测
model = classifier.fit(features_train, target_train)
target_predicted = model.predict(features_test)
# create classification report
生成分类器性能指标
print(classification_report(target_test, target_predicted, target_names=class_names))
precision recall f1-score support
setosa 1.00 1.00 1.00 13
versicolor 1.00 0.94 0.97 16
virginica 0.90 1.00 0.95 9
accuracy 0.97 38
macro avg 0.97 0.98 0.97 38
weighted avg 0.98 0.97 0.97 38