Ejemplo n.º 1
0
                   'scoring': {
                       'sample_weight': 'scoring_weight'
                   },
               })

# %%
# Case C: unweighted feature selection

lr = LogisticRegressionCV(cv=GroupKFold(),
                          scoring='accuracy',
                          prop_routing={
                              'cv': ['groups'],
                              'scoring': ['sample_weight'],
                          })
pipe = make_pipeline(
    SelectKBest(),
    lr,
    prop_routing={'logisticregressioncv': ['sample_weight', 'groups']})
cross_validate(lr,
               X,
               y,
               cv=GroupKFold(),
               props={
                   'sample_weight': my_weights,
                   'groups': my_groups
               },
               scoring='accuracy',
               prop_routing={
                   'estimator': '*',
                   'cv': ['groups'],
                   'scoring': ['sample_weight'],
               })
Ejemplo n.º 2
0
lr = LogisticRegressionCV(
    cv=wrapped_group_cv,
    scoring=wrapped_weighted_acc,
).set_props_request(['sample_weight'])
cross_validate(lr, X, y, cv=wrapped_group_cv, scoring=wrapped_weighted_acc)

# %%
# Case C: unweighted feature selection

lr = WeightedLogisticRegressionCV(
    cv=wrapped_group_cv,
    scoring=wrapped_weighted_acc,
).set_props_request(['sample_weight'])
sel = SelectKBest()
pipe = make_pipeline(sel, lr)
cross_validate(pipe, X, y, cv=wrapped_group_cv, scoring=wrapped_weighted_acc)

# %%
# Case D: different scoring and fitting weights


def other_weighted_acc(est, X, y, sample_weight=None):
    return acc_scorer(est, X, y, sample_weight=MY_OTHER_WEIGHTS.loc[X.index])


lr = WeightedLogisticRegressionCV(
    cv=wrapped_group_cv,
    scoring=other_weighted_acc,
).set_props_request(['sample_weight'])
sel = SelectKBest()
props = {'cv__groups': my_groups,
         'estimator__cv__groups': my_groups,
         'scoring__sample_weight': my_weights,
         'estimator__scoring__sample_weight': my_weights}
cross_validate(lr, X, y, cv=GroupKFold(),
               props=props,
               scoring='accuracy')

# %%
# Case C: unweighted feature selection

lr = LogisticRegressionCV(
    cv=GroupKFold(),
    scoring='accuracy',
)
pipe = make_pipeline(SelectKBest(), lr)
props = {'cv__groups': my_groups,
         'estimator__logisticregressioncv__cv__groups': my_groups,
         'estimator__logisticregressioncv__sample_weight': my_weights,
         'scoring__sample_weight': my_weights,
         'estimator__scoring__sample_weight': my_weights}
cross_validate(pipe, X, y, cv=GroupKFold(),
               props=props,
               scoring='accuracy')

# %%
# Case D: different scoring and fitting weights

lr = LogisticRegressionCV(
    cv=GroupKFold(),
    scoring='accuracy',