Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %
- -------------------------------------------------------------------------
- % Credit Risk Assessment Toolbox
- %
- % Author: D. N. Sotiropoulos (2019)
- %
- -------------------------------------------------------------------------
- % This script file provides fundamental computational functionality
- for
- % training a fitnet type network for the problem of function
- % approximation. In fact, we are going to approximate the
- fico_range_low
- % and fico_range_high feature values as a function of the remaining
- % features. Therefore, the loan status related features will be
- ignored.
- % This neural netwrok simulator uses gpu computation assistance.
- % Clear command window and workspace.
- clc
- clear
- % Load dataset from file "LendingClub.mat" which creates the table
- type
- % variable lending_club_data_table. This table will be loaded into
- table T.
- load('LendingClub.mat');
- T = lending_club_data_table;
- clear lending_club_data_table
- % The following table columns will be excluded from the available set
- of
- % features upon which training will be conducted: =
- % ColumnID = 14 ==> VariableName = 'fico_range_low'
- % ColumnID = 15 ==> VariableName = 'fico_range_high'
- % ColumnID = 36 ==> VariableName = 'last_fico_range_high'
- % ColumnID = 37 ==> VariableName = 'last_fico_range_low'
- % ColumnID = 39 ==> VariableName = 'mths_since_last_derog'
- % ColumnID = 121 ==> VariableName = 'loan_status1'
- % ColumnID = 122 ==> VarialeName = 'loan_status2'
- % Set the variable names to be removed from training:
- RemoveVariableNames = {'fico_range_low','fico_range_high',...
- 'last_fico_range_high','last_fico_range_low',...
- 'mths_since_last_major_derog','loan_status1',...
- 'loan_status2'};
- % Set the feature data.
- Data = removevars(T,RemoveVariableNames);
- 1
- % Convert the feature data table to array.
- Data = table2array(Data)';
- % Set the feature labels.
- Targets = T.fico_range_low';
- % Set the network object.
- net = fitnet(10,'trainscg');
- % Configure the network object.
- net = configure(net,Data,Targets);
- % View network.
- view(net);
- % Initialize the network object.
- net = init(net);
- % Enable verbal output during training.
- net.trainParam.showCommandLine = true;
- % Enable visual output during training.
- net.trainParam.showWindow = true;
- % Devide the data randomly.
- net.divideFcn= 'dividerand';
- % Use the 70% of the available data for training purposes.
- net.divideParam.trainRatio= 0.7;
- % Use the 20% of the available data for validations purposes.
- net.divideParam.valRatio= 0.2;
- % Use the 10% of the available data for testing purposes.
- net.divideParam.testRatio= 0.1;
- % Before training, the network’s tansig layers can be converted to
- % elliotsig layers.
- for i=1:net.numLayers
- if strcmp(net.layers{i}.transferFcn,'tansig')
- net.layers{i}.transferFcn = 'elliotsig';
- end
- end
- % Convert MATLAB arrays to GPU arrays.
- DataGPU = nndata2gpu(Data);
- TargetsGPU = nndata2gpu(Targets);
- % Train the network object while keeping track of the training,
- validation
- % and testing processes.
- net = train(net,Data,Targets);
- % Compute the estimated targets.
- EstimatedTargets = net(Data);
- % Compute the corresponding error values per training pattern.
- Errors = Targets - EstimatedTargets;
- % Compute the associated mean squared error.
- MeanSquaredError = mse(net,Targets,EstimatedTargets);
- fprintf('Neural network performacne in terms of mse: %f
- \n',MeanSquaredError);
- % Plot the associated error histogram in 30 bins.
- 2
- figure('Name','Error Histogram in 30 bins');
- ploterrhist(Errors,'bins',30);
- % Plot the histogram for actual and estimated targets.
- figure('Name','Estimated vs Actual Targets Histogram');
- hold on
- histogram(Targets,'Normalization','countdensity','BinMethod','scott');
- histogram(EstimatedTargets,'Normalization','countdensity','BinMethod','scott');
- hold off;
- grid on
- % Plot the regression results between the actual and the estimated
- targets.
- plotregression(Targets,EstimatedTargets);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement