

.. _sphx_glr_auto_examples_linear_model:

.. _linear_examples:

Generalized Linear Models
-------------------------

Examples concerning the :mod:`sklearn.linear_model` module.



.. raw:: html

    <div class="sphx-glr-thumbnails">


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example compares two different bayesian regressors:">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ard_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ard.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Comparing Linear Bayesian Regressors</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Comparing various online solvers">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_comparison_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_comparison.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Comparing various online solvers</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Computes a Bayesian Ridge Regression of Sinusoids.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_bayesian_ridge_curvefit_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_bayesian_ridge_curvefit.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Curve Fitting with Bayesian Ridge Regression</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Stochastic Gradient Descent is an optimization technique which minimizes a loss function in a s...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_early_stopping_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_early_stopping.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Early stopping of Stochastic Gradient Descent</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The following example shows how to precompute the gram matrix while using weighted samples with...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_elastic_net_precomputed_gram_matrix_with_weighted_samples_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_elastic_net_precomputed_gram_matrix_with_weighted_samples.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Fitting an Elastic Net with a precomputed Gram Matrix and Weighted Samples</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Fit Ridge and HuberRegressor on a dataset with outliers.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_huber_vs_ridge_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_huber_vs_ridge.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">HuberRegressor vs Ridge on dataset with strong outliers</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The multi-task lasso allows to fit multiple regression problems jointly enforcing the selected ...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_multi_task_lasso_support_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_multi_task_lasso_support.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Joint feature selection with multi-task Lasso</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Comparison of the sparsity (percentage of zero coefficients) of solutions when L1, L2 and Elast...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_logistic_l1_l2_sparsity_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_logistic_l1_l2_sparsity.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">L1 Penalty and Sparsity in Logistic Regression</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The present example compares three l1-based regression models on a synthetic signal obtained fr...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_lasso_and_elasticnet_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_lasso_and_elasticnet.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">L1-based models for Sparse Signals</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Lasso and elastic net (L1 and L2 penalisation) implemented using a coordinate descent.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_lasso_coordinate_descent_path_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_lasso_coordinate_descent_path.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Lasso and Elastic Net</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example reproduces the example of Fig. 2 of [ZHT2007]_. A LassoLarsIC estimator is fit on ...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_lasso_lars_ic_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_lasso_lars_ic.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Lasso model selection via information criteria</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example focuses on model selection for Lasso models that are linear models with an L1 pena...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_lasso_model_selection_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_lasso_model_selection.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Lasso model selection: AIC-BIC / cross-validation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="We show that linear_model.Lasso provides the same results for dense and sparse data and that in...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_lasso_dense_vs_sparse_data_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_lasso_dense_vs_sparse_data.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Lasso on dense and sparse data</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Computes Lasso Path along the regularization parameter using the LARS algorithm on the diabetes...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_lasso_lars_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_lasso_lars.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Lasso path using LARS</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The coefficients, residual sum of squares and the coefficient of determination are also calcula...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ols_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ols.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Linear Regression Example</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Show below is a logistic-regression classifiers decision boundaries on the first two dimensions...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_iris_logistic_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_iris_logistic.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Logistic Regression 3-class Classifier</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Shown in the plot is how the logistic regression would, in this synthetic dataset, classify val...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_logistic_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_logistic.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Logistic function</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Here we fit a multinomial logistic regression with L1 penalty on a subset of the MNIST digits c...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sparse_logistic_regression_mnist_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sparse_logistic_regression_mnist.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">MNIST classification using multinomial logistic + L1</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Comparison of multinomial logistic L1 vs one-versus-rest L1 logistic regression to classify doc...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sparse_logistic_regression_20newsgroups_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sparse_logistic_regression_20newsgroups.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Multiclass sparse logistic regression on 20newgroups</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="In this example, we fit a linear model with positive constraints on the regression coefficients...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_nnls_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_nnls.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Non-negative least squares</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to approximate the solution of sklearn.svm.OneClassSVM in the case of an...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgdocsvm_vs_ocsvm_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgdocsvm_vs_ocsvm.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">One-Class SVM versus One-Class SVM using Stochastic Gradient Descent</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Ridge regression is basically minimizing a penalised version of the least-squared function. The...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ols_ridge_variance_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ols_ridge_variance.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Ordinary Least Squares and Ridge Regression Variance</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Using orthogonal matching pursuit for recovering a sparse signal from a noisy measurement encod...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_omp_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_omp.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Orthogonal Matching Pursuit</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Shows the effect of collinearity in the coefficients of an estimator.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ridge_path_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ridge_path.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Plot Ridge coefficients as a function of the regularization</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Plot decision surface of multi-class SGD on iris dataset. The hyperplanes corresponding to the ...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_iris_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_iris.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Plot multi-class SGD on the iris dataset</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Plot decision surface of multinomial and One-vs-Rest Logistic Regression. The hyperplanes corre...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_logistic_multinomial_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_logistic_multinomial.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Plot multinomial and One-vs-Rest Logistic Regression</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the use of log-linear Poisson regression on the French Motor Third-Par...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_poisson_regression_non_normal_loss_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_poisson_regression_non_normal_loss.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Poisson regression and non-normal loss</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to approximate a function with polynomials up to degree degree by...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_polynomial_interpolation_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_polynomial_interpolation.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Polynomial and Spline interpolation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates how quantile regression can predict non-trivial conditional quantiles.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_quantile_regression_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_quantile_regression.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Quantile regression</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip=" Train l1-penalized logistic regression models on a binary classification problem derived from ...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_logistic_path_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Regularization path of L1- Logistic Regression</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A model that overfits learns the training data too well, capturing both the underlying patterns...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ridge_coeffs_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ridge_coeffs.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Ridge coefficients as a function of the L2 Regularization</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Here a sine function is fit with a polynomial of order 3, for values close to zero.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_robust_fit_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_robust_fit.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Robust linear estimator fitting</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="In this example, we see how to robustly fit a linear model to faulty data using the ransac_regr...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ransac_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ransac.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Robust linear model estimation using RANSAC</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Plot the maximum margin separating hyperplane within a two-class separable dataset using a line...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_separating_hyperplane_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_separating_hyperplane.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">SGD: Maximum margin separating hyperplane</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Contours of where the penalty is equal to 1 for the three penalties L1, L2 and elastic-net.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_penalties_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_penalties.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">SGD: Penalties</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Plot decision function of a weighted dataset, where the size of points is proportional to its w...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_weighted_samples_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_weighted_samples.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">SGD: Weighted samples</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A plot that compares the various convex loss functions supported by SGDClassifier .">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_sgd_loss_functions_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_sgd_loss_functions.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">SGD: convex loss functions</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Features 1 and 2 of the diabetes-dataset are fitted and plotted below. It illustrates that alth...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_ols_3d_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_ols_3d.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Sparsity Example: Fitting only features 1  and 2</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Computes a Theil-Sen Regression on a synthetic dataset.">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_theilsen_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_theilsen.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Theil-Sen Regression</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the use of Poisson, Gamma and Tweedie regression on the French Motor T...">

.. only:: html

  .. image:: /auto_examples/linear_model/images/thumb/sphx_glr_plot_tweedie_regression_insurance_claims_thumb.png
    :alt:

  :ref:`sphx_glr_auto_examples_linear_model_plot_tweedie_regression_insurance_claims.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Tweedie regression on insurance claims</div>
    </div>


.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/linear_model/plot_ard
   /auto_examples/linear_model/plot_sgd_comparison
   /auto_examples/linear_model/plot_bayesian_ridge_curvefit
   /auto_examples/linear_model/plot_sgd_early_stopping
   /auto_examples/linear_model/plot_elastic_net_precomputed_gram_matrix_with_weighted_samples
   /auto_examples/linear_model/plot_huber_vs_ridge
   /auto_examples/linear_model/plot_multi_task_lasso_support
   /auto_examples/linear_model/plot_logistic_l1_l2_sparsity
   /auto_examples/linear_model/plot_lasso_and_elasticnet
   /auto_examples/linear_model/plot_lasso_coordinate_descent_path
   /auto_examples/linear_model/plot_lasso_lars_ic
   /auto_examples/linear_model/plot_lasso_model_selection
   /auto_examples/linear_model/plot_lasso_dense_vs_sparse_data
   /auto_examples/linear_model/plot_lasso_lars
   /auto_examples/linear_model/plot_ols
   /auto_examples/linear_model/plot_iris_logistic
   /auto_examples/linear_model/plot_logistic
   /auto_examples/linear_model/plot_sparse_logistic_regression_mnist
   /auto_examples/linear_model/plot_sparse_logistic_regression_20newsgroups
   /auto_examples/linear_model/plot_nnls
   /auto_examples/linear_model/plot_sgdocsvm_vs_ocsvm
   /auto_examples/linear_model/plot_ols_ridge_variance
   /auto_examples/linear_model/plot_omp
   /auto_examples/linear_model/plot_ridge_path
   /auto_examples/linear_model/plot_sgd_iris
   /auto_examples/linear_model/plot_logistic_multinomial
   /auto_examples/linear_model/plot_poisson_regression_non_normal_loss
   /auto_examples/linear_model/plot_polynomial_interpolation
   /auto_examples/linear_model/plot_quantile_regression
   /auto_examples/linear_model/plot_logistic_path
   /auto_examples/linear_model/plot_ridge_coeffs
   /auto_examples/linear_model/plot_robust_fit
   /auto_examples/linear_model/plot_ransac
   /auto_examples/linear_model/plot_sgd_separating_hyperplane
   /auto_examples/linear_model/plot_sgd_penalties
   /auto_examples/linear_model/plot_sgd_weighted_samples
   /auto_examples/linear_model/plot_sgd_loss_functions
   /auto_examples/linear_model/plot_ols_3d
   /auto_examples/linear_model/plot_theilsen
   /auto_examples/linear_model/plot_tweedie_regression_insurance_claims

