|
3.2.1 Data Format
To train a network, you need a set of data containing N input-output pairs. All of the functions in the package require the same data format. The input and output data are each arranged in the form of a Mathematica matrix. Each individual input vector, , is a vector on row i of the input data matrix, and each is a vector on row i of the output data matrix. An exception to this rule is when a neural network is applied to a single data item, in which case the data can be written as a vector rather than as a matrix.
Consider the sample data file one2twodimfunc.dat that is packaged with Neural Networks. This data item has N = 20 input-output pairs. Each is a vector of length 1, and each output item is a vector of length 2. To view the data, first load the package and then load the data file.
Load the Neural Networks package and the data file.
In[1]:=
In[2]:=
In this data file, the input and output matrices are assigned to the variable names x and y, respectively. Once the data set has been loaded, you can query the data using Mathematica commands. To better understand the data format and variable name assignment, you may also want to open the data file itself.
Show the contents of the input and output matrices.
In[3]:=
Out[3]=
In[4]:=
Out[4]=
Check the number of data items and the number of inputs and outputs for each data item.
In[5]:=
Out[5]=
Out[6]=
The data set contains 20 data items with one input and two outputs per item.
Look at input and output of data item 14.
In[7]:=
Out[7]=
Out[8]=
The next example demonstrates the data format for a classification problem. A classification problem is a special type of function approximation: the output of the classifier has discrete values corresponding to the different classes. You can work with classification as you would with any other function approximation, but it is recommended that you follow the standard described here so that you can use the special command options specifically designed for classification problems.
In classification problems input data is often called pattern vectors. Each row of the input data x contains one pattern vector, and the corresponding row in the output data y specifies the correct class of that pattern vector. The output data matrix y should have one column for each class. On each row the correct class is indicated with a 1 in the correct class position, with the rest of the positions containing 0. If the classification problem has only two classes, then you can choose to have only one column in y and indicate the classes with 1 or 0.
Consider the following example with three classes. The data is stored in threeclasses.dat in which the input matrix has been named x and the output data is assigned to matrix y. Although this is an artificially generated data set, imagine that the input data contains the age and weight of several children, and that these children are in three different school classes.
Load a data set.
In[9]:=
Look at the 25th input data sample.
In[10]:=
Out[10]=
The children are from three different groups. The group is indicated by the position of the 1 in each row of the output y.
Check to which class child 25 belongs.
In[11]:=
Out[11]=
Since there is a 1 in the second column, the 25th child belongs to the second class.
Examples of classification problems can be found in Chapter 4, The Perceptron; Chapter 11, Vector Quantization; Section 12.1, Classification of Paper Quality; and Chapter 9, Hopfield Networks.
|