线性回归问题

时间:2018-06-07 14:33:49

标签: python scikit-learn statistics linear-regression

我试图为2列数据运行线性回归(IMF_VALUES,BBG_FV)

我有这段代码:

import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt
import pandas as pd
raw_data = pd.read_csv("IMF and BBG Fair Values.csv")
ISO_TH = raw_data[["IMF_VALUE","BBG_FV"]]


filtered_TH = ISO_TH[np.isfinite(raw_data['BBG_FV'])]

npMatrix = np.matrix(filtered_TH) 
IMF_VALUE, BBG_FV = npMatrix[:,0], npMatrix[:,1]


regression = linear_model.LinearRegression
regression.fit(IMF_VALUE, BBG_FV)

当我将其作为测试运行时,我收到此错误,我真的不知道为什么:

TypeError                                 Traceback (most recent call last)
<ipython-input-28-1ee2fa0bbed1> in <module>()
      1 regression = linear_model.LinearRegression
----> 2 regression.fit(IMF_VALUE, BBG_FV)

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

1 个答案:

答案 0 :(得分:-2)

确保两者都是一维数组:

regression.fit(np.array(IMF_VALUE).reshape(-1,1), np.array(BBG_FV).reshape(-1,1))