【发布时间】:2018-09-27 08:14:02
【问题描述】:
我正在尝试学习机器学习。我是 F# 的新手。 对于给定的数据集,假设我有 2 个字符串数组。
let labels = [|"cat"; "dog"; "horse"|]
let scan_data = [|"cat\1.jpg"; "cat\2.jpg"; "dog\1.jpg"; "dog\2.jpg"; "dog\3.jpg"; "horse\1.jpg"; "horse\2.jpg"; "horse\3.jpg"; "horse\4.jpg"; "horse\5.jpg"|]
您一定猜到了,有 3 个标签(是一种文件夹)包含训练图像数据(共 10 个)。我想使用以上 2 个数组来创建,这样的数组:
let data_labels = [| //val data_labels : int [] []
[|1; 0; 0|]; //since 0th scan_data item represent "cat"
[|1; 0; 0|];
[|0; 1; 0|]; //since 2nd scan_data item represent "dog"
[|0; 1; 0|];
[|0; 1; 0|];
[|0; 0; 1|]; //since 5th scan_data item represent "horse"
[|0; 0; 1|];
[|0; 0; 1|];
[|0; 0; 1|];
[|0; 0; 1|];
|]
因此,只要在“scan_data”项中找到匹配的子字符串(来自“labels”),就应该有一个数组表示匹配为“1”,而没有匹配为“0”。 关于如何在 F# 中实现这一点的任何想法。
【问题讨论】:
标签: arrays string machine-learning f# functional-programming