I try to adjust the size of my figure. However, the moment I do that, by adding plt.figure(figsize=(10,5))
I don't see the dots anymore. The reason I want to change the size is mainly because of ylabel
is not shown the way it is now.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import linear_model
# Check out the Data
df = pd.read_csv("https://s3.amazonaws.com/codecademy-content/programs/data-science-path/linear_regression/honeyproduction.csv")
# print(df.head())
# print(df.columns)
prod_per_year = df.groupby(['year']).totalprod.mean().reset_index()
# print(prod_per_year)
X = prod_per_year['year']
X = X.values.reshape(-1, 1)
y = prod_per_year['totalprod']
plt.scatter(X, y)
plt.xlabel('Year')
plt.ylabel('Total production')
plt.show()
# Create and Fit a Linear Regression Model
regr = linear_model.LinearRegression()
regr.fit(X, y)
# Print out the slope (regr.coef_) and the intercept (regr.intercept_)
print(regr.coef_)
print(regr.intercept_)
y_predict = regr.predict(X)
plt.figure(figsize=(10,5))
plt.plot(X, y_predict)
plt.show()