SwissDataScienceCenter / mlschema-model-converters

Apache License 2.0
3 stars 0 forks source link

mls from lightgbm #11

Open chrisbarber opened 4 years ago

chrisbarber commented 4 years ago

https://lightgbm.readthedocs.io/

chrisbarber commented 4 years ago

LGBMRegressor does indeed have a get_params and the resulting json-ld looks then like this:

{
    "http://purl.org/dc/terms/hasVersion":null,
    "http://www.w3.org/ns/mls#hasInput":[
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:string",
                "@value":"gbdt"
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:boosting_type",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:5359ac724602472888cfce40ba6ec302",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":1.0
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:colsample_bytree",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:a00893936b7c4e4d82b4c06b800b34c4",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:string",
                "@value":"split"
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:importance_type",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:0a65ff7e118a434cbc0b9b85a166ddaf",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":0.05
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:learning_rate",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:a47b43e6fadf4b8fa8a7e132a9c7434a",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":-1
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:max_depth",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:fbcfa65444674e0d9f935ad14cb261e7",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":20
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:min_child_samples",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:71c45483cc66462b86e7cfefcb5e9ecd",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":0.001
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:min_child_weight",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:46ff480ca2b7451f8a48926bbd208e13",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":0.0
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:min_split_gain",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:330b8c62fd494925af2a9d6c30a07cf1",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":20
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:n_estimators",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:57c90dcd95214d3eb87fa808a34864c0",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":-1
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:n_jobs",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:3f541ba4ab31424e9d71e4b1e8ce416e",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":31
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:num_leaves",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:8b43ddcf1354492daa9876ebbea37c4f",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:string",
                "@value":"regression"
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:objective",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:83079f74a4c74f36acf1f17cf7c65633",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":0.0
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:reg_alpha",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:d978eedcc69d4c859e616b5a82da8ccc",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":0.0
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:reg_lambda",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:ff439e4401944f2fb3b76078350646f4",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:boolean",
                "@value":true
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:silent",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:8de089af9bd849a5991f7e2b74dbfb4f",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:float",
                "@value":1.0
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:subsample",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:ba2ab6f7790d46b39638a2ae53902aa7",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":200000
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:subsample_for_bin",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:70c9b5f67ea94eee8fee5c70f9a731c0",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        },
        {
            "http://www.w3.org/ns/mls#hasValue":{
                "@type":"xsd:int",
                "@value":0
            },
            "http://www.w3.org/ns/mls#specifiedBy":{
                "@id":"_:subsample_freq",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            "@id":"_:4f3a838658684613830218b2b0961a6b",
            "@type":[
                "http://www.w3.org/ns/mls#HyperParameterSetting"
            ]
        }
    ],
    "http://www.w3.org/ns/mls#executes":{
        "http://www.w3.org/ns/mls#hasHyperParameter":[
            {
                "@id":"_:boosting_type",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:class_weight",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:colsample_bytree",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:importance_type",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:learning_rate",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:max_depth",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:min_child_samples",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:min_child_weight",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:min_split_gain",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:n_estimators",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:n_jobs",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:num_leaves",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:objective",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:random_state",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:reg_alpha",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:reg_lambda",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:silent",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:subsample",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:subsample_for_bin",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            },
            {
                "@id":"_:subsample_freq",
                "@type":[
                    "http://www.w3.org/ns/mls#HyperParameter"
                ]
            }
        ],
        "http://www.w3.org/ns/mls#implements":{
            "@id":"_:lightgbm.sklearn.LGBMRegressor",
            "@type":[
                "http://www.w3.org/ns/mls#Algorithm"
            ]
        },
        "http://purl.org/dc/terms/hasVersion":"0.22.2.post1",
        "http://purl.org/dc/terms/title":null,
        "@id":"_:lightgbm.sklearn.LGBMRegressor",
        "@type":[
            "http://www.w3.org/ns/mls#Implementation"
        ]
    },
    "http://www.w3.org/ns/mls#hasOutput":[

    ],
    "http://www.w3.org/ns/mls#implements":{
        "@id":"_:lightgbm.sklearn.LGBMRegressor",
        "@type":[
            "http://www.w3.org/ns/mls#Algorithm"
        ]
    },
    "http://purl.org/dc/terms/title":null,
    "@id":"-9223363242114198191",
    "@type":[
        "http://www.w3.org/ns/mls#Run"
    ]
}

On the other hand when I follow https://github.com/microsoft/LightGBM/blob/master/examples/python-guide/simple_example.py I get a Booster object which has no get_params. But it has a params attribute that returns

{'boosting_type': 'gbdt', 'objective': 'regression', 'metric': {'l2', 'l1'}, 'num_leaves': 31, 'learning_rate': 0.05, 'feature_fraction': 0.9, 'bagging_fraction': 0.8, 'bagging_freq': 5, 'verbose': 0, 'num_iterations': 20, 'early_stopping_round': 5}

Maybe it is good enough to just support these two apis; I'm not sure. Looking through the other examples so far all I see are instances of lgb.train which should return the Booster object, or LGBMRegressor.