简体   繁体   English

StandardScaler: TypeError: fit() 缺少 1 个必需的位置参数:'X'

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

I am using StandardScaler to scaling my dataframe like below, and I got an error of ypeError: fit() missing 1 required positional argument: 'X'.我正在使用 StandardScaler 来缩放我的数据框,如下所示,我得到了一个错误 ypeError: fit() missing 1 required positional argument: 'X'. I am not sure where is the problem?我不确定问题出在哪里? Thanks for your help.谢谢你的帮助。


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)

The error is:错误是:

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'

You have to write你必须写

scaler = StandardScaler() 

You forgot the parenthesis你忘了括号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:fit_transform() 缺少 1 个必需的位置参数:&#39;X&#39; - TypeError: fit_transform() missing 1 required positional argument: 'X' sklearn:TypeError:fit() 缺少 1 个必需的位置参数:“x” - sklearn: TypeError: fit() missing 1 required positional argument: 'x" 如何修复“ TypeError:fit()缺少1个必需的位置参数:&#39;X&#39;”的错误 - How to fix “TypeError: fit() missing 1 required positional argument: 'X'” error 类型错误:fit_transform() 缺少 1 个必需的位置参数:'X'; - TypeError: fit_transform() missing 1 required positional argument: 'X' ; 类型错误:x 缺少 1 个必需的位置参数:y - TypeError: x missing 1 required positional argument: y 类型错误:流()缺少 1 个必需的位置参数:'x' - TypeError: flow() missing 1 required positional argument: 'x' TypeError: fit_transform() 缺少 1 个必需的位置参数:&#39;X&#39; - 运行相同的代码并得到一个唯一的错误 - TypeError: fit_transform() missing 1 required positional argument: 'X' - Running identical code & getting a unique error 类型错误:fit_generator() 缺少 1 个必需的位置参数:'generator' - TypeError: fit_generator() missing 1 required positional argument: 'generator' TypeError: fit() 缺少 1 个必需的位置参数:'y' while GridSearching CNN - TypeError: fit() missing 1 required positional argument: 'y' while GridSearching CNN 实现逻辑回归“TypeError: fit() missing 1 required positional argument: 'y'” - Implementing Logistic Regression “TypeError: fit() missing 1 required positional argument: 'y'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM