causallib.estimation.base_weight module

  1. Copyright 2019 IBM Corp.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Created on Apr 25, 2018

class causallib.estimation.base_weight.PropensityEstimator(learner, use_stabilized=False, *args, **kwargs)[source]

Bases: causallib.estimation.base_weight.WeightEstimator

Interface for causal estimators balancing datasets through propensity (i.e. treatment probability) estimation (e.g. inverse probability weighting).

Parameters
abstract compute_propensity(X, a, treatment_values=None, **kwargs)[source]
abstract compute_propensity_matrix(X, a, **kwargs)[source]
class causallib.estimation.base_weight.WeightEstimator(learner, use_stabilized=False, *args, **kwargs)[source]

Bases: object

Interface for causal estimators balancing datasets through weighting.

Parameters
abstract compute_weight_matrix(X, a, use_stabilized=None, **kwargs)[source]

Computes individual weight across all possible treatment values. f(Pr[A=a_j | X_i]) for all individual i and treatment j.

Parameters
  • X (pd.DataFrame) – Covariate matrix of size (num_subjects, num_features).

  • a (pd.Series) – Treatment assignment of size (num_subjects,).

  • use_stabilized (bool) – Whether to re-weigh the learned weights with the prevalence of the treatment. This overrides the use_stabilized parameter provided at initialization. See Also: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4351790/#S6title

  • **kwargs

Returns

A matrix of size (num_subjects, num_treatments) with weight for every individual and every

treatment.

Return type

pd.DataFrame

abstract compute_weights(X, a, treatment_values=None, use_stabilized=None, **kwargs)[source]

Computes individual weight given the individual’s treatment assignment. f(Pr[A=a_i | X_i]) for each individual i.

Parameters
  • X (pd.DataFrame) – Covariate matrix of size (num_subjects, num_features).

  • a (pd.Series) – Treatment assignment of size (num_subjects,).

  • treatment_values (Any | None) – A desired value/s to extract weights to (i.e. weights to what treatment value should be calculated). If not specified, then the weights are chosen by the individual’s actual treatment assignment.

  • use_stabilized (bool) – Whether to re-weigh the learned weights with the prevalence of the treatment. This overrides the use_stabilized parameter provided at initialization. See Also: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4351790/#S6title

  • **kwargs

Returns

A vector of size (num_subjects,) with a weight for each individual

Return type

pd.Series

evaluate_balancing(X, a, y, w)[source]
abstract fit(X, a, y=None)[source]

Trains a model to predict treatment assignment given the covariates: Pr[A|X].

Parameters
  • X (pd.DataFrame) – Covariate matrix of size (num_subjects, num_features).

  • a (pd.Series) – Treatment assignment of size (num_subjects,).

  • y – IGNORED.

Returns

A causal weight model with an inner learner fitted.

Return type

WeightEstimator