@@ -39,6 +39,8 @@ If you're planing on importing any third party packages, anything on
3939`PyPi <https://pypi.org >`_, you'll want to add it to the ``setup.py `` file
4040first.
4141
42+ **setup.py **
43+
4244.. code-block :: python
4345
4446 common.KWARGS [" install_requires" ] += [" scikit-learn>=0.21.2" ]
@@ -75,11 +77,15 @@ We're going to need a few modules from the standard library, let's import them.
7577- ``typing `` is for Python's static type hinting. It lets use give hints to our
7678 editor or IDE so they can help us check our code before we run it.
7779
80+ **dffml_model_myslr/misc.py **
81+
7882.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
7983 :lines: 1-3
8084
8185We'll also need a few things from DFFML.
8286
87+ **dffml_model_myslr/misc.py **
88+
8389.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
8490 :lines: 5-16
8591
@@ -100,6 +106,8 @@ Config
100106Anything that a user might want to tweak about a models behavior should go in
101107the ``Config `` class for the model.
102108
109+ **dffml_model_myslr/misc.py **
110+
103111.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
104112 :lines: 54-61
105113
@@ -129,12 +137,16 @@ model from the DFFML command line and other interfaces.
129137
130138- We must set the ``CONFIG `` attribute to the respective ``Config `` class.
131139
140+ **dffml_model_myslr/misc.py **
141+
132142.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
133143 :lines: 64-67
134144
135145- We must make sure ``setup.py ``'s ``"entry_points" `` field correctly references
136146 the location of our model.
137147
148+ **setup.py **
149+
138150.. literalinclude :: /../dffml/skel/model/setup.py
139151 :lines: 12-14
140152
@@ -156,6 +168,8 @@ Models should save their state to disk after training. Classes derived from
156168``SimpleModel `` can put anything they want saved into ``self.storage ``, which
157169is saved and loaded from a JSON on disk.
158170
171+ **dffml_model_myslr/misc.py **
172+
159173.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
160174 :lines: 76-91
161175
@@ -165,6 +179,8 @@ Accuracy
165179We saved the accuracy as the 2nd index into the ``"regression_line" `` key in the
166180``self.storage `` dictionary. When we assess the accuracy we reload from there.
167181
182+ **dffml_model_myslr/misc.py **
183+
168184.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
169185 :lines: 93-101
170186
@@ -179,6 +195,8 @@ We call :py:meth:`record.predicted <dffml.record.Record.predicted>`
179195passing it the name of the feature we predicted, the predicted value, and the
180196confidence in our prediction.
181197
198+ **dffml_model_myslr/misc.py **
199+
182200.. literalinclude :: /../dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py
183201 :lines: 103-122
184202
@@ -193,7 +211,10 @@ Rename the imports
193211We need to make sure our model is imported via it's new name, ``MySRL `` instead
194212of ``Misc ``.
195213
214+ **tests/test_model.py **
215+
196216.. code-block :: python
217+
197218 from dffml_model_myslr.misc import MySLRModel, MySLRModelConfig
198219
199220 Test data
@@ -202,6 +223,8 @@ Test data
202223We usually try to randomly generate training and test data, but for this example
203224we're just going to hard code in some data.
204225
226+ **tests/test_model.py **
227+
205228.. literalinclude :: /../dffml/skel/model/tests/test_model.py
206229 :lines: 7-34
207230
@@ -211,26 +234,50 @@ Rename the test class
211234Change the test class's name, and make sure ``cls.model `` is instantiating a
212235``MySLR `` model instead of the ``Misc `` model.
213236
214- We create a temporary directory for our tests to use
237+ We create a temporary directory for our tests to use, and clean it up when
238+ they're done. The tests are prefixed with numbers to indicate what order they
239+ should be run in, ensuring that accuracy and predict test always have a trained
240+ model to work with.
241+
242+ **tests/test_model.py **
215243
216244.. literalinclude :: /../dffml/skel/model/tests/test_model.py
217245 :lines: 37-60
218246
219247Testing Train
220248~~~~~~~~~~~~~
221249
250+ Similarly to the quickstart, all we need to to is pass the model and training
251+ data to the :py:func: `train <dffml.train> ` function.
252+
253+ **tests/test_model.py **
254+
222255.. literalinclude :: /../dffml/skel/model/tests/test_model.py
223256 :lines: 62-64
224257
225258Testing Accuracy
226259~~~~~~~~~~~~~~~~
227260
261+ Once again, all we need to to is pass the model and test data to the
262+ :py:func: `accuracy <dffml.accuracy> ` function. Then we check if it's in an
263+ acceptable range. This test is helpful to make sure you never make any horribly
264+ wrong changes to your model, since it will check that the accuracy is within an
265+ acceptable range.
266+
267+ **tests/test_model.py **
268+
228269.. literalinclude :: /../dffml/skel/model/tests/test_model.py
229270 :lines: 66-70
230271
231272Testing Prediction
232273~~~~~~~~~~~~~~~~~~
233274
275+ Finally, we use the test data and model with the
276+ :py:func: `predict <dffml.predict> ` function. Then we check if each predicted Y
277+ value is within 10% of what it should be.
278+
279+ **tests/test_model.py **
280+
234281.. literalinclude :: /../dffml/skel/model/tests/test_model.py
235282 :lines: 72-83
236283
0 commit comments