Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. SeedRandom[0];
  2. n = 10000;
  3. X = RandomReal[{-1, 1}, {n, 100, 5}];
  4. Y = RandomInteger[{0, 1}, n];
  5.  
  6. SeedRandom[0];
  7. netT = NetTrain[
  8. net,
  9. X -> Y,
  10. All,
  11. LossFunction -> CrossEntropyLossLayer["Index"],
  12. BatchSize -> 64, MaxTrainingRounds -> 10, TargetDevice -> "GPU"
  13. ]
  14.  
  15. SeedRandom[0];
  16. netT = NetTrain[
  17. net,
  18. X -> Y,
  19. All,
  20. LossFunction -> CrossEntropyLossLayer["Index"],
  21. BatchSize -> 64, MaxTrainingRounds -> 10, TargetDevice -> "GPU"
  22. ]
  23.  
  24. cm = ClassifierMeasurements[netT["TrainedNet"], X -> Y]
  25.  
  26. cm["ConfusionMatrixPlot"]
  27.  
  28. cm["Precision"]
  29.  
  30. cm["Recall"]
  31.  
  32. proba = netT["TrainedNet"][X, "Probabilities"];
  33. proba0 = Lookup[proba, 0];
  34. proba1 = Lookup[proba, 1];
  35.  
  36. Table[
  37. {
  38. Select[Pick[proba0, Y, 0], # >= i &] // Length,
  39. Select[Pick[proba0, Y, 1], # >= i &] // Length
  40. } // {i, ##, N[#[[1]]/(#[[1]] + #[[2]])]} &,
  41. {i, 0.5, 0.7, 0.01}
  42. ] // MatrixForm
  43.  
  44. Table[
  45. {
  46. Select[Pick[proba0, Y, 0], # >= i &] // Length,
  47. Select[Pick[proba0, Y, 1], # >= i &] // Length
  48. } // {i, ##, N[#[[1]]/(#[[1]] + #[[2]])]} &,
  49. {i, 0.5, 0.7, 0.01}
  50. ] // MatrixForm
  51.  
  52. PairedHistogram[Pick[proba1, Y, 1], Pick[proba1, Y, 0]]
  53.  
  54. Table[
  55. {
  56. Select[Pick[proba1, Y, 1], # >= i &] // Length,
  57. Select[Pick[proba1, Y, 0], # >= i &] // Length
  58. } // {i, ##, N[#[[1]]/(#[[1]] + #[[2]])]} &,
  59. {i, 0.5, 0.7, 0.01}
  60. ] // MatrixForm
  61.  
  62. EV[p_] := p*80 - (1 - p)*100 - 4
  63.  
  64. Plot[
  65. {
  66. Select[Pick[proba1, Y, 1], # >= x &] // Length,
  67. Select[Pick[proba1, Y, 0], # >= x &] // Length
  68. } // EV[#[[1]]/(#[[1]] + #[[2]])]*(#[[1]] + #[[2]]) &,
  69. {x, 0.5, 0.7}
  70. ]
  71.  
  72. Plot[
  73. {
  74. Select[Pick[proba1, Y, 1], # >= x &] // Length,
  75. Select[Pick[proba1, Y, 0], # >= x &] // Length
  76. } // EV[#[[1]]/(#[[1]] + #[[2]])]*(#[[1]] + #[[2]]) &,
  77. {x, 0.5, 0.7}
  78. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement