Last active
June 30, 2017 03:28
-
-
Save gnilchee/dd677665278712c6e856550d97c582ce to your computer and use it in GitHub Desktop.
Easy hello world machine learning example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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