February 2018
Intermediate to advanced
378 pages
10h 14m
English
We use the predict function to get outcome labels for two samples. The first one is light-black, fluffy creature, 24 meters long. The second one is purple polka dot, non-fluffy, and 34 meters long. If you already don't remember the meaning of each feature, consult the feature_names variable:
In []: samples = [[24,1,0,1,0,0], [34,0,0,0,1,0]] tree_model.predict(samples) Out[]: array([u'platyhog', u'rabbosaurus'], dtype=object)
Our model predicted platyhog for the first sample, and rabbosaurus for the second one. A decision tree can also provide probabilistic output (how sure it is about the prediction):
In []:
tree_model.predict_proba(samples)
Out[]:
array([[ 1., 0.],
[ 0., 1.]])
The array contains two nested arrays, one ...
Read now
Unlock full access