3 maja 2016

{Machine Learning} Recipes

Google Developers na swoim kanale, rozpoczął serię filmów traktujących o nauczaniu maszynowym. Krótka i ciekawa forma, bardzo mi się podoba.



Odrobinę przerobiony przykład "Hello Wrold"
# http://scikit-learn.org/stable/
# https://www.continuum.io/
# sudo apt-get install python-scikits-learn

from sklearn import tree

# Collect training data
SMOOTH = 1
BUMPY = 0
APPLE = 0
ORANGE = 1

features = [[140, SMOOTH], [130, SMOOTH], [150, BUMPY], [170, BUMPY]]
labels = [APPLE, APPLE, ORANGE, ORANGE]

# Train classifier
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)

# Make predictions
result = clf.predict([[160, 0]])

if result[0] == APPLE:
    print 'APPLE'
elif result[0] == ORANGE:
    print 'ORANGE'
else:
    'Result unknown'
Wynik:
ORANGE