簡體   English   中英

StandardScaler: TypeError: fit() 缺少 1 個必需的位置參數:'X'

[英]StandardScaler: TypeError: fit() missing 1 required positional argument: 'X'

我正在使用 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 = StandardScaler() 

你忘了括號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM