Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Domo Arigato, Mr. Roboto: Machine Learning with Ruby

Eric Weinstein
November 10, 2016

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

    View full-size slide

  2. Part 0: Hello!

    View full-size slide

  3. About Me
    eric_weinstein = {
    employer: 'Hulu',
    github: 'ericqweinstein',
    twitter: 'ericqweinstein',
    website: 'ericweinste.in'
    }
    30% off with RUBYCONF30!

    View full-size slide

  4. Agenda
    • What is machine learning?
    • What is supervised learning?
    • What’s a neural network?
    • Machine learning with Ruby and the MNIST
    dataset

    View full-size slide

  5. Part 1: Machine Learning

    View full-size slide

  6. What’s machine learning?

    View full-size slide

  7. Generalization

    View full-size slide

  8. What’s Supervised Learning?
    Classification or regression, generalizing from
    labeled data to unlabeled data

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  11. Image credit: https://www.tensorflow.org/versions/r0.9/tutorials/mnist/
    beginners/index.html

    View full-size slide

  12. What’s a neural network?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. Part 2: The MNIST Dataset

    View full-size slide

  16. Our Data
    • Images of handwritten digits, size-normalized
    and centered
    • Training: 60,000 examples, test: 10,000
    • http://yann.lecun.com/exdb/mnist/

    View full-size slide

  17. Image credit: https://www.researchgate.net/

    View full-size slide

  18. How’d We Do?
    • Correct: 9328 / 10_000
    • Incorrect: 672 / 10_000
    • Overall: 93.28% accuracy

    View full-size slide

  19. Developing the App

    View full-size slide

  20. 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
    });
    });
    }

    View full-size slide

  21. Front End
    render() {
    return(








    );
    }

    View full-size slide

  22. 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)

    View full-size slide

  23. STOP
    #demotime

    View full-size slide

  24. Summary
    • Machine learning is generalization
    • Supervised learning is labeled data ->
    unlabeled data
    • Neural networks are awesome
    • You can do all this with Ruby!

    View full-size slide

  25. 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

    View full-size slide

  26. Questions?
    eric_weinstein = {
    employer: 'Hulu',
    github: 'ericqweinstein',
    twitter: 'ericqweinstein',
    website: 'ericweinste.in'
    }
    30% off with RUBYCONF30!

    View full-size slide