scmrelax
Submodules
Attributes
Functions
|
Estimate weights using different relaxation methods and standard synthetic control. |
Package Contents
- scmrelax.__version__
- scmrelax.fit(X_pre, y_pre, X)[source]
Estimate weights using different relaxation methods and standard synthetic control.
This function applies multiple relaxation methods (e.g., synthetic control, L2 relaxation, entropy relaxation, and empirical likelihood relaxation) to estimate weights and make predictions.
- Parameters:
X_pre (ndarray of shape (n_pre_samples, n_features)) – Pre-treatment input data matrix (control units).
y_pre (ndarray of shape (n_pre_samples,)) – Pre-treatment target values (treated unit).
X (ndarray of shape (n_samples, n_features)) – Post-treatment input data matrix (control units).
- Returns:
Dictionary containing the estimated weights and predictions for each method: - ‘scm’: Synthetic control method. - ‘EL’: Empirical likelihood relaxation. - ‘entropy’: Entropy relaxation. - ‘l2’: L2 relaxation. Each key contains:
- ’weights’: ndarray of shape (n_features,)
Estimated weights for control units.
- ’predictions’: ndarray of shape (n_samples,)
Predicted post-treatment target values.
- Return type:
dict
Example
>>> import numpy as np >>> from scmrelax.scmrelax import fit
>>> # Pre-treatment data (control units) >>> X_pre = np.array([[1.2, 3.4, 5.6], ... [2.3, 4.5, 6.7], ... [3.1, 5.4, 7.8]])
>>> # Pre-treatment target data (treated unit) >>> y_pre = np.array([2.5, 3.7, 4.1])
>>> # Post-treatment data (control units) >>> X = np.array([[1.5, 3.8, 6.1], ... [2.7, 4.9, 7.2]])
>>> # Fit the models and get results >>> results = fit(X_pre, y_pre, X)
>>> # Print results >>> for method, res in results.items(): ... print(f"{method} weights:", res['weights']) ... print(f"{method} predictions:", res['predictions'])