python - 如何用二进制数组训练多个矩阵
问题描述
我有七个矩阵和几个数组。每个数组都有二进制元素,每个矩阵都是心电图信号的一类。对于训练,我有 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 数组并使用机器学习模型对其进行训练。这是一个示例
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
推荐阅读
- c# - 如何在 selenium c# 中隐藏 firefox 浏览器
- c# - 当我想选择gridview的当前行时遇到问题
- html - 如何在 4 个网格列的第 2 列之后留出空间?
- javascript - 通过json数组字典翻译变量文本
- html - 为什么页脚的内容不相邻
- java - StringIndexOutOfBoundsException 任何人都可以吗?
- php - 更改 WooCommerce 结帐国家/地区字段默认选项显示标签
- javascript - 如何在 Vuejs 的上下文中使用 Vue 组件中的 JavaScript 文件
- mysql - 我想只为我登录的用户获取记录。目前我可以获取所有用户的记录。请调查这个问题
- mysql - Magento 2.3.6 分层导航选择异常错误