$30 off During Our Annual Pro Sale. View Details »

Domo Arigato, Mr. Roboto: Machine Learning with Ruby

Domo Arigato, Mr. Roboto: Machine Learning with Ruby

Slides for my RubyConf 2016 talk on machine learning.

Eric Weinstein

November 10, 2016
Tweet

More Decks by Eric Weinstein

Other Decks in Technology

Transcript

  1. Dōmo arigatō, Mr. Roboto: Machine Learning with Ruby # Eric

    Weinstein # RubyConf 2016 # Cincinnati, Ohio # 10 November 2016
  2. for Joshua

  3. Part 0: Hello!

  4. About Me eric_weinstein = { employer: 'Hulu', github: 'ericqweinstein', twitter:

    'ericqweinstein', website: 'ericweinste.in' } 30% off with RUBYCONF30!
  5. Agenda • What is machine learning? • What is supervised

    learning? • What’s a neural network? • Machine learning with Ruby and the MNIST dataset
  6. Part 1: Machine Learning

  7. None
  8. What’s machine learning?

  9. In a word:

  10. Generalization

  11. What’s Supervised Learning? Classification or regression, generalizing from labeled data

    to unlabeled data
  12. Features && Labels • Raw pixel features (vectors of intensities)

    • Digit (0..9)
  13. Features && Labels • Raw pixel features (vectors of intensities)

    • Digit (0..9)
  14. Image credit: https://www.tensorflow.org/versions/r0.9/tutorials/mnist/ beginners/index.html

  15. What’s a neural network?

  16. Image credit: https://github.com/cdipaolo/goml/tree/master/perceptron

  17. Image credit: https://en.wikipedia.org/wiki/Artificial_neural_network

  18. Part 2: The MNIST Dataset

  19. Our Data • Images of handwritten digits, size-normalized and centered

    • Training: 60,000 examples, test: 10,000 • http://yann.lecun.com/exdb/mnist/
  20. Image credit: https://www.researchgate.net/

  21. How’d We Do? • Correct: 9328 / 10_000 • Incorrect:

    672 / 10_000 • Overall: 93.28% accuracy
  22. Developing the App

  23. Front End submit() { fetch('/submit', { method: 'POST', body: this.state.canvas.toDataURL('image/png')

    }).then(response => { return response.json(); }).then(j => { this.setState({ prediction: j.prediction }); }); }
  24. Front End render() { return( <div> <EditableCanvas canvas={this.state.canvas} ctx={this.state.ctx} ref='editableCanvas'

    /> <Prediction number={this.state.prediction} /> <div> <Button onClick={this.submit} value='Submit' /> <Button onClick={this.clear} value='Clear' /> </div> </div> ); }
  25. Back End train = RubyFann::TrainData.new(inputs: features, desired_outputs: labels) fann =

    RubyFann::Standard.new(num_inputs: 576, hidden_neurons: [300], num_outputs: 10) fann.train_on_data(train, 1000, 10, 0.01)
  26. STOP #demotime

  27. Summary • Machine learning is generalization • Supervised learning is

    labeled data -> unlabeled data • Neural networks are awesome • You can do all this with Ruby!
  28. Takeaways (TL;DPA) • We can do machine learning with Ruby

    • Contribute to tools like Ruby FANN (github.com/tangledpath/ruby-fann) and sciruby (http://sciruby.com/) • Check it out: http://ruby-mnist.herokuapp.com/ • PRs welcome! github.com/ericqweinstein/ruby- mnist
  29. Thank You!

  30. Questions? eric_weinstein = { employer: 'Hulu', github: 'ericqweinstein', twitter: 'ericqweinstein',

    website: 'ericweinste.in' } 30% off with RUBYCONF30!