【问题标题】:'NoneType' object has no attribute 'transform''NoneType' 对象没有属性 'transform'
【发布时间】:2021-12-11 21:48:57
【问题描述】:

AttributeError at /turboai/turboAI/jaaiparameters/ enter image description here

def transform_data(df, cols, scaler, n_days_past=120):

    n_cols = len(cols)

    # df to np array

    np_arr = np.array(df.values.flatten().tolist())

    np_arr = scaler.transform([np_arr])

    np_arr = np_arr.reshape((np_arr.shape[0], n_days_past, n_cols))

    return np_arr

【问题讨论】:

  • 提供一些代码/数据来重现问题
  • 您是否在任何地方初始化了scaler 对象? scaler = StandardScaler()

标签: python django numpy transform


【解决方案1】:

调用者在您的 transform_data 方法中为 scaler 传递 None 值,这就是您收到上述错误的原因

如果您不确定 scaler 中的值,您可以更新您的代码,如下所示,首先检查 scaler 对象,然后在其之上执行操作。

def transform_data(df, cols, scaler, n_days_past=120):
    n_cols = len(cols)
    np_arr = np.array(df.values.flatten().tolist())

    if scaler:
        np_arr = scaler.transform([np_arr])
    np_arr = np_arr.reshape((np_arr.shape[0], n_days_past, n_cols))
    return np_arr

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-08
  • 2021-11-02
  • 2014-07-05
  • 2018-05-05
  • 2013-02-11
  • 2018-12-01
  • 2017-08-02
相关资源
最近更新 更多