Skip to content

Commit c57d7f6

Browse files
committed
Solves issue #2
1 parent 47a92bb commit c57d7f6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ or one of the scripts in the `python/example` folder
3333
```javascript
3434
{
3535
"model": trained_model,
36-
"metadata": {"features": [{"name": "feature1", "type": "numeric"},
37-
{"name": "feature2", "type": "numeric", "default": -1},
38-
{"name": "feature3", "type": "numeric"}]}
36+
"metadata": {"features": [
37+
{"name": "feature1", "type": "numeric"},
38+
{"name": "feature2", "type": "numeric", "default": -1},
39+
{"name": "feature3", "type": "category", "categories": ["A", "B"]}]}
3940
}
4041
```
4142

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from lightgbm import LGBMClassifier
2+
import pandas as pd
3+
import joblib
4+
5+
6+
df = pd.DataFrame({"feature1": [1.,1.,5.], "feature2": [2.,2.,5.], "feature3": ["B","B","A"]})
7+
df['feature3'] = df['feature3'].astype('category')
8+
9+
model_path = './model.joblib'
10+
11+
model = LGBMClassifier()
12+
model.fit(df, [0, 0, 1])
13+
to_save = dict(model=model,
14+
metadata={"features": [
15+
{"name": "feature1", "type": "numeric"},
16+
{"name": "feature2", "type": "numeric", "default": -1},
17+
{"name": "feature3", "type": "category", "categories": ["A", "B"]}]})
18+
19+
with open(model_path, 'wb') as fo:
20+
joblib.dump(to_save, fo)

0 commit comments

Comments
 (0)