【发布时间】:2023-04-03 01:50:01
【问题描述】:
我正在寻找点和预测线之间的距离。理想情况下,我希望结果显示在包含距离的新列中,称为“距离”。
我的进口:
import os.path
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn.linear_model import LinearRegression
%matplotlib inline
我的数据样本:
idx Exam Results Hours Studied
0 93 8.232795
1 94 7.879095
2 92 6.972698
3 88 6.854017
4 91 6.043066
5 87 5.510013
6 89 5.509297
到目前为止我的代码:
x = df['Hours Studied'].values[:,np.newaxis]
y = df['Exam Results'].values
model = LinearRegression()
model.fit(x, y)
plt.scatter(x, y,color='r')
plt.plot(x, model.predict(x),color='k')
plt.show()
任何帮助将不胜感激。谢谢
【问题讨论】:
标签: python numpy machine-learning scikit-learn linear-regression