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

Commit

Permalink
model: scikit: Simple Linear Regression
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
yashlamba authored and pdxjohnny committed Jul 31, 2019
1 parent 85763d6 commit 5384eb2
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
- PLUGIN=.
- PLUGIN=model/tensorflow
- PLUGIN=model/scratch
- PLUGIN=model/scikit
- PLUGIN=feature/git
- PLUGIN=feature/auth
- CHANGELOG=1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`argparse.ArgumentParser` via the `CLI_FORMATTER_CLASS` property.
- Skeleton for service creation was added
- Simple Linear Regression model from scratch
- Scikit Linear Regression model
- Community link in CONTRIBUTING.md.
- Explained three main parts of DFFML on docs homepage
- Documentation on how to use ML models on docs Models plugin page.
Expand Down
84 changes: 84 additions & 0 deletions docs/plugins/dffml_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,90 @@ hash of their feature names.
- default: /home/user/.cache/dffml/scratch
- Directory where state should be saved

- predict: String

- Label or the value to be predicted

dffml_model_scikit
------------------

.. code-block:: console
pip install dffml-model-scikit
scikitlr
~~~~~~~~

*Core*

Linear Regression Model implemented using scikit. Models are saved under the
``directory`` in subdirectories named after the hash of their feature names.

.. code-block:: console
$ cat > train.csv << EOF
Years,Expertise,Trust,Salary
0,1,0.2,10
1,3,0.4,20
2,5,0.6,30
3,7,0.8,40
EOF
$ cat > test.csv << EOF
Years,Expertise,Trust,Salary
4,9,1.0,50
5,11,1.2,60
EOF
$ dffml train \
-model scikitlr \
-features def:Years:int:1 def:Expertise:int:1 def:Trust:float:1 \
-model-predict Salary \
-sources f=csv \
-source-filename train.csv \
-source-readonly \
-log debug
$ dffml accuracy \
-model scikitlr \
-features def:Years:int:1 def:Expertise:int:1 def:Trust:float:1 \
-model-predict Salary \
-sources f=csv \
-source-filename test.csv \
-source-readonly \
-log debug
1.0
$ echo -e 'Years,Expertise,Trust\n6,13,1.4\n' | \
dffml predict all \
-model scikitlr \
-features def:Years:int:1 def:Expertise:int:1 def:Trust:float:1 \
-model-predict Salary \
-sources f=csv \
-source-filename /dev/stdin \
-source-readonly \
-log debug
[
{
"extra": {},
"features": {
"Expertise": 13,
"Trust": 1.4,
"Years": 6
},
"last_updated": "2019-07-31T08:40:59Z",
"prediction": {
"confidence": 1.0,
"value": 70.0
},
"src_url": "0"
}
]
**Args**

- directory: String

- default: /home/user/.cache/dffml/scikit
- Directory where state should be saved

- predict: String

- Label or the value to be predicted
13 changes: 13 additions & 0 deletions model/scikit/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[run]
source =
dffml_model_scikit
tests
branch = True

[report]
exclude_lines =
no cov
no qa
noqa
pragma: no cover
if __name__ == .__main__.:
20 changes: 20 additions & 0 deletions model/scikit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*.log
*.pyc
.cache/
.coverage
.idea/
.vscode/
*.egg-info/
build/
dist/
docs/build/
venv/
wheelhouse/
*.egss
.mypy_cache/
*.swp
.venv/
.eggs/
*.modeldir
*.db
htmlcov/
21 changes: 21 additions & 0 deletions model/scikit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) 2019 Intel

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions model/scikit/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include LICENSE
71 changes: 71 additions & 0 deletions model/scikit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# DFFML Models For scikit / sklearn

## About

Models created using scikit.

## Install

```console
python3.7 -m pip install --user dffml-model-scikit
```

## Usage

1. Linear Regression Model

For implementing linear regression to a dataset, let us take a simple example:

| Years of Experience | Expertise | Trust Factor | Salary |
| -------------------- | ---------- | ------------ | ------ |
| 0 | 01 | 0.2 | 10 |
| 1 | 03 | 0.4 | 20 |
| 2 | 05 | 0.6 | 30 |
| 3 | 07 | 0.8 | 40 |
| 4 | 09 | 1.0 | 50 |
| 5 | 11 | 1.2 | 60 |

```console
$ cat > train.csv << EOF
Years,Expertise,Trust,Salary
0,1,0.2,10
1,3,0.4,20
2,5,0.6,30
3,7,0.8,40
EOF
$ cat > test.csv << EOF
Years,Expertise,Trust,Salary
4,9,1.0,50
5,11,1.2,60
EOF
$ dffml train \
-model scikitlr \
-features def:Years:int:1 def:Expertise:int:1 def:Trust:float:1 \
-model-predict Salary \
-sources f=csv \
-source-filename train.csv \
-source-readonly \
-log debug
$ dffml accuracy \
-model scikitlr \
-features def:Years:int:1 def:Expertise:int:1 def:Trust:float:1 \
-model-predict Salary \
-sources f=csv \
-source-filename test.csv \
-source-readonly \
-log debug
$ echo -e 'Years,Expertise,Trust\n6,13,1.4\n' | \
dffml predict all \
-model scikitlr \
-features def:Years:int:1 def:Expertise:int:1 def:Trust:float:1 \
-model-predict Salary \
-sources f=csv \
-source-filename /dev/stdin \
-source-readonly \
-log debug
```

## License

Scikit Models are distributed under the terms of the
[MIT License](LICENSE).
Empty file.
Loading

0 comments on commit 5384eb2

Please sign in to comment.