Last answered:

04 Oct 2022

Posted on:

30 Sept 2022

1

AttributeError: 'LinearRegression' object has no attribute 'positive'

Good morning. During the final exam, the error in the title occurred when I tried to run "reg.score(x_train,y_train)". What does it mean and how could I have solved it? Thank you

5 answers ( 0 marked as helpful)
Instructor
Posted on:

03 Oct 2022

0

Hey Alessandro,

Thank you for reaching out!

Such an error would occur if you attempt to execute something like the following:
image.png
Is the following

reg.score(x_train,y_train)

the only piece of code inside the cell you are trying to execute?

EDIT: Could you also let me know what version of sklearn you are using?

Kind regards,
365 Hristina

Posted on:

03 Oct 2022

0

Good morning. Yes, it was just that piece of code if I well remember. How can I know my version of sklearn?

Instructor
Posted on:

04 Oct 2022

0

Hey,

Open your anaconda prompt and activate the environment you are working in (you don't need to do this if you are using the base environment). Then type

conda list

and you will get a list of all the libraries installed in this environment, together with their versions. Find scikit-learn and you will see its version. The one I am using is 1.0.1:
image.png

If you are having trouble with any of the steps above, please watch our Python packages installation lecture.

In any case, the error you are getting is a bit strange. Could you, just in case, restart the kernel in Jupyter notebook and re-run the entire notebook anew?

Kind regard,
365 Hristina

Posted on:

04 Oct 2022

0

Good morning. I have two different scikit-learn:
image.png
But I think the version you meant is 1.0.2.
I have tried to restart the kernel and re-run all, but nothing has changed.

Instructor
Posted on:

04 Oct 2022

0

Hey,

The version of sklearn should not be the cause of the problem. If you are successfully running the notebooks from the resources, then you should be able to solve the questions from the exam without any trouble. Unfortunately, it's a bit difficult to say why this error message occurs without the code in front. Make sure that you are
1. creating an instance of the LinearRegression class
2. fitting the model
3. and only then retrieving the score.

Kind regards,
365 Hristina

Submit an answer