Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

python - Jupyter notebook is giving error when using MinMaxScalar or StandardScalar?

When performing StandardScalar or MinMaxScalar using PythonAdv kernel the jupyter notebook is printing error. However, when using Python 3 environment the same jupyter note book is working fine:

from sklearn.preprocessing import MinMaxScaler

# Scale X values
X_scalar = MinMaxScaler().fit(X_train)
#print(X_scalar)
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)

Error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-e5dc00a586d3> in <module>
      4 X_scalar = MinMaxScaler().fit(X_train)
      5 #print(X_scalar)
----> 6 X_train_scaled = X_scaler.transform(X_train)
      7 X_test_scaled = X_scaler.transform(X_test)

NameError: name 'X_scaler' is not defined

I have Anaconda 3, python 3.6 and PythonAdv environments on Git Bash on Windows.

question from:https://stackoverflow.com/questions/65915769/jupyter-notebook-is-giving-error-when-using-minmaxscalar-or-standardscalar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
from sklearn.preprocessing import MinMaxScaler

# Scale X values
X_scaler = MinMaxScaler().fit(X_train)
#print(X_scalar)
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)

There is a small typo. you define X_scalar then use X_scaler.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...