Hello I'm now learning linear regression. And I want to draw linear regression graph from the data that I made.
if there is a data as indicated below,
one_cycle = [(0, 401.92), (5, 103.62), (7, 62.8), (8, 28.26), (10, 10.55)]
I used statsmodels.api.OLS and got the regression results.
def basic_regression(one_cycle):
#one_cycle would be [(0,100),(1,75)...]
X, Y = [x[0] for x in one_cycle], [x[1] for x in one_cycle]
X = numpy.array(X).T
X = statsmodels.api.add_constant(X)
results = statsmodels.api.OLS(Y, X).fit()
return results
and When I draw graph of the results,
def draw(results):
fig, ax = plt.subplots()
fig = statsmodels.api.graphics.plot_fit(results, 0, ax=ax)
ax.ticklabel_format(useOffset=False)
plt.show()
The graph is not what I expected like the following.
Instead of that graph, I expected this graph:
(source: sourceforge.net)
How can I draw grah like that? Thank you have a good day.