2017-06-04 15 views
0

我想寫一元線性迴歸模型,但我得到一個錯誤類型:線性迴歸模型缺少變量.fit

Traceback (most recent call last) <ipython-input-65-8a233a281e65> in <module>() 
     2 y_val= df['GOOGL'] 
     3 body_reg =linear_model.LinearRegression 
----> 4 body_reg.fit(x_val, y_val) 

TypeError: fit() missing 1 required positional argument: 'y' 

這是代碼我有這麼進口sklearn,熊貓等

import pandas as pd 
import matplotlib.pyplot as plt 
% matplotlib inline 
df = pd.read_csv(r'C:\Users\Brian\Desktop\GOOGTICKER.CSV') 
df 
times = pd.DatetimeIndex(df['Date']) 
grouped= df.groupby([times.year]).mean() 
from sklearn import linear_model 
x_val= df['MSFT'] 
y_val= df['GOOGL'] 
body_reg =linear_model.LinearRegression 
body_reg.fit(x_val, y_val) 

我是否缺少一個參數?

回答

1

您需要創建類的實例:

body_reg = linear_model.LinearRegression() 
+0

我收到一條錯誤消息:C:\用戶\布萊恩\ Anaconda3 \ LIB \站點包\ sklearn \ utils的\ validation.py:395 :DeprecationWarning:作爲數據傳遞1d數組在0.17中被棄用,並且將引起0.19中的ValueError。如果數據具有單個特徵,則使用X.reshape(-1,1)重新整形數據,如果數據包含單個特徵,則使用X.reshape(1,-1)重整數據。 DeprecationWarning) –

+0

也ValueError:找到具有不一致樣本數的輸入變量:[1,2246] –