Skip to content

Commit

Permalink
Update tutorial
Browse files Browse the repository at this point in the history
(cherry picked from commit 8d744ed)
  • Loading branch information
ospillinger authored and deliahu committed Jan 22, 2020
1 parent ded1605 commit 62702df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions examples/sklearn/iris-classifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This example shows how to deploy a classifier trained on the famous [iris data s
1. Create a Python file `trainer.py`.
2. Use scikit-learn's `LogisticRegression` to train your model.
3. Add code to pickle your model (you can use other serialization libraries such as joblib).
4. Upload it to S3 (boto3 will need access to valid AWS credentials).
4. Replace the bucket name "cortex-examples" with your bucket and upload it to S3 (boto3 will need access to valid AWS credentials).

```python
import boto3
Expand All @@ -35,7 +35,7 @@ print("accuracy: {:.2f}".format(accuracy))

pickle.dump(model, open("model.pkl", "wb"))
s3 = boto3.client("s3")
s3.upload_file("model.pkl", "my-bucket", "sklearn/iris-classifier/model.pkl")
s3.upload_file("model.pkl", "cortex-examples", "sklearn/iris-classifier/model.pkl")
```

Run the script locally:
Expand Down Expand Up @@ -101,7 +101,7 @@ You can skip dependencies that are [pre-installed](../../../docs/deployments/pyt

## Configure your API

Create a `cortex.yaml` file and add the configuration below. An `api` provides a runtime for inference and makes your `predictor.py` implementation available as a web service that can serve real-time predictions:
Create a `cortex.yaml` file and add the configuration below and replace `cortex-examples` with your S3 bucket. An `api` provides a runtime for inference and makes your `predictor.py` implementation available as a web service that can serve real-time predictions:

```yaml
# cortex.yaml
Expand Down Expand Up @@ -133,7 +133,7 @@ Track the status of your api using `cortex get`:
$ cortex get iris-classifier --watch
status up-to-date requested last update avg inference 2XX
live 1 1 8s - -
live 1 1 1m - -
endpoint: http://***.amazonaws.com/iris-classifier
```
Expand Down Expand Up @@ -194,7 +194,7 @@ After making more predictions, your `cortex get` command will show information a
$ cortex get iris-classifier --watch
status up-to-date requested last update avg inference 2XX
live 1 1 10m 28ms 14
live 1 1 1m 1.1 ms 14
class count
setosa 8
Expand All @@ -209,6 +209,8 @@ virginica 4
This model is fairly small but larger models may require more compute resources. You can configure this in your `cortex.yaml`:

```yaml
# cortex.yaml
- name: iris-classifier
predictor:
type: python
Expand Down Expand Up @@ -237,7 +239,7 @@ Run `cortex get` again:
$ cortex get iris-classifier --watch
status up-to-date requested last update avg inference 2XX
live 1 1 10m 24ms 14
live 1 1 1m 1.1 ms 14
class count
setosa 8
Expand All @@ -252,6 +254,8 @@ virginica 4
If you trained another model and want to A/B test it with your previous model, simply add another `api` to your configuration and specify the new model:

```yaml
# cortex.yaml
- name: iris-classifier
predictor:
type: python
Expand Down Expand Up @@ -295,7 +299,7 @@ $ cortex get --watch
api status up-to-date requested last update
iris-classifier live 1 1 5m
another-iris-classifier live 1 1 8s
another-iris-classifier live 1 1 1m
```

## Add a batch API
Expand Down Expand Up @@ -335,6 +339,8 @@ class PythonPredictor:
Next, add the `api` to `cortex.yaml`:

```yaml
# cortex.yaml
- name: iris-classifier
predictor:
type: python
Expand Down Expand Up @@ -391,9 +397,9 @@ Since a new file was added to the directory, and all files in the directory cont
$ cortex get --watch
api status up-to-date requested last update
iris-classifier live 1 1 17s
another-iris-classifier live 1 1 17s
batch-iris-classifier live 1 1 17s
iris-classifier live 1 1 1m
another-iris-classifier live 1 1 1m
batch-iris-classifier live 1 1 1m
```

<br>
Expand Down
2 changes: 1 addition & 1 deletion examples/sklearn/iris-classifier/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

pickle.dump(model, open("model.pkl", "wb"))
s3 = boto3.client("s3")
s3.upload_file("model.pkl", "my-bucket", "sklearn/iris-classifier/model.pkl")
s3.upload_file("model.pkl", "cortex-examples", "sklearn/iris-classifier/model.pkl")

0 comments on commit 62702df

Please sign in to comment.