python - 使用 LSTM 构建二元分类模型

标签 python machine-learning classification lstm text-classification

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

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

这是数据集的示例: enter image description here

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

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

谢谢,

最佳答案

以下两个教程可能会对您有所帮助:

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:类(class)总数。
  • 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)

关于python - 使用 LSTM 构建二元分类模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58285521/

相关文章:

python - 使用 Scrapy 获取 img src 会得到奇怪的结果,为什么?

python - 简单socket服务器的基本理解

machine-learning - 不同维度数据的分类器

machine-learning - 如何处理二元分类问题的多标签分类特征?

python - 神经网络(感知器) - 执行二元分类时可视化决策边界(作为超平面)

python - 如何在训练过程中纠正不稳定的损失和准确率? (二元分类)

python - 在获得最佳 TPOT 管道后获得 feature_importances_?

r - 几何段: Removed 1 rows containing missing values

python - 使用 SelectKBest 的问题 [scikit-learn]

python - 如何在嵌套循环中关闭 sys.stdout ,以便它不会将打印语句复制到文件中的内循环之外