📄 equalisedata.m.svn-base
字号:
function [newX, newY] = equaliseData(X, y, params);
%Make sure that the ratio of positive to negative examples is the same (in
%general) across any seqencial subset of the data
if ~binaryLabels(y)
newX = X;
newY = y;
return;
end
numExamples = size(X, 1);
numFeatures = size(X, 2);
positiveIndices = find(y == 1);
negativeIndices = find(y == -1);
numPositives = length(positiveIndices);
numNegatives = length(negativeIndices);
newPositiveIndices = floor((1:numPositives)*(numExamples/numPositives));
newNegativeIndices = setdiff(1:numExamples, newPositiveIndices);
if issparse(X)
newX = sparse(numExamples, numFeatures);
else
newX = zeros(numExamples, numFeatures);
end
newY = zeros(numExamples, 1);
newX(newPositiveIndices, :) = X(positiveIndices, :);
newX(newNegativeIndices, :) = X(negativeIndices, :);
newY(newPositiveIndices) = y(positiveIndices);
newY(newNegativeIndices) = y(negativeIndices);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -