causalpy.skl_models
Scikit-Learn Models
Weighted Proportion
- class causalpy.skl_models.WeightedProportion
Model which minimises sum squared error subject to:
All weights are bound between 0-1
Weights sum to 1.
Inspiration taken from this blog post https://towardsdatascience.com/understanding-synthetic-control-methods-dd9a291885a1
Example
>>> import numpy as np >>> from causalpy.skl_models import WeightedProportion >>> rng = np.random.default_rng(seed=42) >>> X = rng.normal(loc=0, scale=1, size=(20,2)) >>> y = rng.normal(loc=0, scale=1, size=(20,)) >>> wp = WeightedProportion() >>> wp.fit(X, y) WeightedProportion() >>> wp.coef_ array([[0.36719946, 0.63280054]]) >>> X_new = rng.normal(loc=0, scale=1, size=(10,2)) >>> wp.predict(X_new) array(...)
- fit(X, y)
Fit model on data X with predictor y
- loss(W, X, y)
Compute root mean squared loss with data X, weights W, and predictor y
- predict(X)
Predict results for data X
- set_score_request(*, sample_weight='$UNCHANGED$')
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.Parameters
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weight
parameter inscore
.
Returns
- selfobject
The updated object.
- Parameters:
self (WeightedProportion)
- Return type: