import pandas as pd
icecream = pd.read_csv("icecream.csv")
import matplotlib.pyplot as plt
import pylab
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.scatter(icecream.iloc[:,1],icecream.iloc[:,0])
plt.xlabel("气温")
plt.ylabel("销售量")
pylab.show()
icecream.iloc[:,0:2].corr()
销售量 气温
from sklearn.linear_model import LinearRegression
model = LinearRegression()
feature_cols = ['气温']
X = icecream[feature_cols]
y = icecream.销售量
model.fit(X,y)
plt.scatter(icecream.气温, icecream.销售量)
plt.plot(icecream.气温, model.predict(X) , color='blue')
plt.xlabel('气温')
plt.ylabel('销售量')
plt.show()
print("截距与斜率:",model.intercept_,model.coef_)
截距与斜率: 57.1673282152 [ 5.21607823]
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |