handson-ml
handson-ml copied to clipboard
Error when training the regression model in Chapter 2
Hello,
Could you please help in telling me the below issue when I am trying to import the regression model and train it on the dataset in Chapter 2.
INPUT from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression() lin_reg.fit(housing_prepared, housing_labels)
OUTPUT
NameError Traceback (most recent call last)
NameError: name 'housing_prepared' is not defined
As the error message said, maybe the name "housing_prepared" is not defined. You can check the sentence:
housing_prepared =
Hi @Nishant90ML ,
As @GoldenRaven answered, the error message says that the variable housing_prepared is not defined. This probably means that you did not run the cell that defines it, or perhaps you ran it but then you restarted the kernel or Jupyter. In this case, you need to run the cells again, in order.
Hope this helps.
from sklearn.linear_model import LinearRegression
lin_reg=LinearRegression()
lin_reg.fit(housing_prepared,housing_labels)
housing_labels ()
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_6508/3928194044.py in
TypeError: 'Series' object is not callable
what to do if we have these problem
Hi @1sunkesulalalbasha12 ,
The housing_labels object is a Pandas Series object. It cannot be called like a function. Just remove the line housing_labels (), or remove the parentheses: housing_labels.