Answers.Body: <p>The short answer to your question is: you probably do not fully know your data. remember that ML is no magic wand. It needs your understanding of the data and the behavior of it. Although it is approved that neural networks with at most two hidden layers can approximate <strong>any</strong> model with an acceptable degree precision, setting up the structure of the neural network is still your task; also note that the cleaner your data is, the more acceptable the degree of precision will be for a structured NN.</p>
  
  <p>the following more detailed explanation might also help. <strong>understanding your data</strong> that I pointed above, means:</p>
  
  <ol>
  <li><p>the <strong>design of your machine learning pipeline</strong> is the first and most important thing to take care of. Are you sure you have handled training set and test set appropriately? are the ratios standard? have you performed random sampling well?</p></li>
  <li><p>the <strong>size of the dataset</strong> is also a matter of consideration. remember a ratio of <code>n/p&gt;10</code> (n: the number of instances, p: the number of features) is necessary. So if you have 7 features, you should have more than around 100 instances. check how big is your dataset</p></li>
  <li><p>the <strong>distribution of your dataset</strong> is also important. dealing with badly distributed data should be considered if you have an issue here. use plots and histograms to understand the distribution of your dataset over feature axes. There is a high risk of overfitting if your data is distributed badly</p></li>
  <li><p>also take care of your <strong>output distribution</strong>. with a bad distribution over your output data (focused outputs in a zone) you loose the power of generalization of your model</p></li>
  <li><p>check the relations between different features. check if there are any pairs of <strong>dependent variables</strong>. you can use scatter plot or calculating pairwise covariances. PCA or more complicated methods (like auto-encoders) will be of help if there is any issue here</p></li>
  <li><p>one possibility is maybe your data doesn't carry any latent information at all. maybe <strong>the underlying pattern is so stochastic and nonlinear that it seems to be random</strong>. in other words: you can not predict what kind of food your grandma has cooked by looking at results of world cup games, no matter how big your dataset is.</p></li>
  </ol>
  
  <p>Now about your output matrix:</p>
  
  <p>reshaping your matrix to an array of 144 might be the best or the worst thing to do. it depends on the characteristics of your data. maybe the position of each element in the matrix is also important in predicting the value. so you might want to include the <code>i,j</code> of each element in the input array too. maybe each output also takes effect from neighbors. there are some other options to consider:</p>
  
  <ol>
  <li><p>you can <strong>use 144 different MLP networks</strong>, one for each element (a little bit like what you have already done, when reshaping your matrix. since your library constructs a single MLP network that has 144 neurons in the output layer. so it seems like 144 networks that only vary in the output layer, and note that the weight correction step is different too, since the training error for all of the outputs propagate back in the layers simultaneously)</p></li>
  <li><p>you can <strong>create 144 instances out of each instance</strong>, each of which has 7+2 inputs and 1 output. the 2 more inputs are the position of the output value (i,j). it might be a poor decision to do that but this method has helped me a couple of times, so test it</p></li>
  <li><p>Do the second step, but <strong>include the neighbor values too.</strong> so you'd have for example 7+2+4 inputs (7 initial + 2 i,j + 4 neighbor values)</p></li>
  <li><p>also <strong>consider using RNNs</strong> (recurrent neural networks). if you consider the matrix to be a sequence of values which has internal dependency plus the external dependency to those 7 features, then you can use a RNN network like LSTM.</p></li>
  </ol>
  
  <p>feel free to update your post with more specific experiments and issues.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-25T16:48:26.690Z
Answers.Text: Updated op with more details about the problem. But i'll do some more tests considering your points, they helped a lot and made me think better about the problem. Thank you very much!
Answers.UserDisplayName: Fuga
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-25T14:00:59.530Z
Answers.LastActivityDate: 2017-10-25T14:00:59.530Z
Answers.UserDisplayName: Alireza
Body: <p>So, i need to use an MLP to predict a 12x12 matrix composed of floating points. 
  The matrices are as this one that follows:
  <a href="https://i.sstatic.net/j8pfK.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/j8pfK.jpg" alt="enter image description here"></a>
  Most matrices have this "pattern".</p>
  
  <p>As input, i have 7 floating points, such as these:</p>
  
  <p>"2.0", "0.23", "239.10","3.5", "12,0", "10.6", "0.62".</p>
  
  <p>To simplify the output matrix, i've converted it in a array with the 144 elements of the matrix.
  So far i'm using MLPRegressor from Scikit.The problem is, there's absolutely no pattern in the predicted results.The predicted results include negative numbers, numbers really big and no "pattern" for the indexes whatsoever.
  Is there a way to adjust these things in the model or the problem is on my dataset?
  Thank you very much!</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I wasn't very clear about the problem, so i'll try to explain it better.</p>
  
  <p>About the problem: Predict water distribution in irrigation systems. I already have a program to simulate this, and works with rather good precision. The challenge now was to make an AI model to simulate this, instead of the old methods.</p>
  
  <p>About the inputs: Inputs are one float representing the pressure of the sprinkler used to distribute water, two floats representing the speed and angle of the wind at the time data was collected. The 4 remaining are numbers representing some configuration of the sprinker (these numbers change very little between instances, but they do have impact in the result, which is why i decided to mantain them in the dataset).</p>
  
  <p>About the output: Output is an array of 144 elements, representing the 12*12 matrix. Each element of the matrix contain a number representing the amount of water that was collected in that point. These collectors where evenly spread around the sprinkler. So the position of the matrix matter a lot, since in most cases the first and last lines and columns will have 0 or a close to 0 (but positive) number - this may vary depending especially on the speed and angle of the wind, but also on the sprinkler.</p>
  
  <p>About the dataset: I have available 75 instances. They are all stored in a CSV file, where the 7 inputs and the 144 outputs are, each in one line.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-25T12:25:35.690Z
Comments.Text: I think that MLP is not a suitable solution in your case and autoencoders are more suitable for your task. However, no guarantees that even AE with the best architecture will work, since it’s not a fact, that your input data contains enough information for such reconstruction. However, if you don’t insist on MPL and can consider using AE instead, I can give you an answer with suggestions how doing it. If you can share your data I even can check it and give you more precise answer . You can find the simple CAE sample here - https://stackoverflow.com/questions/46921246/issue-with-simple-cae
Comments.UserDisplayName: Stepan Novikov
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-25T16:50:03.353Z
Comments.Text: Just updated op with more details. Will do some reading about AE. Thank you!
Comments.UserDisplayName: Fuga
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-26T13:14:03.040Z
Comments.Text: I think that 75 examples is not enough for good accuracy, therefore it probably can be up to 80-90% for a such small dataset. However, could you share your dataset, so I will be able to test model with it?
Comments.UserDisplayName: Stepan Novikov
Tags: <multilayer-perceptrons>
Title: Using a MLP to predict a 12x12 matrix
UserDisplayName: Fuga
ThreadText: # Using a MLP to predict a 12x12 matrix
  
  (Asked by: username_0 on 2017-10-25)
  
  So, i need to use an MLP to predict a 12x12 matrix composed of floating points.
  The matrices are as this one that follows:
  [![enter image description here](https://i.sstatic.net/j8pfK.jpg)](https://i.sstatic.net/j8pfK.jpg)
  Most matrices have this "pattern".
  
  As input, i have 7 floating points, such as these:
  
  "2.0", "0.23", "239.10","3.5", "12,0", "10.6", "0.62".
  
  To simplify the output matrix, i've converted it in a array with the 144 elements of the matrix.
  So far i'm using MLPRegressor from Scikit.The problem is, there's absolutely no pattern in the predicted results.The predicted results include negative numbers, numbers really big and no "pattern" for the indexes whatsoever.
  Is there a way to adjust these things in the model or the problem is on my dataset?
  Thank you very much!
  
  **Update:**
  
  I wasn't very clear about the problem, so i'll try to explain it better.
  
  About the problem: Predict water distribution in irrigation systems. I already have a program to simulate this, and works with rather good precision. The challenge now was to make an AI model to simulate this, instead of the old methods.
  
  About the inputs: Inputs are one float representing the pressure of the sprinkler used to distribute water, two floats representing the speed and angle of the wind at the time data was collected. The 4 remaining are numbers representing some configuration of the sprinker (these numbers change very little between instances, but they do have impact in the result, which is why i decided to mantain them in the dataset).
  
  About the output: Output is an array of 144 elements, representing the 12\*12 matrix. Each element of the matrix contain a number representing the amount of water that was collected in that point. These collectors where evenly spread around the sprinkler. So the position of the matrix matter a lot, since in most cases the first and last lines and columns will have 0 or a close to 0 (but positive) number - this may vary depending especially on the speed and angle of the wind, but also on the sprinkler.
  
  About the dataset: I have available 75 instances. They are all stored in a CSV file, where the 7 inputs and the 144 outputs are, each in one line.
  
  **Tags:** multilayer-perceptrons
  > **Comments:**
  > **username_1**: I think that MLP is not a suitable solution in your case and autoencoders are more suitable for your task. However, no guarantees that even AE with the best architecture will work, since it’s not a fact, that your input data contains enough information for such reconstruction. However, if you don’t insist on MPL and can consider using AE instead, I can give you an answer with suggestions how doing it. If you can share your data I even can check it and give you more precise answer . You can find the simple CAE sample here - https://stackoverflow.com/questions/46921246/issue-with-simple-cae  
  > **username_0**: Just updated op with more details. Will do some reading about AE. Thank you!  
  > **username_1**: I think that 75 examples is not enough for good accuracy, therefore it probably can be up to 80-90% for a such small dataset. However, could you share your dataset, so I will be able to test model with it?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-10-25. Score: 2
  
  The short answer to your question is: you probably do not fully know your data. remember that ML is no magic wand. It needs your understanding of the data and the behavior of it. Although it is approved that neural networks with at most two hidden layers can approximate **any** model with an acceptable degree precision, setting up the structure of the neural network is still your task; also note that the cleaner your data is, the more acceptable the degree of precision will be for a structured NN.
  
  the following more detailed explanation might also help. **understanding your data** that I pointed above, means:
  
  1. the **design of your machine learning pipeline** is the first and most important thing to take care of. Are you sure you have handled training set and test set appropriately? are the ratios standard? have you performed random sampling well?
  2. the **size of the dataset** is also a matter of consideration. remember a ratio of `n/p>10` (n: the number of instances, p: the number of features) is necessary. So if you have 7 features, you should have more than around 100 instances. check how big is your dataset
  3. the **distribution of your dataset** is also important. dealing with badly distributed data should be considered if you have an issue here. use plots and histograms to understand the distribution of your dataset over feature axes. There is a high risk of overfitting if your data is distributed badly
  4. also take care of your **output distribution**. with a bad distribution over your output data (focused outputs in a zone) you loose the power of generalization of your model
  5. check the relations between different features. check if there are any pairs of **dependent variables**. you can use scatter plot or calculating pairwise covariances. PCA or more complicated methods (like auto-encoders) will be of help if there is any issue here
  6. one possibility is maybe your data doesn't carry any latent information at all. maybe **the underlying pattern is so stochastic and nonlinear that it seems to be random**. in other words: you can not predict what kind of food your grandma has cooked by looking at results of world cup games, no matter how big your dataset is.
  
  Now about your output matrix:
  
  reshaping your matrix to an array of 144 might be the best or the worst thing to do. it depends on the characteristics of your data. maybe the position of each element in the matrix is also important in predicting the value. so you might want to include the `i,j` of each element in the input array too. maybe each output also takes effect from neighbors. there are some other options to consider:
  
  1. you can **use 144 different MLP networks**, one for each element (a little bit like what you have already done, when reshaping your matrix. since your library constructs a single MLP network that has 144 neurons in the output layer. so it seems like 144 networks that only vary in the output layer, and note that the weight correction step is different too, since the training error for all of the outputs propagate back in the layers simultaneously)
  2. you can **create 144 instances out of each instance**, each of which has 7+2 inputs and 1 output. the 2 more inputs are the position of the output value (i,j). it might be a poor decision to do that but this method has helped me a couple of times, so test it
  3. Do the second step, but **include the neighbor values too.** so you'd have for example 7+2+4 inputs (7 initial + 2 i,j + 4 neighbor values)
  4. also **consider using RNNs** (recurrent neural networks). if you consider the matrix to be a sequence of values which has internal dependency plus the external dependency to those 7 features, then you can use a RNN network like LSTM.
  
  feel free to update your post with more specific experiments and issues.
  
  > **Comments:**
  > **username_0**: Updated op with more details about the problem. But i'll do some more tests considering your points, they helped a lot and made me think better about the problem. Thank you very much!  
  
  ---
  
  