A user is trying to run a linear regression for 2 columns of data (IMF_VALUES, BBG_FV)and got the following error

244    Asked by ranjan_6399 in Data Science , Asked on Jan 15, 2020
Answered by Ranjana Admin

TypeError Traceback (most recent call last)

in ()

      1 regression = linear_model.LinearRegression

----> 2 regression.fit(IMF_VALUE, BBG_FV)

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

 The following code is given below

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)

This happens because of the difference in shape of the arrays. The below code can fix the problem.

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



Your Answer

Interviews

Parent Categories