handson-ml icon indicating copy to clipboard operation
handson-ml copied to clipboard

Error when training the regression model in Chapter 2

Open Nishant90ML opened this issue 5 years ago • 5 comments

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) in 2 3 lin_reg = LinearRegression() ----> 4 lin_reg.fit(housing_prepared, housing_labels)

NameError: name 'housing_prepared' is not defined

Nishant90ML avatar Jan 24 '20 13:01 Nishant90ML

As the error message said, maybe the name "housing_prepared" is not defined. You can check the sentence: housing_prepared =

GoldenRaven avatar Feb 10 '20 15:02 GoldenRaven

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.

ageron avatar Mar 19 '21 21:03 ageron

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 ----> 1 housing_labels ()

TypeError: 'Series' object is not callable

1sunkesulalalbasha12 avatar Apr 29 '22 07:04 1sunkesulalalbasha12

what to do if we have these problem

1sunkesulalalbasha12 avatar Apr 29 '22 07:04 1sunkesulalalbasha12

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.

ageron avatar May 05 '22 09:05 ageron