小编Rak*_*san的帖子

没有估计器的 plot_confusion_matrix

我正在尝试使用 plot_confusion_matrix,

from sklearn.metrics import confusion_matrix

y_true = [1, 1, 0, 1]
y_pred = [1, 1, 0, 0]

confusion_matrix(y_true, y_pred)
Run Code Online (Sandbox Code Playgroud)

输出:

array([[1, 0],
       [1, 2]])
Run Code Online (Sandbox Code Playgroud)

现在,在使用以下内容时;使用“类”或不使用“类”

from sklearn.metrics import plot_confusion_matrix

plot_confusion_matrix(y_true, y_pred, classes=[0,1], title='Confusion matrix, without normalization')
Run Code Online (Sandbox Code Playgroud)

或者

plot_confusion_matrix(y_true, y_pred, title='Confusion matrix, without normalization')
Run Code Online (Sandbox Code Playgroud)

除了里面的数字,我希望得到类似的输出,

在此处输入图片说明

绘制简单的图表,应该不需要估计器。

使用 mlxtend.plotting,

from mlxtend.plotting import plot_confusion_matrix
import matplotlib.pyplot as plt
import numpy as np

binary1 = np.array([[4, 1],
                   [1, 2]])

fig, ax = plot_confusion_matrix(conf_mat=binary1)
plt.show()
Run Code Online (Sandbox Code Playgroud)

它提供相同的输出。

基于

它需要一个分类器,

disp = plot_confusion_matrix(classifier, X_test, y_test, …
Run Code Online (Sandbox Code Playgroud)

python confusion-matrix scikit-learn

7
推荐指数
2
解决办法
3605
查看次数

为什么需要“预测空间”?

这是一个关于使用回归探索 Gapminder 数据进行预测的老问题。他们使用“预测空间”来计算预测。

Q1. 我为什么要创建“预测空间”?它有什么用呢?

Q2。“预测空间”上计算预测的关系?

import numpy as np
import pandas as pd

# Read the CSV file into a DataFrame: df
df = pd.read_csv('gapminder.csv')
Run Code Online (Sandbox Code Playgroud)

数据看起来像这样;

国家、年份、寿命、人口、收入、地区

阿富汗,1800,28.211,3280000,603.0,南亚

斯洛伐克共和国,1960,70.47800000000001,4137224,8693.0,欧洲和中亚

# Create arrays for features and target variable
y = df.life.values
X = df.fertility.values

# Reshape X and y
y = y.reshape(-1,1)
X = X.reshape(-1,1)

# Create the regressor: reg
reg = LinearRegression()

# Create the prediction space
prediction_space = np.linspace(min(X_fertility), max(X_fertility)).reshape(-1,1)

# Fit the model to the data
reg.fit(X_fertility, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning linear-regression scikit-learn

3
推荐指数
1
解决办法
1469
查看次数