Reputation: 24705
I have installed scikit-learn 0.23.2
via pip3
, however, I get this error from my code
Traceback (most recent call last):
File "pca_iris.py", line 12, in <module>
X = StandardScaler().fit_transform(X)
NameError: name 'StandardScaler' is not defined
I searched the web and saw similar topics, however the version is correct and I don't know what to do further. The line import sklearn
is in the top of the script.
Any thought?
Upvotes: 0
Views: 34887
Reputation: 3594
StandardScaler
is a method under sklearn.preprocessing
. You need to import the StandardScaler
like this:
from sklearn.preprocessing import StandardScaler
X = StandardScaler().fit_transform(X)
Or
import sklearn
X = sklearn.preprocessing.StandardScaler().fit_transform(X)
Upvotes: 7