You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add ability to select different protocols for the communication medium in `README.md`
* `CHANGELOG.md` updated
* enhance code snippets
* `CHANGELOG.md` updated
* convert `pycon` code snippets to `python` snippets
* merge with latest state of dev
Copy file name to clipboardExpand all lines: README.md
+46-36Lines changed: 46 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,21 +80,21 @@ PyMilo is an open source Python package that provides a simple, efficient, and s
80
80
## Usage
81
81
### Import/Export
82
82
Imagine you want to train a `LinearRegression` model representing this equation: $y = x_0 + 2x_1 + 3$. You will create data points (`X`, `y`) and train your model as follows.
83
-
```pycon
84
-
>>> import numpy as np
85
-
>>> from sklearn.linear_model import LinearRegression
Using PyMilo `Export` class you can easily serialize and export your trained model into a JSON file.
95
-
```pycon
96
-
>>> from pymilo import Export
97
-
>>> Export(model).save("model.json")
95
+
```python
96
+
from pymilo import Export
97
+
Export(model).save("model.json")
98
98
```
99
99
100
100
You can check out your model as a JSON file now.
@@ -142,10 +142,10 @@ You can check out your model as a JSON file now.
142
142
You can see all the learned parameters of the model in this file and change them if you want. This JSON representation is a transparent version of your model.
143
143
144
144
Now let's load it back. You can do it easily by using PyMilo `Import` class.
145
-
```pycon
146
-
>>> from pymilo import Import
147
-
>>> model = Import("model.json").to_model()
148
-
>>> pred = model.predict(np.array([[3, 5]]))
145
+
```python
146
+
from pymilo import Import
147
+
model = Import("model.json").to_model()
148
+
pred = model.predict(np.array([[3, 5]]))
149
149
# pred = [16.] (=1 * 3 + 2 * 5 + 3)
150
150
```
151
151
This loaded model is exactly the same as the original trained model.
@@ -157,44 +157,54 @@ You can easily serve your ML model from a remote server using `ML streaming` fea
157
157
158
158
⚠️ In order to use `ML streaming` feature, make sure you've installed the `streaming` mode of PyMilo
159
159
160
+
You can choose either `REST` or `WebSocket` as the communication medium protocol.
161
+
160
162
#### Server
161
-
Let's assume you are in the remote server and you want to import the exported JSON file and start serving your model!
Now `PymiloServer` runs on port `8000` and exposes REST API to `upload`, `download` and retrieve **attributes** either **data attributes** like `model._coef` or **method attributes** like `model.predict(x_test)`.
170
176
171
177
#### Client
172
178
By using `PymiloClient` you can easily connect to the remote `PymiloServer` and execute any functionalities that the given ML model has, let's say you want to run `predict` function on your remote ML model and get the result:
ℹ️ If you've deployed `PymiloServer` locally (on port `8000` for instance), then `SERVER_URL` would be `http://127.0.0.1:8000`
190
+
ℹ️ If you've deployed `PymiloServer` locally (on port `8000` for instance), then `SERVER_URL` would be `http://127.0.0.1:8000` or `ws://127.0.0.1:8000` based on the selected protocol for the communication medium.
181
191
182
192
You can also download the remote ML model into your local and execute functions locally on your model.
183
193
184
194
Calling `download` function on `PymiloClient` will sync the local model that `PymiloClient` wraps upon with the remote ML model, and it doesn't save model directly to a file.
185
195
186
-
```pycon
187
-
>>> pymilo_client.download()
196
+
```python
197
+
pymilo_client.download()
188
198
```
189
199
If you want to save the ML model to a file in your local, you can use `Export` class.
`PymiloClient` wraps around the ML model, either to the local ML model or the remote ML model, and you can work with `PymiloClient` in the exact same way that you did with the ML model, you can run exact same functions with same signature.
0 commit comments