# Fix output of Neural Network predict method?

**URL:** <https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189>\
**Category:** Questions\
**Tags:** data-science, modeling, machine-learning, neural-networks\
**Created:** [June 8, 2019, 3:59am UTC](https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189 "2019-06-08T03:59:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [June 8, 2019, 3:59am UTC](https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189/1 "2019-06-08T03:59:23Z")

</div>

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}]

```

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [June 8, 2019, 3:05pm UTC](https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189/2 "2019-06-08T15:05:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [June 18, 2019, 4:17am UTC](https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189/3 "2019-06-18T04:17:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [June 18, 2019, 8:18am UTC](https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189/4 "2019-06-18T08:18:39Z")

</div>

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:

 ![GhorbaniData.png](https://global.discourse-cdn.com/wolfram/original/2X/a/a61548c262a5a587581acb38b7804e988896a79b.png)

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` *)

```

---

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [June 18, 2019, 10:49am UTC](https://community.wolfram.com/t/fix-output-of-neural-network-predict-method/14189/5 "2019-06-18T10:49:01Z")

</div>

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.
