8000 Moved directory. Simple classifier. · Dhee2211/practice-python@060dbc8 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 060dbc8

Browse files
committed
Moved directory. Simple classifier.
1 parent f237ab1 commit 060dbc8

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

machine-learning/fruit-classify.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from sklearn import tree
2+
3+
TEXTURE_BUMPY = 0
4+
TEXTURE_SMOOTH = 1
5+
6+
LABEL_APPLE = 0
7+
LABEL_ORANGE = 1
8+
9+
LABELS = {
10+
LABEL_APPLE: 'apple',
11+
LABEL_ORANGE: 'orange',
12+
}
13+
14+
15+
def classify(to_classify):
16+
features = [
17+
[90, TEXTURE_BUMPY],
18+
[140, TEXTURE_SMOOTH],
19+
[130, TEXTURE_SMOOTH],
20+
[150, TEXTURE_BUMPY],
21+
[170, TEXTURE_BUMPY],
22+
]
23+
labels = [
24+
LABEL_ORANGE,
25+
LABEL_APPLE,
26+
LABEL_APPLE,
27+
LABEL_ORANGE,
28+
LABEL_ORANGE
29+
]
30+
31+
clf = tree.DecisionTreeClassifier()
32+
clf = clf.fit(features, labels)
33+
34+
return clf.predict(to_classify)
35+
36+
37+
def main():
38+
to_classify = [
39+
[145, TEXTURE_BUMPY],
40+
[120, TEXTURE_SMOOTH],
41+
[100, TEXTURE_BUMPY],
42+
]
43+
44+
decisions = classify(to_classify)
45+
46+
for decision in decisions:
47+
print("It's a(n):", LABELS[decision])
48+
49+
50+
if __name__ == '__main__':
51+
main()
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
0