-
Notifications
You must be signed in to change notification settings - Fork 252
/
random-forest.yml
33 lines (33 loc) · 1.32 KB
/
random-forest.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
metadata:
title: Predictive analytics
documentation: "https://docassemble.org/docs/ml.html#RandomForestMachineLearner"
example start: 1
example end: 2
---
mandatory: True
code: |
rf = RandomForestMachineLearner('fruit', use_initial_file=True)
if rf.is_empty():
rf.add_to_training_set({'a': 1, 'b': 2.0, 'c': 3.0, 'd': 'A'}, 'apple')
rf.add_to_training_set({'a': 0.9, 'b': 2, 'c': 3.0, 'd': 'A'}, 'apple')
rf.add_to_training_set({'a': 0.8, 'b': 2.0, 'c': 3.0, 'd': 'A'}, 'apple')
rf.add_to_training_set({'a': 1.0, 'b': 2.1, 'c': 3, 'd': 'B'}, 'apple')
rf.add_to_training_set({'a': 1.2, 'b': 2.0, 'c': 3.1, 'd': 'A'}, 'apple')
rf.add_to_training_set({'a': 1.0, 'b': 7.0, 'c': 3.0, 'd': 'B'}, 'orange')
rf.add_to_training_set({'a': 0.9, 'b': 6.9, 'c': 3.0, 'd': 'A'}, 'orange')
rf.add_to_training_set({'a': 0.8, 'b': 6.7, 'c': 2.9, 'd': 'B'}, 'orange')
rf.add_to_training_set({'a': 1.0, 'b': 7.1, 'c': 2.95, 'd': 'B'}, 'orange')
rf.add_to_training_set({'a': 1.05, 'b': 6.8, 'c': 3.1, 'd': 'B'}, 'orange')
---
code: |
sample_data = {'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] }.