Sklearn Decision Tree Classifier - игра в угадывание животных - PullRequest
2 голосов
/ 21 июня 2020

Я пытаюсь создать игру «Угадай животных» с классификатором дерева решений sklearn. В нем, при вводе пользователя, он скажет, является ли животное пауком или фантастикой sh. Когда я ввожу количество ног и их положение, появляется сообщение, что животное - это fi sh, и наоборот. Это код, есть идеи?

from sklearn.tree import DecisionTreeClassifier

clf = DecisionTreeClassifier()
features=[[6,0],
      [6,0],                #0 is spider and 1 is fish
      [0,1],                #6 = 4 legs and 8=stays in land ( this is a spider)
      [0,1]]               #4=no legs and 7 is stays in water (this is a fish)
     

outcomes=[1,1,0,0]

clf.fit(features, outcomes)

legs=int(input("Enter the number of legs your animal has: "))
land_water=input("Enter whether you animal stays in land or water: ")
if land_water=="land":
   land_water=0
else:
   land_water=1

sa=clf.predict([[legs, land_water]])

if sa==[0]:
    print("Animal is a spider")
else:
    print('Animal is a fish')

1 Ответ

1 голос
/ 21 июня 2020

Вы перевернули outcomes, как это работает для меня:

from sklearn.tree import DecisionTreeClassifier

clf = DecisionTreeClassifier()
features=[[6,0],
      [6,0],                #0 is spider and 1 is fish
      [0,1],                #6 = 4 legs and 8=stays in land ( this is a spider)
      [0,1]]               #4=no legs and 7 is stays in water (this is a fish)
     

outcomes=["spider","spider","fish","fish"]

clf.fit(features, outcomes)

legs=int(input("Enter the number of legs your animal has: "))
land_water=input("Enter whether you animal stays in land or water: ")
if land_water=="land":
   land_water=0
else:
   land_water=1

sa=clf.predict([[legs, land_water]])
print(sa)
if sa[0] == "spider":
    print("Animal is a spider")
else:
    print('Animal is a fish')
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...