1

Why does this work,

from sklearn.metrics import mean_squared_error

but not the other?

import sklearn.metrics.mean_squared_error as mse

This gives

ModuleNotFoundError: No module named 'sklearn.metrics.mean_squared_error'

It is not possible because mean_squared_error is a function is my guess?

1
  • @RocketHazmat i know that works. I didn't to get something that works but why what I wrote it wrong. Commented Dec 1, 2020 at 20:48

1 Answer 1

4

You cannot import sklearn.metrics.mean_squared_error because it is not a module but a function, yes. The as part stands completely independently. So you can, for example, from sklearn.metrics import mean_squared_error as mse.

Sign up to request clarification or add additional context in comments.

2 Comments

I know that as implied in my question title. But what I want is why.
I don't understand how I'm supposed to answer that. If "it is not a module" isn't an adequate explanation for "why do I get an error message saying no module named...", then I don't know what would be. Questions about why language designers made the design decisions they did are not a good fit for Stack Overflow; unless there is an authoritative interview with the designers, we are speculating and offering opinions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.