【问题标题】:How do I confirm the output from the sklearn transform model (sc.transform)?如何确认 sklearn 变换模型 (sc.transform) 的输出?
【发布时间】:2022-11-08 07:54:52
【问题描述】:

我正在学习 sklearn 中的 StandardScaler 模块。我了解 sc.fit 获得数据的平均值并使用它来转换数据的训练和测试,但我不明白使用从 sc 获得的 sc.mean_ 对数据数组执行什么数学函数。合身。

如何确认我从 sc.transform 或 sc.fit_transform 收到的输出是我想要的,或者它是否正确?

【问题讨论】:

    标签: python python-3.x transform sklearn-pandas


    【解决方案1】:

    利用

    df.describe()
    

    查看您想要的转换。

    from sklearn.preprocessing import StandardScaler
    import numpy as np
    import pandas as pd
    # 4 samples/observations and 2 variables/features
    data = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
    df = pd.DataFrame(data, columns=['V1', 'V2']).astype('float64')
    columns_scaling = ['V1', 'V2']
    scaler = StandardScaler()
    df[columns_scaling]= scaler.fit_transform(df[columns_scaling])
    df.describe().apply(lambda s: s.apply(lambda x: format(x, 'g')))
    

    【讨论】:

      猜你喜欢
      • 2020-02-03
      • 2019-08-04
      • 2016-07-25
      • 2021-12-17
      • 1970-01-01
      • 2021-09-18
      • 2018-05-21
      • 2020-10-25
      • 1970-01-01
      相关资源
      最近更新 更多