Skip to content

Add categorical variable example model and in README file #2

@lopezco

Description

@lopezco

Add a LightGBM model example with categorical variables.
Ex:

from lightgbm import LGBMClassifier
import pandas as pd
import joblib

df = pd.DataFrame({"feature1": [1.,1.,5.], "feature2": [2.,2.,5.], "feature3": ["B","B","A"]})
df['feature3'] = df['feature3'].astype('category')

model_path = './model.joblib'

model = LGBMClassifier()
model.fit(df, [0, 0, 1])
to_save = dict(model=model,
               metadata={"features": [
                   {"name": "feature1", "type": "numeric"},
                   {"name": "feature2", "type": "numeric", "default": -1},
                   {"name": "feature3", "type": "category", "categories": ["A", "B"]}]})

with open(model_path, 'wb') as fo:
    joblib.dump(to_save, fo)

Add something like the following in the README

{
    "model": trained_model,
    "metadata": {"features": [
                            {"name": "feature1", "type": "numeric"},
                            {"name": "feature2", "type": "numeric", "default": -1},
                            {"name": "feature3", "type": "category", "categories": ["A", "B"]}]}
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions