Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import sklearn module sklearn has no attribute metrics

when we use sklearn,

from sklearn.metrics import mean_squared_error

why we can use only this way to caluate mse?

import sklearn

sklearn.metrics.mean_squared_error

why this way can not? and The compiler will report an error(module sklearn has no attribute metrics).

like image 775
JasonLee5555 Avatar asked Nov 20 '25 19:11

JasonLee5555


1 Answers

It is possible in both the ways to find mean_squared_error. For you, the compiler has reported an error because you havenot specified any attributes. I hope below example helps you

from sklearn.metrics import mean_squared_error
Y_true = [1,1,2,2,4]  # Y_true = Y (original values)
Y_pred = [0.6,1.29,1.99,2.69,3.4]  # Y_pred = Y'
# Calculation of Mean Squared Error (MSE)
mean_squared_error(Y_true,Y_pred)

or

import sklearn
# Given values
Y_true = [1,1,2,2,4]  # Y_true = Y (original values)
Y_pred = [0.6,1.29,1.99,2.69,3.4]  # Y_pred = Y'
# Calculation of Mean Squared Error (MSE)
sklearn.metrics.mean_squared_error(Y_true,Y_pred)

You can refer my Example by clicking this link

like image 115
San Avatar answered Nov 23 '25 08:11

San



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!