0
$\begingroup$

I am trying to compute prediction intervals for a classifier I trained in scikit-learn. Even after setting a new random_state parameter in my pipeline, this does not seem to change my results when refitting on the data. What can I do about this? This is a relevant snippet of the code I am using:

SEED_VALUE = 3

t_clf = Pipeline(steps=[('preprocessor', preprocessor),
                      ('lgbm', LGBMClassifier(class_weight="balanced",random_state=SEED_VALUE, max_depth=20, min_child_samples=20, num_leaves=31))

                 ])
states = [0,1,2,3]

///

for state in states:

    train_temp = train.copy()
    t_clf.set_params(lgbm__random_state=state)
    t_clf.fit(train_temp, train_temp['label'])
    t_clf.predict_proba(test)   

# output from predict probability doesn't change with varying states

The same occurs when trying to change shuffle order.

$\endgroup$
0
$\begingroup$

I realized that when shuffling I did not set the replace parameter to True which prevented randomness from being inserted into the process.

SEED_VALUE = 3

t_clf = Pipeline(steps=[('preprocessor', preprocessor),
                      ('lgbm', LGBMClassifier(class_weight="balanced",random_state=SEED_VALUE, max_depth=20, min_child_samples=20, num_leaves=31))

                 ])
states = [0,1,2,3]

///

for state in states:

    train_temp = train.copy().sample(frac=1, replace=True).reset_index(drop=True)
    t_clf.fit(train_temp, train_temp['label'])
    t_clf.predict_proba(test)   

# output from predict probability should be different each run
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.