I'm trying to use Simple Linear regression lm.fit()
but getting this error:
TypeError: fit() missing 1 required positional argument: 'self'
Code:
lm = LinearRegression
x = df[['battery_power']]
y = df['price']
lm.fit(X=x, y=y)
What you did is
lm = LinearRegression
But this does not create a LinearRegression instance. instead, you are just making another way to call the LinearRegression class.
What you need to do is this:
lm = LinearRegression()
With parenthesis.
In general, you should know that A missing 1 required positional argument: 'self' error means that you are not passing an instance of the class. probably because you did not create one or the variable you are calling the method with is not an instance of the class.
So this is your code:
lm = LinearRegression()
x = df[['battery_power']]
y = df['price']
lm.fit(X=x, y=y)