【问题标题】:how to convert user input to independent dummy variables如何将用户输入转换为独立的虚拟变量
【发布时间】:2019-08-02 07:12:57
【问题描述】:

我有一个如下所示的数据集

Plant   Brand   Volume
A         HL      12
B         AG      14
A         FP      50000
G         TT      08

为了训练我使用 pd.get_dummies 方法制作的模型(Plant-Brand) 它扩展为 186 列,如下所示;

Plant_A    Plant_B ...  Brand_HL    Brand_AG   ...
   1          0            1           0
   0          1            0           1
   1          0            0           0
   0          0            0           0

我的模型运行良好,但我需要使用用户输入来处理这个模型

用户应仅手动提供植物 ID、品牌和数量 我需要转换这些值并以相同的格式(186 列)写入以预测独立值

y_pred = model.predict(X_user)

如何将 4 维转换为 186?有什么方法可以快速完成吗?

提前致谢,

【问题讨论】:

  • 您是如何执行一种热编码的?如果您使用 Scale 方法,您可以简单地使用一个热编码值进行解码。
  • @Mohamed Thasih 啊我用pandas方法-

标签: python pandas prediction dummy-variable


【解决方案1】:

你可以使用:

np_array = np.asarray(df) # df is your pandas DataFrame

np_array.resize((new_num_rows, new_num_columns))

但你必须记住 old_num_rows * old_num_columns 应该等于 new_num_rows * new_num_columns

【讨论】:

    猜你喜欢
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    相关资源
    最近更新 更多