【问题标题】:How to fit an n dimentional array which is a coulmn of dataframe for x(input) using sklearn?如何使用sklearn拟合一个n维数组,它是x(输入)的一列数据框?
【发布时间】:2021-03-03 05:39:15
【问题描述】:
X = scaler.fit_transform(np.array(data.iloc[:, :-1], dtype = float))

TypeError: only size-1 arrays can be converted to Python scalars

我有 8 列的数据框,有些列包含超过 1000 个样本的数组。现在我面临类型错误。请帮助我将 n 维数组数据作为输入进行拟合

【问题讨论】:

    标签: python scikit-learn


    【解决方案1】:

    在所需列中使用 .values

    X = scaler.fit_transform(data[["columns", "you", "want"]].values)
    

    您似乎想跳过最后一列(我猜是因为它包含标签)。

    X = scaler.fit_transform(data[data.columns[:-1]].values)
    

    【讨论】:

    • 你实际上不能像那样索引列,你需要用一个列表来索引,例如data[["columns", "you", "want"]].
    猜你喜欢
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    相关资源
    最近更新 更多