How to fix smile NeuralNetwork for regression which outputs always the same prediction

112 Views Asked by At

I am using the smile library for training a neural network for a simple nonlinear regression problem. For every input I get the same prediction. Maybe I am doing something wrong with the construction of the neural network. Could you maybe suggest what am I missing? I am not including the data because of legal reasons ex. [1, 3, 8, 15, 7 ...]

    int[] units=new int[4];
    units[0]=1;
    units[1]=10;
    units[2]=10;
    units[3]=1;
    smile.regression.NeuralNetwork net =
        new smile.regression.NeuralNetwork(
         smile.regression.NeuralNetwork.ActivationFunction.LOGISTIC_SIGMOID,
         units);

    int epochs=10;
    for (int i = 0; i < epochs; i++) {
        net.learn(data, label);
    }

    double[] pred = new double[label.length];
    double maxError=0.0;
    for (int i = 0; i < label.length; i++) {
        pred[i] = net.predict(data[i]);
        double error=Math.abs(pred[i]-label[i]);
        if(error>maxError){
            maxError=error;
        }
        System.out.println("For data "+data[i][0]);
        System.out.println(pred[i]+" "+label[i]);
    }
1

There are 1 best solutions below

0
On

I belive it is due to your unit vector, it should only contain 3 numbers: the number of input layers = number of features the number of hidden layers and the number of output layers = 1