4. Tackling Company Bankruptcy
Activity 4.01: Feature Selection with Lasso
- Import
Lasso
from the sklearn.linear_model package:from sklearn.linear_model import Lasso from sklearn.feature_selection import SelectFromModel
- Fit the independent and dependent variables with lasso regularization for the
mean_imputed_df4
DataFrame:features_names=X6.columns.tolist() lasso = Lasso(alpha=0.01 ,positive=True) lasso.fit(X6,y6)
- Print the coefficients of lasso regularization:
coef_list=sorted(zip(map(lambda x: round(x,4), \ lasso.coef_.reshape(-1)),\ features_names), reverse=True) coef_list [0:5]
The output will be as follows:
[(0.0009, 'X21'), (0.0002, 'X2'), (0.0001, ...