我有一个100x3的数据集,都具有值。我在绘制模型时遇到麻烦。一直说x和Y的大小必须相同。但是,当我使用
if len(x1) == len(y):
print('Equal')
else:
print('Not Equal')
它给了我平等的机会。
这是我的绘图代码
plt.scatter(x1,y)
yhat = 227.7009*x1 + -5.772e+06
fig = plt.plot(x1,yhat, lw=1, c='blue' , label = 'regression line')
plt.xlabel('size',fontsize=20)
plt.ylabel('price',fontsize=20)
plt.show()
编辑:还想问我是否在代码中缺少某些内容,
#import the necessary packages that we need.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
import seaborn
seaborn.set()
data = pd.read_csv('real_estate_price_size_year.csv')
data
data.describe()
#our dependent variable would be the GPA.
y = data['price']
#and our predictor would be the SAT Score.
x1 = data[['size','year']]
x = sm.add_constant(x1)
results = sm.OLS(y,x).fit()
results.summary()
plt.scatter(x1,y)
yhat = 227.7009 * x1 + -5.772e+06
fig = plt.plot(x1,yhat, lw=1, c='blue' , label = 'regression line')
plt.xlabel('size',fontsize=20)
plt.ylabel('price',fontsize=20)
plt.show()