Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 7608dbb

Browse files
committed
docs: tutorial: model: Mention file paths of files we're editing
Fixes: #464 Signed-off-by: John Andersen <[email protected]>
1 parent a6efd7c commit 7608dbb

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- New model tutorial mentions file paths that should be edited.
810

911
## [0.3.5] - 2020-03-10
1012
### Added

dffml/skel/model/REPLACE_IMPORT_PACKAGE_NAME/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class MiscModelConfig:
5757
features: Features = field("Features to train on. For SLR only 1 allowed")
5858
directory: pathlib.Path = field(
5959
"Directory where state should be saved",
60-
default=pathlib.Path("~", ".cache", "dffml", "miscmodel"),
60+
default=pathlib.Path("~", ".cache", "dffml", "misc"),
6161
)
6262

6363

64-
@entrypoint("miscmodel")
64+
@entrypoint("misc")
6565
class MiscModel(SimpleModel):
6666
# The configuration class needs to be set as the CONFIG property
6767
CONFIG: Type[MiscModelConfig] = MiscModelConfig

docs/tutorials/model.rst

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
4040
first.
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

8185
We'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
100106
Anything that a user might want to tweak about a models behavior should go in
101107
the ``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
157169
is 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
165179
We 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>`
179195
passing it the name of the feature we predicted, the predicted value, and the
180196
confidence 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
193211
We need to make sure our model is imported via it's new name, ``MySRL`` instead
194212
of ``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
202223
We usually try to randomly generate training and test data, but for this example
203224
we'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
211234
Change 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

219247
Testing 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

225258
Testing 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

231272
Testing 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

Comments
 (0)