Honey Production Exercise

Hi,

I am working on the Honey Production exercise in the Python for Finance course

https://www.codecademy.com/paths/finance-python/tracks/regression-for-finance/modules/linear-regression-python-finance/projects/honey-production

I am unable to get the right co-efficients for the Regression and all it generates is a bunch of 0s.
This results in no predictions for y- axis.

Can you someone see what is wrong with this code?

import pandas as pd import matplotlib.pyplot as plt import numpy as np from sklearn import linear_model from sklearn.linear_model import LinearRegression df = pd.read_csv("https://content.codecademy.com/programs/data-science-path/linear_regression/honeyproduction.csv") df.head() prod_per_year=df.groupby('year').totalprod.mean().reset_index() prod_per_year.head() x=prod_per_year["year"] x=x.values.reshape(1,-1) y=prod_per_year["totalprod"] y=y.values.reshape(1,-1) plt.scatter(x,y) plt.xlabel("year") plt.ylabel("Total Production") plt.title("Year vs Total Production") plt.show() regr=linear_model.LinearRegression().fit(x,y) print(regr.coef_) print(regr.intercept_) predict_y=regr.predict(x) print(predict_y)

Make sure you’re using the correct shape for your X. If you’re unsure print the shape so you know.