How to make a hybrid model (LSTM and Ensemble) in MATLAB - matlab

I am working on C02 prediction in matlab. My data set is 3787 (Including test and validation set). I am trying to predict the CO2 with a Standard Deviation of 179.60. My number of predictor is 15 and response is 1. Within that predictors I have two types of datasets (1. Sequential number data such as temperature and humidity, 2. Conditions i.e yes/no ). So that I have decided to use two types of networks to train my model.
1) LSTM - For the sequential data
2) Ensemble or SVM - for the yes/no data
3) Combine two models and predict the response variable.
How to achieve this? Can anyone help me to achieve this?

Related

Concept of validate for neural network

I have a problem with concept of Validation for NN. suppose I have 100 set of input variables (for example 8 input, X1,...,X8) and want to predict one Target(Y). now I have two ways to use NN:
1- use 70 set of data for training NN and then use trained NN to predict other 30 sets of Target for validation and then plot output VS Target for this 30 sets as validation plot.
2- use 100 sets of data for training NN and then divide all outputs to two part (70% and 30%). plot 70% of outputs VS corresponding Targets as Training plot. then plot other 30% outputs VS their corresponding Targets as validation plot
Which one is correct??
Also, what the difference between checking NN with new data set and validation data set??
Thanks
You cannot use data for validation, if it has been already used for the training, because the trained NN will already "know" your validation examples. The result of such validation will be very biased. I would for sure use the first way.

Reuse dimensionality reduction after designing model with Matlab

I'm using a binary classification with SVM and MLP for financial data. My input data has 21 features so I used dimensionally reduction methods for reducing the dimension of data. Some dimensionally reduction methods like stepwise regression report best features so I will used these features for my classification mode and another methods like PCA transform data to a new space and I use for instance 60% of best reported columns (features). The critical problem is in the phase of using final model. For example I used the financial data of past year and two years ago for today financial position. So now I want use past and today data to prediction next year. My question is here: Should I use PCA for new input data before inserting to my designed classification model? How can I use (For example Principal component analysis) for this data? I must use it like before? (pca(newdata…)) or there is some results from last PCA that I must use in this phase?
more information :
This is my system structure:
I have a hybrid classification method with optimization algorithm for select best features (inputs) of my model and best parameters of my classification method so for a classification method like MLP I takes long time to optimization with 21 features (beside of this I repeat every iteration of my optimization algorithm 12 times / cross section ) . So I want decrease the features with dimensionally reduction techniques (like PCA, NLPCA or supervised methods like LDA/FDA) before insert it to classification method. For example I’m using this structure of PCA code:
[coeff,score,latent,tsquared,explained,mu] = pca(_)
After that I will use 10 first columns of output (that sorted by PCA function) for input of my classification and optimization model. In final phase I will find the best model parameters with the best combination of inputs. For example my raw data has 21 features. After first phase of using PCA I will choose 10 features and in final model after optimization of my classification model. I will have a model with 5 best chosen features. Now I want use this model with new data. What must I do?
Thank you so much for your kind helps.
You should follow the following steps:
With your training data, create a PCA model
With the PCA of your training data, train your classifier
Apply the first PCA model to your new data
With the PCA of your new data, test the classifier
Here are some code snippets for steps 1 and 3 (2 and 4 depend on your classifier):
%Step 1.Generate a PCA data model
[W, Y] = pca(data, 'VariableWeights', 'variance', 'Centered', true);
%# Getting the correct W, mean and weights of data (for future data)
W = diag(std(data))\W;
[~, mu, we] = zscore(data);
we(we==0) = 1;
%Step 3.Apply the previous data model to a new vector
%# New coordinates as principal components
x = newDataVector;
x = bsxfun(#minus,x, mu);
x = bsxfun(#rdivide, x, we);
newDataVector_PCA = x*W;

Neural network for pattern recognition

I want you to help me figure out which problem am I dealing with (pattern recognition or time series forecasting) and find the best NN architecture suited for this problem.
In my problem, I have many finite sets of two dimensional data (learning sets)
Lets N be the size of the data set I want to calculate using the NN.
I want my NN to learn these data and by giving it the first m data of the data set it gives me the remaining N-m data.
I think it's rather a pattern recognition problem, so which is the best NN architecture suited for this kind.
Thank you.
As far as I have understood you problem, you have a dataset with N rows. And you want to train your network using first M rows. And then you want your NN to predict the rest N-M rows.
Typically, in forecasting (timeseries prediction), we do this kind of stuffs. We train our model with historical data and try to predict future values.
So, in your case, top M rows could be training data in the training phase.And during the model accuracy evaluation phase, future values could be your N-M rows.
Typically, recurrent networks are best suited for temporal data, because, they can take care of ordered data.
ENCOG also provides a special dataset for temporal data.And you can use them for your problem.

How to use created "net" neural network object for prediction?

I used ntstool to create NAR (nonlinear Autoregressive) net object, by training on a 1x1247 input vector. (daily stock price for 6 years)
I have finished all the steps and saved the resulting net object to workspace.
Now I am clueless on how to use this object to predict the y(t) for example t = 2000, (I trained the model for t = 1:1247)
In some other threads, people recommended to use sim(net, t) function - however this will give me the same result for any value of t. (same with net(t) function)
I am not familiar with the specific neural net commands, but I think you are approaching this problem in the wrong way. Typically you want to model the evolution in time. You do this by specifying a certain window, say 3 months.
What you are training now is a single input vector, which has no information about evolution in time. The reason you always get the same prediction is because you only used a single point for training (even though it is 1247 dimensional, it is still 1 point).
You probably want to make input vectors of this nature (for simplicity, assume you are working with months):
[month1 month2; month2 month 3; month3 month4]
This example contains 2 training points with the evolution of 3 months. Note that they overlap.
Use the Network
After the network is trained and validated, the network object can be used to calculate the network response to any input. For example, if you want to find the network response to the fifth input vector in the building data set, you can use the following
a = net(houseInputs(:,5))
a =
34.3922
If you try this command, your output might be different, depending on the state of your random number generator when the network was initialized. Below, the network object is called to calculate the outputs for a concurrent set of all the input vectors in the housing data set. This is the batch mode form of simulation, in which all the input vectors are placed in one matrix. This is much more efficient than presenting the vectors one at a time.
a = net(houseInputs);
Each time a neural network is trained, can result in a different solution due to different initial weight and bias values and different divisions of data into training, validation, and test sets. As a result, different neural networks trained on the same problem can give different outputs for the same input. To ensure that a neural network of good accuracy has been found, retrain several times.
There are several other techniques for improving upon initial solutions if higher accuracy is desired. For more information, see Improve Neural Network Generalization and Avoid Overfitting.
strong text

cross validation process

I am working on a voice morphing system. I have source speech signal (divided into test, train & validation) and target speech signal (divided into test, train and validation data). Now I'am designing a radial basis neural network with 3 fold cross validation to find the morphed speech wavelet coefficients. I need to initialize the net with source and target training data and perform 3 fold cross validation using training and validation samples.
I think that as per the cross validation I need to divide my data set into 3 parts and then use 2 of them for training and the other for testing. (Repeating the process for all the folds). Now the problem is that I want to know that weather I need to divide my source training data into 3 parts or the target training...??
Thus I need to know how to apply the cross validation? Can anyone please elaborate the process for me?
You should randomly divide your entire data (tuples of input ["source"] and output ["target"/"morphed"] observations) into 3 sets: training, cross-validation, and test.
The training set will be used to train each neural network you try. The cross-validation set will be used after each network is trained, in order to select the best parameters (# of hidden nodes, etc, etc). The test set is used at the end to validate the overall performance (i.e. accuracy, generalization, etc.) of the final model.