SHARE
TWEET

Untitled

a guest Jun 17th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %
  2.  -------------------------------------------------------------------------
  3. % Credit Risk Assessment Toolbox
  4. %
  5. % Author: D. N. Sotiropoulos (2019)
  6. %
  7.  -------------------------------------------------------------------------
  8. % This script file provides fundamental computational functionality
  9.  for
  10. % training a fitnet type network for the problem of function
  11. % approximation. In fact, we are going to approximate the
  12.  fico_range_low
  13. % and fico_range_high feature values as a function of the remaining
  14. % features. Therefore, the loan status related features will be
  15.  ignored.
  16. % This neural netwrok simulator uses gpu computation assistance.
  17. % Clear command window and workspace.
  18. clc
  19. clear
  20. % Load dataset from file "LendingClub.mat" which creates the table
  21.  type
  22. % variable lending_club_data_table. This table will be loaded into
  23.  table T.
  24. load('LendingClub.mat');
  25. T = lending_club_data_table;
  26. clear lending_club_data_table
  27. % The following table columns will be excluded from the available set
  28.  of
  29. % features upon which training will be conducted: =
  30. % ColumnID = 14 ==> VariableName = 'fico_range_low'
  31. % ColumnID = 15 ==> VariableName = 'fico_range_high'
  32. % ColumnID = 36 ==> VariableName = 'last_fico_range_high'
  33. % ColumnID = 37 ==> VariableName = 'last_fico_range_low'
  34. % ColumnID = 39 ==> VariableName = 'mths_since_last_derog'
  35. % ColumnID = 121 ==> VariableName = 'loan_status1'
  36. % ColumnID = 122 ==> VarialeName = 'loan_status2'
  37. % Set the variable names to be removed from training:
  38. RemoveVariableNames = {'fico_range_low','fico_range_high',...
  39.  
  40.  'last_fico_range_high','last_fico_range_low',...
  41.  
  42.  'mths_since_last_major_derog','loan_status1',...
  43.  'loan_status2'};
  44. % Set the feature data.
  45. Data = removevars(T,RemoveVariableNames);
  46. 1
  47. % Convert the feature data table to array.
  48. Data = table2array(Data)';
  49. % Set the feature labels.
  50. Targets = T.fico_range_low';
  51. % Set the network object.
  52. net = fitnet(10,'trainscg');
  53. % Configure the network object.
  54. net = configure(net,Data,Targets);
  55. % View network.
  56. view(net);
  57. % Initialize the network object.
  58. net = init(net);
  59. % Enable verbal output during training.
  60. net.trainParam.showCommandLine = true;
  61. % Enable visual output during training.
  62. net.trainParam.showWindow = true;
  63. % Devide the data randomly.
  64. net.divideFcn= 'dividerand';
  65. % Use the 70% of the available data for training purposes.
  66. net.divideParam.trainRatio= 0.7;
  67. % Use the 20% of the available data for validations purposes.
  68. net.divideParam.valRatio= 0.2;
  69. % Use the 10% of the available data for testing purposes.
  70. net.divideParam.testRatio= 0.1;
  71. % Before training, the network’s tansig layers can be converted to
  72. % elliotsig layers.
  73. for i=1:net.numLayers
  74.  if strcmp(net.layers{i}.transferFcn,'tansig')
  75.  net.layers{i}.transferFcn = 'elliotsig';
  76.  end
  77. end
  78. % Convert MATLAB arrays to GPU arrays.
  79. DataGPU = nndata2gpu(Data);
  80. TargetsGPU = nndata2gpu(Targets);
  81. % Train the network object while keeping track of the training,
  82.  validation
  83. % and testing processes.
  84. net = train(net,Data,Targets);
  85. % Compute the estimated targets.
  86. EstimatedTargets = net(Data);
  87. % Compute the corresponding error values per training pattern.
  88. Errors = Targets - EstimatedTargets;
  89. % Compute the associated mean squared error.
  90. MeanSquaredError = mse(net,Targets,EstimatedTargets);
  91. fprintf('Neural network performacne in terms of mse: %f
  92. \n',MeanSquaredError);
  93. % Plot the associated error histogram in 30 bins.
  94. 2
  95. figure('Name','Error Histogram in 30 bins');
  96. ploterrhist(Errors,'bins',30);
  97. % Plot the histogram for actual and estimated targets.
  98. figure('Name','Estimated vs Actual Targets Histogram');
  99. hold on
  100. histogram(Targets,'Normalization','countdensity','BinMethod','scott');
  101. histogram(EstimatedTargets,'Normalization','countdensity','BinMethod','scott');
  102. hold off;
  103. grid on
  104. % Plot the regression results between the actual and the estimated
  105.  targets.
  106. plotregression(Targets,EstimatedTargets);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top