Skip to content

Enable external predictions for short model in benchmark #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 11, 2024

Conversation

SvenKlaassen
Copy link
Member

Description

Contributed by @lucien1011.

This pull request adds an optional input arguments fit_args to the function sensitivity_benchmark in the class DoubleML. Most importantly, this addition will enable the usage of external_predictions when fitting short models for sensitivity analysis.

The new argument has to be in a nested dictionary like this:

dataset = dml.DoubleMLData(
    df,
    y_col='y',
    d_col='d',
    x_cols=cov_cols,
    force_all_x_finite=False,
)

dml_irm = dml.DoubleMLIRM(
    dataset,
    ml_g=RandomForestRegressor(), #dummy learner only
    ml_l=RandomForestClassifier(),
)

# Some user-specific codes to calculate external_predictions and put in the following columns
# df['d_prop'] df['y_pred_d0'] df['y_pred_d1']

bm = dml_irm.sensitivity_benchmark(
    benchmarking_set=['covariate_to_be_tested'],
    fit_args=dict(
        external_predictions=(
            d=dict(
                ml_m=df['d_prop'].to_numpy().reshape(-1,1),
                ml_g0=df['y_pred_d0'].to_numpy().reshape(-1,1),
                ml_g1=df['y_pred_d1'].to_numpy().reshape(-1,1),
            ),
        ),
    ),
)

Reference to Issues or PRs

No related issues or PRs to my knowledge.

PR Checklist

Please fill out this PR checklist (see our contributing guidelines for details).

  • The title of the pull request summarizes the changes made.
  • The PR contains a detailed description of all changes and additions.
  • References to related issues or PRs are added.
  • The code passes all (unit) tests.
  • Enhancements or new feature are equipped with unit tests.
  • The changes adhere to the PEP8 standards.

@SvenKlaassen SvenKlaassen merged commit ba9cc57 into main Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant