1+ .. _plugin_models :
2+
13Models
24======
35
@@ -7,6 +9,11 @@ abstract the usage of machine learning models.
79dffml_model_tensorflow
810----------------------
911
12+ .. code-block :: console
13+
14+ pip install dffml-model-tensorflow
15+
16+
1017 tfdnnc
1118~~~~~~
1219
@@ -15,6 +22,93 @@ tfdnnc
1522Implemented using Tensorflow's DNNClassifier. Models are saved under the
1623``directory `` in subdirectories named after the hash of their feature names.
1724
25+ .. code-block :: console
26+
27+ $ wget http://download.tensorflow.org/data/iris_training.csv
28+ $ wget http://download.tensorflow.org/data/iris_test.csv
29+ $ head iris_training.csv
30+ $ sed -i 's/.*setosa,versicolor,virginica/SepalLength,SepalWidth,PetalLength,PetalWidth,classification/g' *.csv
31+ $ head iris_training.csv
32+ $ dffml train \
33+ -model tfdnnc \
34+ -model-epochs 3000 \
35+ -model-steps 20000 \
36+ -model-classification classification \
37+ -model-classifications 0 1 2 \
38+ -model-clstype int \
39+ -sources iris=csv \
40+ -source-filename iris_training.csv \
41+ -features \
42+ def:SepalLength:float:1 \
43+ def:SepalWidth:float:1 \
44+ def:PetalLength:float:1 \
45+ def:PetalWidth:float:1 \
46+ -log debug
47+ ... lots of output ...
48+ $ dffml accuracy \
49+ -model tfdnnc \
50+ -model-classification classification \
51+ -model-classifications 0 1 2 \
52+ -model-clstype int \
53+ -sources iris=csv \
54+ -source-filename iris_test.csv \
55+ -features \
56+ def:SepalLength:float:1 \
57+ def:SepalWidth:float:1 \
58+ def:PetalLength:float:1 \
59+ def:PetalWidth:float:1 \
60+ -log critical
61+ 0.99996233782
62+ $ dffml predict all \
63+ -model tfdnnc \
64+ -model-classification classification \
65+ -model-classifications 0 1 2 \
66+ -model-clstype int \
67+ -sources iris=csv \
68+ -source-filename iris_test.csv \
69+ -features \
70+ def:SepalLength:float:1 \
71+ def:SepalWidth:float:1 \
72+ def:PetalLength:float:1 \
73+ def:PetalWidth:float:1 \
74+ -caching \
75+ -log critical \
76+ > results.json
77+ $ head -n 33 results.json
78+ [
79+ {
80+ "extra": {},
81+ "features": {
82+ "PetalLength": 4.2,
83+ "PetalWidth": 1.5,
84+ "SepalLength": 5.9,
85+ "SepalWidth": 3.0,
86+ "classification": 1
87+ },
88+ "last_updated": "2019-07-31T02:00:12Z",
89+ "prediction": {
90+ "confidence": 0.9999997615814209,
91+ "value": 1
92+ },
93+ "src_url": "0"
94+ },
95+ {
96+ "extra": {},
97+ "features": {
98+ "PetalLength": 5.4,
99+ "PetalWidth": 2.1,
100+ "SepalLength": 6.9,
101+ "SepalWidth": 3.1,
102+ "classification": 2
103+ },
104+ "last_updated": "2019-07-31T02:00:12Z",
105+ "prediction": {
106+ "confidence": 0.9999984502792358,
107+ "value": 2
108+ },
109+ "src_url": "1"
110+ },
111+
18112 **Args **
19113
20114- directory: String
@@ -48,4 +142,84 @@ Implemented using Tensorflow's DNNClassifier. Models are saved under the
48142- clstype: locate
49143
50144 - default: <class 'str'>
51- - Data type of classifications values (default: str)
145+ - Data type of classifications values (default: str)
146+
147+ dffml_model_scratch
148+ -------------------
149+
150+ .. code-block :: console
151+
152+ pip install dffml-model-scratch
153+
154+
155+ scratchslr
156+ ~~~~~~~~~~
157+
158+ *Core *
159+
160+ Simple Linear Regression Model for 2 variables implemented from scratch.
161+ Models are saved under the ``directory `` in subdirectories named after the
162+ hash of their feature names.
163+
164+ .. code-block :: console
165+
166+ $ cat > dataset.csv << EOF
167+ Years,Salary
168+ 1,40
169+ 2,50
170+ 3,60
171+ 4,70
172+ 5,80
173+ EOF
174+ $ dffml train \
175+ -model scratchslr \
176+ -features def:Years:int:1 \
177+ -model-predict Salary \
178+ -sources f=csv \
179+ -source-filename dataset.csv \
180+ -source-readonly \
181+ -log debug
182+ $ dffml accuracy \
183+ -model scratchslr \
184+ -features def:Years:int:1 \
185+ -model-predict Salary \
186+ -sources f=csv \
187+ -source-filename dataset.csv \
188+ -source-readonly \
189+ -log debug
190+ 1.0
191+ $ echo -e 'Years,Salary\n6,0\n' | \
192+ dffml predict all \
193+ -model scratchslr \
194+ -features def:Years:int:1 \
195+ -model-predict Salary \
196+ -sources f=csv \
197+ -source-filename /dev/stdin \
198+ -source-readonly \
199+ -log debug
200+ [
201+ {
202+ "extra": {},
203+ "features": {
204+ "Salary": 0,
205+ "Years": 6
206+ },
207+ "last_updated": "2019-07-19T09:46:45Z",
208+ "prediction": {
209+ "confidence": 1.0,
210+ "value": 90.0
211+ },
212+ "src_url": "0"
213+ }
214+ ]
215+
216+ **Args **
217+
218+ - directory: String
219+
220+ - default: /home/user/.cache/dffml/scratch
221+ - Directory where state should be saved
222+
223+ - predict: String
224+
225+ - Label or the value to be predicted
0 commit comments