我尝试调整身材的大小。但是,当我这样做的时候,通过添加plt.figure(figsize=(10,5))
我再也看不到这些点了。我要更改大小的原因主要是因为ylabel
并未像现在这样显示。
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()