Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Last active June 30, 2017 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnilchee/dd677665278712c6e856550d97c582ce to your computer and use it in GitHub Desktop.
Save gnilchee/dd677665278712c6e856550d97c582ce to your computer and use it in GitHub Desktop.
Easy hello world machine learning example
#!/usr/bin/env python3
from sklearn import tree
###################
## Texture
# smooth = 1
# bumpy = 0
## label
# apple = 0
# orange = 1
##################
## Training Data
# texture
features = [[140, 1], [130, 1], [150, 0], [170, 0]]
# fruit
labels = [0, 0, 1, 1]
# setup sklearn decision tree and feed training data
clf = tree.DecisionTreeClassifier()
ml = clf.fit(features, labels)
## Test
# 160 grams and bumpy
result = ml.predict([[160, 0]])
## Show result
print("160g and bumpy is (0=apple, 1=orange):", result)
apt-get install python3-numpy python3-scipy python3-sklearn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment