Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (36 sloc) 1.28 KB
metadata:
title: Predictive analytics
documentation: "https://docassemble.org/docs/ml.html#RandomForestMachineLearner"
example start: 2
example end: 4
---
modules:
- docassemble.base.util
---
mandatory: True
code: |
rf = RandomForestMachineLearner('fruit', use_initial_file=True)
if rf.is_empty():
rf.add_to_training_set(dict(a=1, b=2.0, c=3.0, d='A'), 'apple')
rf.add_to_training_set(dict(a=0.9, b=2, c=3.0, d='A'), 'apple')
rf.add_to_training_set(dict(a=0.8, b=2.0, c=3.0, d='A'), 'apple')
rf.add_to_training_set(dict(a=1.0, b=2.1, c=3, d='B'), 'apple')
rf.add_to_training_set(dict(a=1.2, b=2.0, c=3.1, d='A'), 'apple')
rf.add_to_training_set(dict(a=1.0, b=7.0, c=3.0, d='B'), 'orange')
rf.add_to_training_set(dict(a=0.9, b=6.9, c=3.0, d='A'), 'orange')
rf.add_to_training_set(dict(a=0.8, b=6.7, c=2.9, d='B'), 'orange')
rf.add_to_training_set(dict(a=1.0, b=7.1, c=2.95, d='B'), 'orange')
rf.add_to_training_set(dict(a=1.05, b=6.8, c=3.1, d='B'), 'orange')
---
code: |
sample_data = dict(a=1, b=3.8, c=3.1, d='B')
predictions = rf.predict(sample_data, probabilities=True)
---
mandatory: True
question: |
The prediction
subquestion: |
With
${ '{0:.1f}%'.format(predictions[0][1]*100) }
certainty, I think it is an
${ predictions[0][0] }.