【问题标题】:StandardScaler: TypeError: fit() missing 1 required positional argument: 'X'StandardScaler:TypeError:fit()缺少1个必需的位置参数:'X'
【发布时间】:2021-09-11 04:20:45
【问题描述】:

我正在使用 StandardScaler 来缩放我的数据框,如下所示,我收到错误 ypeError: fit() missing 1 required positional argument: 'X'。我不确定问题出在哪里?感谢您的帮助。


import seaborn as sns
import pandas as pd
from random import randrange
import random
import numpy as np
from sklearn.preprocessing import StandardScaler # for feature scaling

random.seed(10)

df = pd.DataFrame()
for i in range(0,50):
    df = df.append({'x': randrange(1,10),
                    'y': randrange(10,21),
                    'depth':randrange(400,601)}, ignore_index=True)
df.head()


depth   x   y
0   523.0   1.0 16.0
1   518.0   1.0 13.0
2   567.0   8.0 14.0
3   533.0   3.0 10.0
4   419.0   8.0 15.0

scaler = StandardScaler

scaler.fit(df)
df_scaled= scaler.transform(df)

错误是:

TypeError                                 Traceback (most recent call last)
<ipython-input-40-98ea46087b3f> in <module>
      4 scaler = StandardScaler
      5 
----> 6 scaler.fit(df)
      7 df_scaled= scaler.transform(df)

TypeError: fit() missing 1 required positional argument: 'X'

【问题讨论】:

  • scaler.fit(X=df) 相同的错误?

标签: python pandas scikit-learn


【解决方案1】:

你必须写

scaler = StandardScaler() 

你忘了括号

【讨论】:

    猜你喜欢
    • 2019-06-13
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    • 2017-03-27
    • 2019-11-12
    • 2019-12-23
    相关资源
    最近更新 更多