【问题标题】:How to train multiple matrix with binary arrays如何用二进制数组训练多个矩阵
【发布时间】:2019-11-19 14:45:55
【问题描述】:

我有七个矩阵和几个数组。每个数组都有二进制元素,每个矩阵都是心电图信号的一类。 对于训练,我有 7 个矩阵,每个矩阵有 110 个数组,其中包含许多表示 ecg 信号的二进制元素(只有 0 和 1,其中 1 是空白,0 是代表信号的黑色部分)。 对于测试,我有 7 个相同的矩阵,有 30 个数组。

应该如何制作模型来训练这些矩阵,我应该如何做这个机器学习算法? 这就是火车矩阵的样子

[[1. 1. 1. ... 1. 1. 1.] ->this is array 1
 [1. 1. 1. ... 1. 1. 1.] ->this is array 2
 [1. 1. 1. ... 1. 1. 1.]
 ...//here are a lot of numbers, including 0
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]] -> this is array 110

这就是测试矩阵的样子:

[[1. 1. 1. ... 1. 1. 1.] ->this is array 1
 [1. 1. 1. ... 1. 1. 1.] ->this is array 2
 [1. 1. 1. ... 1. 1. 1.]
 ... //here are a lot of numbers, including 0
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]] -> this is array 30```

【问题讨论】:

  • 如果你把它转换成一个 numpy 数组,每个机器学习算法都可以处理它,因为它们都是分类特征。这里有很多例子:scikit-learn.org/stable

标签: python arrays machine-learning matrix


【解决方案1】:

将其转换为 numpy 数组并使用机器学习模型对其进行训练。这是一个示例

import numpy as np 
features=np.random.choice([0,1], (110,6), p=[0.5, 0.5]) # Generating random numpy array with values 0&1 for training
targets = np.random.choice([0,1], (110,), p=[0.5, 0.5])
test_features = np.random.choice([0,1], (50,6), p=[0.5, 0.5]) # Test set
test_targets = np.random.choice([0,1], (50,), p=[0.6, 0.4])

from sklearn.tree import DecisionTreeClassifier # Training algo of your choice
from sklearn.metrics import accuracy_score 
model = DecisionTreeClassifier() 
model.fit(features,targets)
pred = model.predict(test_features) # Inference of test set
accuracy_score(test_targets,pred) # Evaluation 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    • 2012-06-02
    • 2016-09-07
    • 2018-12-07
    相关资源
    最近更新 更多