Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...