hanslovsky

julia mnist random forest

Oct 2nd, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.68 KB | None | 0 0
  1. using HDF5
  2. using DecisionTree
  3.  
  4. fn = "/home/phil/Downloads/mnist-original.h5"
  5. n = 70000
  6. data = float64(h5read( fn, "data/data", (1:n,:) ))
  7. labels = uint64(h5read( fn, "data/label", )[1:n])
  8.  
  9.  
  10. nData = size(data,1)
  11.  
  12. nTraining = 0.7*nData
  13. selection = shuffle!(int(linspace(1,nData,nData)))
  14.  
  15. trainingData   = data[selection[1:nTraining],:]
  16. trainingLabels = labels[selection[1:nTraining]]
  17.  
  18. testData   = data[selection[nTraining+1:end],:]
  19. testLabels = labels[selection[nTraining+1:end]]
  20.  
  21. model = build_forest(trainingLabels, trainingData, 20, 10, 1.0)
  22. pred  = apply_forest(model, testData)
  23.  
  24. accuracy = sum( pred .== testLabels ) / size(testLabels,1)
  25.  
  26. @printf "Accuracy=%f" accuracy
Advertisement
Add Comment
Please, Sign In to add comment