Here is my code:
function testRegression()
load carsmall
x1 = Weight;
x2 = Horsepower; % Contains NaN data
y = MPG;
X = [ones(size(x1)) x1 x2 x1.*x2];
X(isnan(X)) = 0;
y(isnan(y)) = 0;
for i = 2:size(X,2)
X(:,i) = (X(:,i) - min(X(:,i))) / (max(X(:,i)) - min(X(:,i)));
end
y = (y - min(y)) / (max(y) - min(y));
model = train(y,sparse(X),'s 0');
[a,b,c] = predict(y, sparse(X), model);
end
I am always getting 0 for prediction. What is the problem with my code? When I dont normalize y, I am getting some output, however when I normalize the output is always 0.
You shouldn't be normalizing the output values. The point of normalizing is to do it only for the input features. This decreases the dynamic range of the input features so that it makes the model easier to train. The output values need to stay the same because those are the true values you are trying to predict. By normalizing the output values, you are effectively shrinking the dynamic range of the expected outputs, meaning that small variances in your input features largely affect what the output is.
tl;dr: You never normalize the expected output values.