CausalEffect

class lingam.CausalEffect(causal_model)[source]

Implementation of causality and prediction. [1]

References

__init__(causal_model)[source]

Construct a CausalEffect.

Parameters:

causal_model (lingam object inherits 'lingam._BaseLiNGAM' or array-like with shape (n_features, n_features)) – Causal model for calculating causal effects. The lingam object is lingam.DirectLiNGAM or lingam.ICALiNGAM, and fit function needs to be executed already. For array-like, adjacency matrix to estimate causal effect, where n_features is the number of features.

estimate_effects_on_prediction(X, target_index, pred_model)[source]

Estimate the intervention effect with the prediction model.

Parameters:
  • X (array-like, shape (n_samples, n_features)) – Original data, where n_samples is the number of samples and n_features is the number of features.

  • target_index (int) – Index of target variable.

  • pred_model (model object implementing 'predict' or 'predict_proba') – Model to predict the expectation. For linear regression or non-linear reggression, model object must have predict method. For logistic regression, model object must have predict_proba method.

Returns:

intervention_effects – Estimated values of intervention effect. The first column of the list is the value of ‘E[Y|do(Xi=mean)]-E[Y|do(Xi=mean+std)]’, and the second column is the value of ‘E[Y|do(Xi=mean)]–E[Y|do(Xi=mean-std)]’. The maximum value in this array is the feature having the greatest intervention effect.

Return type:

array-like, shape (n_features, 2)

estimate_optimal_intervention(X, target_index, pred_model, intervention_index, desired_output)[source]

Estimate of the intervention such that the expectation of the prediction of the post-intervention observations is equal or close to a specified value.

Parameters:
  • X (array-like, shape (n_samples, n_features)) – Original data, where n_samples is the number of samples and n_features is the number of features.

  • target_index (int) – Index of target variable.

  • pred_model (model object.) – Model to predict the expectation. Only linear regression model can be specified. Model object musst have coef_ and intercept_ attributes.

  • intervention_index (int) – Index of variable to apply intervention.

  • desired_output – Desired expected post-intervention output of prediction.

Returns:

optimal_intervention – Optimal intervention on intervention_index variable.

Return type:

float