utils.stats.compute_standardized_betas
utils.stats.compute_standardized_betas(model, X_encoded, y)
Computes standardized (beta) coefficients for a fitted statsmodels OLS model.
Parameters
| model |
statsmodels.regression.linear_model.RegressionResultsWrapper |
The fitted OLS model. |
required |
| X_encoded |
pandas.DataFrame |
The design matrix of independent variables. |
required |
| y |
pandas.Series |
The dependent variable. |
required |
Returns
|
pd.DataFrame |
pandas.DataFrame: A DataFrame containing the standardized beta coefficients. |
Examples
>>> from spotpython.utils.stats import compute_standardized_betas
>>> import pandas as pd
>>> import statsmodels.api as sm
>>> data = pd.DataFrame({
... 'x1': [1, 2, 3, 4, 5],
... 'x2': [2, 4, 6, 8, 10],
... 'x3': [1, 3, 5, 7, 9]
... })
>>> y = pd.Series([1, 2, 3, 4, 5])
>>> X = sm.add_constant(data)
>>> model = sm.OLS(y, X).fit()
>>> compute_standardized_betas(model, data, y)
Variable Standardized Beta
0 const 0.000000
1 x1 0.000000
2 x2 0.000000
3 x3 0.000000