Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

Sign up
Appearance settings

Commit060dbc8

Browse files
committed
Moved directory. Simple classifier.
1 parentf237ab1 commit060dbc8

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+
fromsklearnimporttree
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+
defclassify(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+
returnclf.predict(to_classify)
35+
36+
37+
defmain():
38+
to_classify= [
39+
[145,TEXTURE_BUMPY],
40+
[120,TEXTURE_SMOOTH],
41+
[100,TEXTURE_BUMPY],
42+
]
43+
44+
decisions=classify(to_classify)
45+
46+
fordecisionindecisions:
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)

[8]ページ先頭

©2009-2025 Movatter.jp