【问题标题】:build a binary classification model with LSTM使用 LSTM 构建二元分类模型
【发布时间】:2020-02-05 16:36:05
【问题描述】:

我有一个 csv 格式的数据集,有 49 列,其中一些是字符串,其中一些是整数。

我添加了一个新列用作名为“输入”的标签,其中适当的标签为 0 和 1。

以下是数据集的示例:

要求在模型训练时考虑所有这些特征列。

我有哪些选择来训练这个模型? 我应该遵循哪些步骤? 任何资源(文章、视频等)将不胜感激。

谢谢,

【问题讨论】:

  • 你能提供更多关于你尝试过什么的信息吗?
  • 为什么LSTM 的所有型号?
  • @Andrei @shahaf LSTM 是客户的要求,令人困惑的部分是所有特征列的利用,其中包括字符串列,主要是 1 或 2 个单词,我是否应该实现 tokenization ?

标签: python machine-learning classification lstm text-classification


【解决方案1】:

这里有两个教程可能会对您有所帮助:

https://towardsdatascience.com/machine-learning-recurrent-neural-networks-and-long-short-term-memory-lstm-python-keras-example-86001ceaaebc

https://stackabuse.com/time-series-analysis-with-lstm-using-pythons-keras-library/

本教程是关于混合数据的: https://www.pyimagesearch.com/2019/02/04/keras-multiple-inputs-and-mixed-data/

如果您不使用未提及的其他东西,我建议您尝试使用 Keras 来熟悉如何训练它。

只要在 google 上写下你的问题,就能帮你找到很多具体的教程!

编辑: 来自 keras 文档:

keras.utils.to_categorical(y, num_classes=None, dtype='float32')

将类向量(整数)转换为二进制类矩阵。例如。与 categorical_crossentropy 一起使用。 参数

  • y:要转换为矩阵的类向量(从 0 到 num_classes 的整数)。
  • num_classes:类的总数。
  • dtype:输入期望的数据类型,作为字符串(float32、float64、int32...)

返回:

输入的二进制矩阵表示。类轴放在最后。

# Consider an array of 5 labels out of a set of 3 classes {0, 1, 2}:
> labels
array([0, 2, 1, 2, 0])
# `to_categorical` converts this into a matrix with as many
# columns as there are classes. The number of rows
# stays the same.
> to_categorical(labels)
array([[ 1.,  0.,  0.],
       [ 0.,  0.,  1.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.],
       [ 1.,  0.,  0.]], dtype=float32)

【讨论】:

  • 我在考虑 Keras,但令人困惑的部分是我必须利用所有功能以及 LSTM,但是如何将带有字符串的列转换为标记化?也在想one-hot encoding
  • 你现在用了什么?张量流?还有什么?
  • 我在预处理阶段,可以使用任何一种TF或Keras。
  • 字符串只是分类数据,因此您可以对其进行一次性编码。
  • 混合数据教程将帮助您将所有列作为输入
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-01
  • 2016-04-12
  • 1970-01-01
  • 2018-07-06
  • 2021-09-25
  • 2020-04-16
  • 1970-01-01
相关资源
最近更新 更多