gpt4 book ai didi

python - 如何获得预测值和测试数据,并将实际值与预测值可视化?

转载 作者:行者123 更新时间:2023-12-05 05:08:54 25 4
gpt4 key购买 nike

from sklearn import datasets
import numpy as np
import pandas as pd from sklearn.model_selection
import train_test_split
from sklearn.linear_model import Perceptron

data = pd.read_csv('student_selection.csv')

x = data[['Average','Pass','Division','Domicile']]
y = data[['Selected']]

x_train,x_test,y_train,y_test train_test_split(x,y,test_size=1,random_state=0)

ppn = Perceptron(eta0=1.0, fit_intercept=True, max_iter=1000, n_iter_no_change=5, random_state=0)

ppn.fit(x_train, y_train)

y_pred = ppn.predict(x_train)

x_train['Predicted'] = pd.Series(y_pred)

如何在表格和图表中查看实际值与预测值? x_train 是我得到的预测值,但我无法将它与实际数据合并以查看偏差。

最佳答案

How to see the actual vs predicted as a table and along with a plot?

只需运行:

y_predict= pnn.predict(x)

data['y_predict'] = y_predict

并且在你的数据框中有列,如果你想绘制它,你可以使用:

import matplotlib.pyplot as plt
plt.scatter(data['Selected'], data['y_predict'])
plt.show()

关于python - 如何获得预测值和测试数据,并将实际值与预测值可视化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57978791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com