%%% learns weights of a two layer NN using the NN toolbox %%% ************************************************************* %%% Milos Hauskrecht %%% CS2750 Machine Learning, University of Pittsburgh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% load the train and test data load pima_train.txt; load pima_test.txt; tr_data = pima_train; test_data = pima_test; %%% create x x = tr_data(:,1:n_features); %% create y vector y=tr_data(:,data_col); %% builds x for the the test set x_test = test_data(:,1:n_features); %% builds y vector for the test set y_test=test_data(:,data_col); %%% builds a two layer neural network with two hidden units and 1 output unit - parameter [2 1] %% logistic functions are used in both the hidden and the output units %%% to be trained with the gradient method net=newff(minmax(x'),[2 1],{'logsig','logsig'},'traingd'); %% sets the number of the NN model %% see the NN toolbox documentation net.trainParam.epochs = 2000; net.trainParam.show = 10; net.trainParam.max_fail=5; TV.P=x_test'; TV.T=y_test'; %%% training of the neural net %% supplying the test set allows to see the curves for train and test LMS errors [net, tr] = train(net,x',y',[],[],[],TV); %% simulates learned network on inputs in x % that is, it computes outputs for all inputs in x and current set of weights res=sim(net,x'); %%% 'Mean training error (MLP)' %%% error = mean_misclass_error(round(res'),y);