Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #The goal is to clssify anyone as 'male' or 'female' given just their 'height', 'weight' and 'shoe size'
  2. #we use scikit-learn package to train a decision tree with already existing data set to make it able to predict on it's own
  3.  
  4. from sklearn import tree
  5.  
  6. # data set x [height, weight, shoe size]
  7.  
  8. X = [[181, 80, 44], [177, 70, 43], [160, 60, 38], [154, 54, 37], [166, 65, 40], [190, 90, 47], [175, 64, 39], [177, 70, 40], [159, 55, 37], [171, 75, 42], [181, 85, 43]]
  9.  
  10. #data set Y [Gender labels]
  11. Y = ['male', 'female', 'female', 'female', 'male', 'male', 'male', 'female', 'male', 'female', 'male']
  12.  
  13. #storing classifier in variable clf calling the Decision Tree Classifier from tree submodule of sklearn
  14. clf = tree.DecisionTreeClassifier()
  15.  
  16. #training the classifier with our data set x and y
  17. clf = clf.fit(X, Y)
  18.  
  19. #testing prediction
  20. prediction = clf.predict([[250, 70, 45]])
  21.  
  22. print (prediction)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement