How to access estimator parameters in scikit-learn?

Hey, I recently came across a concept in Scikit-learn regarding accessing the estimated parameters or attributes of an estimator. Could anyone explain the common methods for doing this and how they fit into machine learning tasks?

In Scikit-learn, some common ways to access the estimated parameters or attributes of an estimator include:

  1. Using the get_params() method: This method returns a dictionary of the estimator’s current parameters and their values.

  2. Using the estimator’s attributes: Some estimators have specific attributes that contain the estimated parameters or other useful information, such as coef_ or intercept_ for linear models and feature_importances_ for tree-based models.

  3. Printing the estimator object: The estimator object itself can provide information about the estimator’s parameters and their default values.

Here is the code snippet of linear model to illustrate this:

As you can see, the get_params() method returns the estimator’s current parameters, including the ones that were set explicitly and the ones that were set to their default values. However, the coef_ and intercept_ attributes are specific to linear models and contain the estimated coefficients and intercepts, respectively. Also, the fit() method updates all of the estimator’s parameters, but not all of them are printed or reported. Finally, the estimator object itself provides information about the estimator’s parameters and their default values, which can be useful when exploring and setting the parameters.