Message Boards Message Boards

Fix output of Neural Network predict method?

Hi,

How do I fix the predicted values (YPrediction) when I run the program every time.

Input: X1   Output: Y

In[1]:= Y = {14.437499999999996`, 13.629166666666666`, 11.016666666666666`, 
   9.254166666666666`, 9.483333333333334`, 11.029166666666669`, 
   9.916666666666668`, 8.637500000000001`, 10.629166666666666`, 
   11.399999999999999`, 12.962500000000002`, 13.320833333333333`, 
   16.14166666666667`, 16.425`, 15.149999999999995`, 13.791666666666664`, 
   12.908333333333331`, 10.83333333333333`, 8.674999999999997`, 9.7625`, 
   10.595833333333333`, 9.266666666666666`, 9.0625`, 9.333333333333332`, 
   10.866666666666664`, 12.741666666666664`, 12.158333333333333`, 
   14.470833333333331`, 15.666666666666668`, 15.625`, 14.891666666666667`, 
   13.454166666666662`, 10.083333333333332`, 8.029166666666663`, 
   9.504166666666666`, 9.683333333333334`, 8.879166666666666`, 
   8.691666666666663`, 7.862499999999999`, 10.416666666666668`, 
   12.137500000000003`, 10.9`, 14.554166666666667`, 17.82083333333333`, 
   20.55416666666666`, 20.104166666666664`, 17.129166666666663`, 
   12.866666666666667`, 9.112499999999997`, 8.5125`, 9.245833333333334`, 
   8.624999999999998`, 8.2375`, 7.391666666666666`, 9.820833333333333`, 
   11.6375`, 13.145833333333337`, 17.8125`, 22.883333333333333`, 
   25.108333333333334`, 25.162499999999998`, 20.825`, 17.416666666666664`, 
   13.7`, 11.683333333333332`, 11.283333333333331`, 10.687500000000002`, 
   8.691666666666666`, 6.866666666666665`, 12.6875`, 16.437499999999996`, 
   19.112499999999997`, 22.66666666666667`, 28.09583333333333`, 
   28.758333333333333`, 27.95833333333333`, 23.349999999999998`, 
   21.40416666666666`, 17.720833333333335`, 14.187499999999995`, 14.625`, 
   16.724999999999998`, 12.983333333333334`, 9.787499999999998`, 
   17.379166666666663`, 22.091666666666672`, 24.7125`, 27.208333333333332`, 
   32.89583333333333`, 32.98333333333333`, 30.199999999999992`, 
   25.762499999999996`, 24.854166666666664`, 20.595833333333335`, 
   16.858333333333334`, 17.674999999999997`, 19.870833333333334`, 17.95`, 
   13.591666666666669`, 19.870833333333334`};
X1 = {16.625`, 14.437499999999996`, 13.629166666666666`, 11.016666666666666`, 
   9.254166666666666`, 9.483333333333334`, 11.029166666666669`, 
   9.916666666666668`, 8.637500000000001`, 10.629166666666666`, 
   11.399999999999999`, 12.962500000000002`, 13.320833333333333`, 
   16.14166666666667`, 16.425`, 15.149999999999995`, 13.791666666666664`, 
   12.908333333333331`, 10.83333333333333`, 8.674999999999997`, 9.7625`, 
   10.595833333333333`, 9.266666666666666`, 9.0625`, 9.333333333333332`, 
   10.866666666666664`, 12.741666666666664`, 12.158333333333333`, 
   14.470833333333331`, 15.666666666666668`, 15.625`, 14.891666666666667`, 
   13.454166666666662`, 10.083333333333332`, 8.029166666666663`, 
   9.504166666666666`, 9.683333333333334`, 8.879166666666666`, 
   8.691666666666663`, 7.862499999999999`, 10.416666666666668`, 
   12.137500000000003`, 10.9`, 14.554166666666667`, 17.82083333333333`, 
   20.55416666666666`, 20.104166666666664`, 17.129166666666663`, 
   12.866666666666667`, 9.112499999999997`, 8.5125`, 9.245833333333334`, 
   8.624999999999998`, 8.2375`, 7.391666666666666`, 9.820833333333333`, 
   11.6375`, 13.145833333333337`, 17.8125`, 22.883333333333333`, 
   25.108333333333334`, 25.162499999999998`, 20.825`, 17.416666666666664`, 
   13.7`, 11.683333333333332`, 11.283333333333331`, 10.687500000000002`, 
   8.691666666666666`, 6.866666666666665`, 12.6875`, 16.437499999999996`, 
   19.112499999999997`, 22.66666666666667`, 28.09583333333333`, 
   28.758333333333333`, 27.95833333333333`, 23.349999999999998`, 
   21.40416666666666`, 17.720833333333335`, 14.187499999999995`, 14.625`, 
   16.724999999999998`, 12.983333333333334`, 9.787499999999998`, 
   17.379166666666663`, 22.091666666666672`, 24.7125`, 27.208333333333332`, 
   32.89583333333333`, 32.98333333333333`, 30.199999999999992`, 
   25.762499999999996`, 24.854166666666664`, 20.595833333333335`, 
   16.858333333333334`, 17.674999999999997`, 19.870833333333334`, 17.95`, 
   13.591666666666669`};

In[3]:= tuples = Thread[Transpose[{X1}] -> Y];

In[4]:= Length[tuples]

Out[4]= 100

In[5]:= train = Take[tuples, 70];

In[6]:= test = Take[tuples, -30];

In[12]:= cfunc = Predict[train, Method -> "NeuralNetwork", 
  PerformanceGoal -> "Quality"]

Out[12]= PredictorFunction[\[Ellipsis]]

In[13]:= YPrediction = Map[cfunc, test[[All, 1]]];

In[14]:= YObserved = test[[All, 2]];

In[15]:= Correlation[YPrediction, YObserved]

Out[15]= 0.721966

In[16]:= ListLinePlot[{YPrediction, YObserved}]
POSTED BY: M.A. Ghorbani
4 Replies

I interpret your question in a way that you would like to improve your result. Being definitely not experienced in machine learning but simply looking at you data, I find:

enter image description here

From this you are using the first 70 tuples for learning and the last 30 for testing. I guess one can not expect under these conditions a good result.

As a probably better approach you might try:

train = RandomSample[tuples, 70];
test = Complement[tuples, train];
Length /@ {train, test}
(*  Out:  {70,30}  *)

Using this I get (e.g.):

Correlation[YPrediction, YObserved]
(*  Out:  0.9251388656090284`  *)
POSTED BY: Henrik Schachner

Thank you, Henrik.

When I run the below command each time: " cfunc = Predict[train, Method -> "NeuralNetwork", PerformanceGoal -> "Quality"] "

I got different answers for the Correlation value.

I would like to fix the predicted values.

Thank you again.

POSTED BY: M.A. Ghorbani

Does it help to set an explicit value for the RandomSeeding option?

POSTED BY: Daniel Lichtblau

Daniel,

I tried different ways, I could not get the expected a fixed output. Could you please show me how I can do it with RandomSeeding option for the above example?

Thanks a lot.

POSTED BY: M.A. Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract