从逻辑回归绘制预测

Plotting prediction from logistic regression

我想在散点图中绘制 y_test 和预测。 我正在使用逻辑回归作为模型。

from sklearn.linear_model import LogisticRegression

vectorizer = CountVectorizer()

X = vectorizer.fit_transform(df['Spam'])
y = df['Label']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=27)

lr = LogisticRegression(solver='liblinear').fit(X_train, y_train)
pred_log = lr.predict(X_test)

我试过如下

## Plot the model

plt.scatter(y_test, pred_log)
plt.xlabel("True Values")
plt.ylabel("Predictions")

我得到了这个:

我认为这不是我应该期待的。 y_test是(250,),同理pred_log是(250,)

我是在考虑绘制错误的变量,还是它们是正确的? 我不知道这四个值的情节是什么意思。我本来期望情节中有更多点,但也许我错了。

如果您需要更多信息,请告诉我。谢谢

我想你知道 LogisticRegression 是一种 class化算法。如果你做二进制 classification 它将预测预测的 class 是 0 还是 1.If 你想获得关于模型如何预成型的可视化,你应该考虑 confusion matrix。你可以' t 使用散点图可视化 class化结果。

import seaborn as sns
cm = confusion_matrix(y_true, y_pred)
sns.heatmap(cf_matrix, annot=True)

混淆矩阵显示有多少标签有正确的预测,有多少是 wrong.Looking 在混淆矩阵你可以计算出 model.We 可以使用不同的指标有多准确 precision,recall and F1 score.