我有以下数据集,
第 1 至 6 列
1.0000 0 0.9954 -0.0589 0.8524 0.0231
1.0000 0 1.0000 -0.1883 0.9304 -0.3616
1.0000 0 1.0000 -0.0336 1.0000 0.0049
1.0000 0 1.0000 -0.4516 1.0000 1.0000
1.0000 0 1.0000 -0.0240 0.9414 0.0653
1.0000 0 0.0234 -0.0059 -0.0992 -0.1195
1.0000 0 0.9759 -0.1060 0.9460 -0.2080
0 0 0 0 0 0
1.0000 0 0.9636 -0.0720 1.0000 -0.1433
我正在尝试使用二进制分割来构建决策树,其中一个问题是数据是连续的,而我当前的实现通过保留数据原样并进行分割而变得计算密集。我必须说,如果您只是构建一个分类器,那么这会很糟糕。
就我而言,我将分类器的数量增加了 10 倍,从 5 增加到 50(装袋)。我本想以这种方式进行分箱,将数据分入 0.2 个桶,但我意识到存在负数。我正在使用 matlab 进行实现。我是一个 Matlab 新手,不确定是否有预定义方法来处理这样的场景。
最佳答案
不确定这是否完全解决了您的问题,但如果您的问题是动态定义“存储桶”,您可以这样做:
% Find the minimum and maximum of the matrix
Mmin = min(M(:));
Mmax = max(M(:));
% Assume you have a matrix M with positive and negative values, and want it in bins of 0.2
buckets = Mmin:0.2:Mmax;
% OR assume you want to spread them equally over a fixed amount of bins, say 100
buckets = linspace(Mmin,100,Mmax);
编辑:
假设你想根据一列的值来划分矩阵,比如 3,那么你可以这样做:
% Define the relevant column as a vector for easy handling
v = M(:,3);
% Assume you want to spread them equally over a fixed amount of bins, say 100
buckets = linspace(min(v),100,max(v));
% Now see which column belongs in each bucket
bucket_idx = ones(size(v));
for i = 2:length(buckets)
bucket_idx(v>buckets(i-1)&(v<buckets(i)) = i;
end
这会告诉您每行属于哪个存储桶,将其矢量化会更好,但目前这是我能想到的最快的解决方案。我认为一旦你知道所有东西都属于哪个桶,你就应该能够解决剩下的问题。
关于matlab - 离散连续数据的分箱技术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13458603/