Explain the difference between L1 and L2 regularization.
TechnicalJunior AI EngineerMachine Learning EngineerData ScientistSenior Data ScientistL1 regularization, also known as Lasso, adds the absolute value of the coefficients as a penalty term to the loss function, promoting sparsity in the model. This means it can effectively reduce the number of features by driving some coefficients to zero. On the other hand, L2 regularization, or Ridge, adds the squared values of the coefficients as a penalty, which tends to keep all features but reduces their impact, thus preventing overfitting without eliminating any features.
The main trade-off is that L1 can lead to simpler models, while L2 generally provides better predictive performance when all features are relevant.