%%% learns logistic regression weights using the NN toolbox %%% ************************************************************* %%% Milos Hauskrecht %%% CS2750 Machine Learning, University of Pittsburgh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% load the train and test data (both are normalized) load pima_train.txt; load pima_test.txt; tr_data = pima_train; test_data = pima_test; data_col= size(tr_data,2) n_features = data_col - 1 %%% 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 one layer neural network with logistic function output %%% to be trained with the gradient method net=newff(minmax(x'),[1],{'logsig'},'traingd'); %% sets the parameters 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 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 (logistic)' error = mean_misclass_error(round(res'),y); %% 'Mean training error (logistic)' error = mean_misclass_error(round(res'),y);