【发布时间】:2020-03-21 23:26:03
【问题描述】:
我正在尝试编写一个从头开始制作决策树的代码。在某一时刻,我需要将我的 2D 数组(填充)数据拆分为多个 2D 数组,然后将这些数组拆分为更多数组。例如,如果我的二维数组中有这样的数据
sunny, hot, high, weak, no
sunny, hot, high, strong, no
overcast, hot, high, weak, yes
rain, mild, high, weak, yes
rain,cool, normal, weak, yes
rain, cool, normal, strong, no
overcast, cool, normal, strong, yes
sunny, mild, high, weak, no
sunny, cool, normal, weak, yes
rain, mild, normal, weak, yes
sunny, mild, normal, strong, yes
overcast, mild, high, strong, yes
overcast, hot, normal, weak, yes
rain, mild, high, strong, no
所以我将有一个代码来计算要拆分的最佳列,然后我希望它拆分它。例如,假设我想根据第一列的值进行拆分。结果将是三个子集
sunny rain overcast
sunny, hot, high, weak, no rain, mild, high, weak, yes overcast, hot, high, weak, yes
sunny, hot, high, strong, no rain,cool, normal, weak, yes overcast, cool, normal, strong, yes
sunny, mild, high, weak, no rain, cool, normal, strong, no overcast, mild, high, strong, yes
sunny, cool, normal, weak, yes rain, mild, normal, weak, yes overcast, hot, normal, weak, yes
sunny, mild, normal, strong, yes rain, mild, high, strong, no
然后我想使用相同的算法,找到要拆分的最佳值,然后再次拆分,例如,假设我想根据第四列的值再次拆分 Sunny 数组。这次的结果将是两个子集
weak strong
sunny, hot, high, weak, no sunny, hot, high, strong, no
sunny, mild, high, weak, no sunny, mild, normal, strong, yes
sunny, cool, normal, weak, yes
我知道逻辑应该是这样的
split(featureToSplitOn, data)
int bestColumn=findBestColumnToSplitOn();
for every value in best column
split(value,subset);
但老实说,我不知道该怎么做。有什么想法吗?
【问题讨论】:
-
定义“要拆分的最佳列”。描述您的需求确实可以帮助您了解如何为其编写代码。
标签: java arrays multidimensional-array decision-tree