【发布时间】:2016-08-27 05:56:47
【问题描述】:
我正在学习 Python,并且我有一个辅助项目来学习使用 matplotlib.pyplot 模块显示数据。这是一个使用日期[] 和价格[] 作为数据来显示数据的示例。有谁知道为什么我们需要第 5 行和第 6 行?我很困惑为什么需要此步骤来显示图表。
from sklearn import linear_model
import matplotlib.pyplot as plt
def showgraph(dates, prices):
dates = numpy.reshape(dates, (len(dates), 1)) # line 5
prices = numpy.reshape(prices, (len(prices), 1)) # line 6
linear_mod = linear_model.LinearRegression()
linear_mod.fit(dates,prices)
plt.scatter(dates,prices,color='yellow')
plt.plot(dates,linear_mod.predict(dates),color='green')
plt.show()
【问题讨论】:
标签: python matplotlib linear-regression