简单的机器学习任务不起作用

2024-10-06 14:33:24 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是Siraj的演示:下面是我的代码,它最适合单变量数据

(可以在here中找到文件):

#import dependencies
import pandas as pd
from sklearn import linear_model
import matplotlib.pyplot as plt

#read data
dataframe = pd.read_fwf('brain_body.txt')
x_values = dataframe[['Brain']]
y_values = dataframe[['Body']]

#train model on data
body_reg = linear_model.LinearRegression()
body_reg.fit(x_values, y_values)

#visualize results
plt.scatter(x_values, y_values)
plt.plot(x_values, body_reg.predict(x_values))
plt.show()

我总是弄得一团糟:

enter image description here


Tags: 数据代码importdataframereaddatamodelas
2条回答

达伦·奥洛克的回答值得称赞

因为熊猫图书馆似乎有区别,numpy为我解决了这个问题。你知道吗

import numpy as np
x_values = np.array(x_values)
y_values = np.array(y_values)

我希望这能解决问题。你知道吗

干杯

我的看起来一模一样。我来这里是想看看有没有人帮我贴了什么。问题似乎与2个异常值(2547-4603和6654-5712)有关,因为它们明显更高。你知道吗

相关问题 更多 >