【问题标题】:Python sklearn scalerPython sklearn 缩放器
【发布时间】:2020-03-12 21:46:54
【问题描述】:

如果我先定义缩放器,然后调用它,一切正常:

scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

但打电话

X_scaled = StandardScaler.fit_transform(X)

返回错误: fit_transform() 缺少 1 个必需的位置参数:'X'

【问题讨论】:

  • 第二个例子缺少括号。

标签: python


【解决方案1】:

单行调用中缺少括号:

X_scaled = StandardScaler().fit_transform(X)

函数 fit_transform 需要两个参数 self 和 X。如果您使用带括号的 StandardScaler,则会自动提供 self。否则,您还必须提供 StandardScaler 的实例作为 self 参数。您的调用传递了变量 X,该变量被视为 self,因此该函数仍然缺少 X 参数。希望这会有所帮助。

【讨论】:

    【解决方案2】:

    你仍然需要在函数调用中包含括号:

    X_scaled = StandardScaler().fit_transform(X)
    

    这应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 2018-12-29
      • 1970-01-01
      • 2014-06-05
      • 2019-08-18
      • 2015-10-28
      • 2021-12-13
      • 2019-11-24
      • 2020-09-03
      • 2017-10-05
      相关资源
      最近更新 更多