Skip to content

[python-package] monotonic constraints don't work #6155

Open
@yuanf8

Description

Description

I've trained a monotonic binary classifier with 'monotone_constraints_method': 'advanced', but as per the example below, it doesn't seem to work : (

Reproducible example

import lightgbm as lgb
import pandas as pd

bst = lgb.Booster(model_file='model_file_test.txt')
df = pd.read_csv('test_data.csv')
df['pred_score'] = bst.predict(df.drop(columns=['pred_score']))

In the test_data.csv, the two records only differ in feature columns col_13 and col 15.

col_13 col_15
0 9 2
1 28.3156374 2.32535749

And in the model_file_test.txt,

feature_names=col_1 col_2 col_3 col_4 col_5 col_6 col_7 col_8 col_9 col_10 col_11 col_12 col_13 col_14 col_15 col_16 col_17 col_18 col_19 col_20 col_21 col_22 col_23 col_24 col_25 col_26 col_27 col_28 col_29 col_30 col_31
monotone_constraints=1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1

Features col_13 and col_15 are constrained to be monotonic increasing.

However, the pred_scores from bst.predict() seem to decrease as the feature values increase.

pred_score
0 0.41453699
1 0.41169457

Environment info

LightGBM version or commit hash: 4.0.0

Command(s) you used to install LightGBM:

python3.9 -m pip install lightgbm

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions