millionaireW
2022-04-19 16:25
采纳率: 0%
浏览 75

python中的plot图为什么不显示

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

x=np.array([[1,0,180,165,175,165,170,165],
[3,0,180,165,175,165,173,165],
[4,0,180,165,175,166,173,165],
[6,0,180,165,175,163,171,165],
[8,1,180,165,175,167,170,165],
[10,0,180,166,175,165,170,165],
[11,0,180,165,175,165,170,165],
[12,0,180,165,175,165,170,165],
[13,1,180,165,175,165,170,165],
[14,0,180,165,175,165,170,165],
[17,0,170,165,175,165,170,165]]
)
x_test=x[:,0].reshape(1,-1)
print(x_test)

#标签数据(儿童身高)
y=np.array([60,90,100,110,130,140,150,164,160,163,168]).reshape(1,-1)
print(y)

#预测
xs=np.array([[10,0,180,165,175,165,170,165],
[17,1,173,153,175,161,170,161],
[35,0,170,165,170,165,170,165]])
xs_train=xs[:,0].reshape(1,-1)
print(xs_train)

sg = LinearRegression()
sg.fit(x_test, y)

y_pred = sg.predict(x_test)

plt.scatter(x_test,y,color='blue')
plt.plot(x_test,sg.predict(x_test),color='red',linewidth=3)
plt.show()

print('斜率:{}, 截距:{}'.format(sg.coef_,sg.intercept_))

3条回答 默认 最新

相关推荐 更多相似问题