python错误代码40035_python-(matplotlib.pyplot)散点图轴的顺序错误
发布日期:2021-06-24 12:33:09 浏览次数:2 分类:技术文章

本文共 1534 字,大约阅读时间需要 5 分钟。

这个问题已经在这里有了答案:????????????>????????????Plot sklearn LinearRegression output with matplotlib????????????????????????????????????1个

我正在追踪this linear regression example,但我的结果与实际结果有所不同.问题出在绘图轴上,它们没有顺序.

预期:

我的结果:

缩放以查看轴:

编码:

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()

brain_body.txt

Brain Body

3.385 44.500

0.480 15.500

1.350 8.100

465.000 423.000

36.330 119.500

27.660 115.000

14.830 98.200

1.040 5.500

4.190 58.000

0.425 6.400

0.101 4.000

0.920 5.700

1.000 6.600

0.005 0.140

0.060 1.000

3.500 10.800

2.000 12.300

1.700 6.300

2547.000 4603.000

0.023 0.300

187.100 419.000

521.000 655.000

0.785 3.500

10.000 115.000

3.300 25.600

0.200 5.000

1.410 17.500

529.000 680.000

207.000 406.000

85.000 325.000

0.750 12.300

62.000 1320.000

6654.000 5712.000

3.500 3.900

6.800 179.000

35.000 56.000

4.050 17.000

0.120 1.000

0.023 0.400

0.010 0.250

1.400 12.500

250.000 490.000

2.500 12.100

55.500 175.000

100.000 157.000

52.160 440.000

10.550 179.500

0.550 2.400

60.000 81.000

3.600 21.000

4.288 39.200

0.280 1.900

0.075 1.200

0.122 3.000

0.048 0.330

192.000 180.000

3.000 25.000

160.000 169.000

0.900 2.600

1.620 11.400

0.104 2.500

4.235 50.400

这是我第一次使用python,我认为某些模块的安装存在问题,但是我没有任何线索.

转载地址:https://blog.csdn.net/weixin_32767591/article/details/112932512 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:kali激活phpstorm_Phpstorm不知道如何运行Wordpress - WordPress - srcmini
下一篇:python2和3安装后怎样切换 mac_Mac下安装配置Python2和Python3并相互切换使用

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月25日 10时54分43秒