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

ML in Ruby

ML in Ruby

Recording (in Polish): https://youtu.be/zSfXh-Qul1s
TRUG#59 - Short intro to Machine Learning in Ruby

Michał Poczwardowski

February 15, 2017
Tweet

More Decks by Michał Poczwardowski

Other Decks in Programming

Transcript

  1. f Machine learning - field of study that gives computers

    the ability to learn without being explicitly programmed. Arthur Samuel, 1959
  2. • Decision Tree - ID3 • Jaccard Index • K-means

    clustering • Naive Bayes • Artificial Neural Networks • + more more more
  3. ? • lack of stuff • speed (historical) • old

    gems / not so many resources • ML and AI experts mosty use Java and Python, Ruby hasn't got much love - most of them come from Universities and more scientific studies - Ruby is just not used in such environments
  4. #1 1: require 'decisiontree' 2: 3: attributes = ['Temperature'] 4:

    training = [ 5: [36.6, 'healthy'], 6: [37, 'sick'], 7: [38, 'sick'], 8: [36.7, 'healthy'], 9: [40, 'sick'], 10: [50, 'really sick'], 11: ]
  5. #2 12: dec_tree = DecisionTree::ID3Tree.new(attributes, training, 'sick', :continuous) 13: dec_tree.train

    14: 15: test = [37.5, 'sick'] 16: decision = dec_tree.predict(test) 17: puts "Predicted: #{decision} ... True decision: #{test.last}" # => Predicted: sick ... True decision: sick
  6. 1: a = ["likes:jeans", "likes:blue"] 2: b = ["likes:jeans", "likes:women",

    "likes:red"] 3: c = ["likes:women", "likes:red"] 4: 5: # Determines how similar a pair of sets are 6: Jaccard.coefficient(a, b) 7: #=> 0.25 8: 9: Jaccard.coefficient(a, c) 10: #=> 0.0 11: 12: Jaccard.coefficient(b, c) 13: #=> 0.6666666666666666 14: 15: # According to the input data, b and c have the most similar likes.
  7. -

  8. - 1: require 'k_means' 2: 3: data = [[1,1], [1,2],

    [1,1], [1000, 1000], [500, 500]] 4: kmeans = KMeans.new(data, centroids: 2) 5: kmeans.inspect 6: => [[3, 4], [0, 1, 2]]