【问题标题】:Preparing y_target variable for Neural Network training为神经网络训练准备 y_target 变量
【发布时间】:2019-04-27 01:48:16
【问题描述】:

我有 y_target 变量的数组,其形状为 (5000,),我想将它用于 Keras NN 模型进行时间序列分类。

使用 numpy newaxis 我已通过执行以下操作将维度从 1D 转换为 2D:y_target = y_target[..., newaxis]

我的目标变量有 2 个类:[0,1] 所以上次转换的数组(形状 (5000,1))。看起来像这样:

[[0],
 [0],
 [1],
 [0],
 [1]]

我想使用以下逻辑转换此数组:(5000,2),它将具有如下二进制结构:

 [[1, 0],
  [1, 0],
  [0, 1],
  [1, 0],
  [0, 1]]

在 pandas 中是否有直接的方法来做到这一点?

【问题讨论】:

    标签: python pandas numpy tensorflow keras


    【解决方案1】:

    我知道该怎么做:)

    一种可能的方法是使用Keras 库和to_categorical() 函数

    from keras.utils import to_categorical
    y_target = to_categorical(y_target)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2017-05-28
      • 2010-11-20
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多