Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. {X, Y} = (ExampleData[{"MachineLearning", "MNIST"}, "Data"] /. Rule -> List)[Transpose];
  2.  
  3. θsize = AbsoluteTiming[Dimensions[matrixX =Flatten[Map[ImageData, X], {3, 2}][Transpose]]][[2,2]];
  4. θ= Table[Symbol["θ" <> ToString[i]], {i,θsize}];
  5.  
  6. trainingX = matrixX[[;; 60000]];
  7. trainingY = Y[[;; 60000]];
  8. testX = matrixX[[60001 ;;]];
  9. testY = Y[[60001 ;;]];
  10. Clear[X, Y, matrixX]
  11.  
  12. individualTrainingSets = MovingMap[List[#[[1]] + 1, #[[2]]] &, Prepend[Accumulate[Length /@ Split[trainingY]], 0], 2]
  13.  
  14. (* {{1, 5923}, {5924, 12665}, {12666, 18623}, {18624, 24754}, {24755, 30596}, {30597, 36017}, {36018, 41935}, {41936, 48200}, {48201, 54051}, {54052, 60000}}
  15.  
  16. Yranges = Table[Symbol["trainingY" <> ToString[i]], {i, 0, 9}];
  17. Y = SparseArray[i_ /; #1 <= i <= #2 -> 1, {60000}] & @@@individualTrainingSets;
  18.  
  19. data = Transpose[trainingX[Transpose]~Join~{Y[[1]]}];
  20.  
  21. rlm = LogitModelFit[data,θ,θ]; // AbsoluteTiming
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement