File size: 1,309 Bytes
829e3ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

"""
This module sets up a Lasso Regression model with hyperparameter tuning.

Features:
- Uses `Lasso` estimator from scikit-learn.
- Defines a hyperparameter grid for preprocessing and model-specific parameters.
- Increases `max_iter` to address convergence warnings.

Special Considerations:
- Lasso Regression may produce convergence warnings if `max_iter` is insufficient.
- Applying a log transformation (`log_transform`) to the target variable can be beneficial if it's skewed.
- Ensure `OneHotEncoder` outputs dense arrays to avoid compatibility issues.
"""

from sklearn.linear_model import Lasso

# Define the estimator
estimator = Lasso()

# Define the hyperparameter grid
param_grid = {
    'model__alpha': [0.01, 0.1, 1.0, 10.0],  # Regularization strength
    'model__max_iter': [5000],  # Single value to ensure convergence
    'model__fit_intercept': [True],  # Assume the intercept is important
    'model__selection': ['cyclic'],  # Focus on the default cyclic selection
    'preprocessor__num__imputer__strategy': ['mean'],  # Single imputation strategy
    'preprocessor__num__scaler__with_mean': [True],  # StandardScaler
    'preprocessor__num__scaler__with_std': [True],  # StandardScaler
}

# Optional: Define the default scoring metric
default_scoring = 'neg_root_mean_squared_error'