【发布时间】:2018-11-17 12:39:29
【问题描述】:
我正在尝试对 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'
【问题讨论】:
-
检查
IMF_VALUE和BBG_FV值的形状。BBG_FV可能不是数组。 -
您忘记初始化回归对象。你需要做:
regression = linear_model.LinearRegression()。观察最后的括号。没有它们,regression是一个类,而不是初始化的对象模型。
标签: python scikit-learn statistics linear-regression