You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Sofia Samaniego bfd84e1652 fix: corrige extension duplicada del README 2 weeks ago
README_files fix: corrige extension duplicada del README 2 weeks ago
Regresion_Logistica fix: corrige extension duplicada del README 2 weeks ago
.gitignore Estructura inicial del proyecto y primer código de Regresión Logística 3 weeks ago
README.md fix: corrige extension duplicada del README 2 weeks ago

README.md

Titulo del proyecto

Module 1: Logistic Regression Classifier

Author: Sofia Samaniego Lopez

Institution: Universidad Autonoma de Baja California (UABC)

Advisor: Dr. Gerardo Marx Chavez Campos

This script establishes the baseline evaluation for binary classification using the classic Iris dataset. The objective of this specific work is to analyze linear combination, decision boundaries, and probability estimation based on morphological features—specifically petal width and length.

The model utilizes Scikit-Learn's LogisticRegression framework to execute the optimization process and map inputs to a probability output using the Sigmoid function. This code serves as a strict benchmark comparison, generating the reference ground truth metrics and spatial visualizations required to evaluate the performance and accuracy of subsequent custom implementations.

Experimental Setup and Preliminary Analysis

Step 1: Import Required Libraries and Environment Setup

In this initial stage, the necessary scientific computing and data processing libraries are imported to set up our development environment:

  • NumPy: Utilized for efficient multi-dimensional array operations and core matrix algebra.
  • Matplotlib (pyplot): Employed to generate the spatial scatter plots and map the resulting decision boundaries.
  • Scikit-Learn: Specifically importing the datasets module to fetch the target morphological data and LogisticRegression to serve as our validation benchmark baseline.
!pip3 install scikit-learn
!pip3 install matplotlib
!pip3 install numpy

import matplotlib.pyplot as plt
import numpy as np

Step 2: Load and Explore the Iris Dataset Characteristics

The classic Iris Dataset is loaded into the workspace to establish our baseline classification task.

Dataset Overview and Morphological Features

The complete dataset consists of 150 samples from three distinct species of Iris flowers (Iris setosa, Iris versicolor, and Iris virginica). For each sample, four continuous geometric features are available:

  1. Sepal Length
  2. Sepal Width
  3. Petal Length
  4. Petal Width

Problem Simplification & Single-Feature Evaluation

The classification task is constrained to analyze the Sigmoid function and linear thresholds on a simpler scale:

  • Target Binarization: The multi-class target is converted to binary labels (y=1 for Iris virginica, y=0 for others) to establish a clear threshold.
  • Single-Feature Isolation: Instead of combining dimensions, features are evaluated one at a time (e.g., petal width or sepal length) to inspect their independent separation power before building multi-dimensional models.
from sklearn import datasets
iris=datasets.load_iris()
print(iris.DESCR)
.. _iris_dataset:

Iris plants dataset
--------------------

**Data Set Characteristics:**

:Number of Instances: 150 (50 in each of three classes)
:Number of Attributes: 4 numeric, predictive attributes and the class
:Attribute Information:
    - sepal length in cm
    - sepal width in cm
    - petal length in cm
    - petal width in cm
    - class:
            - Iris-Setosa
            - Iris-Versicolour
            - Iris-Virginica

:Summary Statistics:

============== ==== ==== ======= ===== ====================
                Min  Max   Mean    SD   Class Correlation
============== ==== ==== ======= ===== ====================
sepal length:   4.3  7.9   5.84   0.83    0.7826
sepal width:    2.0  4.4   3.05   0.43   -0.4194
petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)
petal width:    0.1  2.5   1.20   0.76    0.9565  (high!)
============== ==== ==== ======= ===== ====================

:Missing Attribute Values: None
:Class Distribution: 33.3% for each of 3 classes.
:Creator: R.A. Fisher
:Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
:Date: July, 1988

The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken
from Fisher's paper. Note that it's the same as in R, but not as in the UCI
Machine Learning Repository, which has two wrong data points.

This is perhaps the best known database to be found in the
pattern recognition literature.  Fisher's paper is a classic in the field and
is referenced frequently to this day.  (See Duda & Hart, for example.)  The
data set contains 3 classes of 50 instances each, where each class refers to a
type of iris plant.  One class is linearly separable from the other 2; the
latter are NOT linearly separable from each other.

.. dropdown:: References

  - Fisher, R.A. "The use of multiple measurements in taxonomic problems"
    Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions to
    Mathematical Statistics" (John Wiley, NY, 1950).
  - Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.
    (Q327.D83) John Wiley & Sons.  ISBN 0-471-22361-1.  See page 218.
  - Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System
    Structure and Classification Rule for Recognition in Partially Exposed
    Environments".  IEEE Transactions on Pattern Analysis and Machine
    Intelligence, Vol. PAMI-2, No. 1, 67-71.
  - Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule".  IEEE Transactions
    on Information Theory, May 1972, 431-433.
  - See also: 1988 MLC Proceedings, 54-64.  Cheeseman et al"s AUTOCLASS II
    conceptual clustering system finds 3 classes in the data.
  - Many, many more ...

Step 3: Exploratory Data Analysis & Target Inspection

Prior to model optimization, a visual and structural inspection evaluates the data distribution:

  • Unclassified Spatial Mapping: Plotting Sepal Length (sl) vs. Sepal Width (sw) using plain markers ('.k') reveals the raw data structure. This helps verify if the morphological features naturally form distinct clusters before applying any algorithmic boundaries.
  • Target Label Mapping (iris.target): Inspecting the ground-truth array to map the multi-class numerical taxonomy:
    • 0: Iris setosa
    • 1: Iris versicolor
    • 2: Iris virginica

This inspection links the visual spatial groups with their mathematical labels, establishing the baseline before data binarization.

sl = iris.data[:, 0:1]
sw = iris.data[:, 1:2]
plt.plot(sl,sw,'.k')
plt.show()

png

iris.target
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])

Step 4: Theoretical Sigmoid Function & Decision Boundary

Generating a synthetic domain from -10 to 10 to plot the standalone mathematical Sigmoid function:

\sigma(t) = \frac{1}{1 + e^{-t}}

This visualizes how the curve maps inputs to a probability between 0 and 1, establishing the inflection point \sigma(0) = 0.5 as the theoretical threshold for the decision boundary.

t= np.linspace(-10,10,100)
sig = 1/(1+np.exp(-t))
plt.plot(t,sig, '.b', label=r"$\sigma$")
plt.legend(loc='upper left', fontsize=20)
plt.show()

png

Model Training and Benchmark Evaluation

Model 1: Iris-Setosa Classifier based on petal width

Feature Selection & Setosa Target Binarization

The dataset is filtered and restructured to evaluate a new binary classification task:

  • Feature Vector (X): Slicing index [:, 3:] isolates Petal Width as the continuous predictor variable.
  • Target Binarization (y): The criteria (iris.target == 0).astype(int) shifts the positive class (y=1) exclusively to Iris setosa, mapping all other species to 0. This creates the target array seen in the output.
x = iris.data[:, 3:]
y = (iris.target == 0).astype(int)
y
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Benchmark Model Initialization and Fitting

This cell instantiates and trains the baseline classification model using Scikit-Learn:

  • LogisticRegression(solver='lbfgs', random_state=42): Instantiates the model using the Limited-memory BFGS (lbfgs) optimization solver and locks the random_state to 42 to ensure reproducible weight initialization.
  • mylr.fit(x, y): Trains the classifier on the isolated feature vector x and the binarized target labels y. This optimization process computes the optimal weight (w) and bias (b) parameters that minimize the loss function.
from sklearn.linear_model import LogisticRegression
mylr = LogisticRegression(solver='lbfgs', random_state=42)
mylr.fit(x,y)
LogisticRegression(random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
    <div class="estimator-table">
        <details>
            <summary>Parameters</summary>
            <table class="parameters-table">
              <tbody>

    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('random_state',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-random_state;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone">
        random_state
        <span class="param-doc-description"
        style="position-anchor: --doc-link-random_state;">
        random_state: int, RandomState instance, default=None<br><br>Used when ``solver`` == &#x27;sag&#x27;, &#x27;saga&#x27; or &#x27;liblinear&#x27; to shuffle the<br>data. See :term:`Glossary &lt;random_state&gt;` for details.</span>
    </a>
</td>
        <td class="value">42</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('penalty',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-penalty;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27">
        penalty
        <span class="param-doc-description"
        style="position-anchor: --doc-link-penalty;">
        penalty: {&#x27;l1&#x27;, &#x27;l2&#x27;, &#x27;elasticnet&#x27;, None}, default=&#x27;l2&#x27;<br><br>Specify the norm of the penalty:<br><br>- `None`: no penalty is added;<br>- `&#x27;l2&#x27;`: add an L2 penalty term and it is the default choice;<br>- `&#x27;l1&#x27;`: add an L1 penalty term;<br>- `&#x27;elasticnet&#x27;`: both L1 and L2 penalty terms are added.<br><br>.. warning::<br>   Some penalties may not work with some solvers. See the parameter<br>   `solver` below, to know the compatibility between the penalty and<br>   solver.<br><br>.. versionadded:: 0.19<br>   l1 penalty with SAGA solver (allowing &#x27;multinomial&#x27; + L1)<br><br>.. deprecated:: 1.8<br>   `penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>   Use `l1_ratio` and `C` instead. `l1_ratio=0` for `penalty=&#x27;l2&#x27;`,<br>   `l1_ratio=1` for `penalty=&#x27;l1&#x27;`, `l1_ratio` set to any float between 0 and 1<br>   for `penalty=&#x27;elasticnet&#x27;`, and `C=np.inf` for `penalty=None`.</span>
    </a>
</td>
        <td class="value">&#x27;deprecated&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('C',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-C;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0">
        C
        <span class="param-doc-description"
        style="position-anchor: --doc-link-C;">
        C: float, default=1.0<br><br>Inverse of regularization strength; must be a positive float.<br>Like in support vector machines, smaller values specify stronger<br>regularization. `C=np.inf` results in unpenalized logistic regression.<br>For a visual example on the effect of tuning the `C` parameter<br>with an L1 penalty, see:<br>:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span>
    </a>
</td>
        <td class="value">1.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('l1_ratio',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-l1_ratio;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0">
        l1_ratio
        <span class="param-doc-description"
        style="position-anchor: --doc-link-l1_ratio;">
        l1_ratio: float, default=0.0<br><br>The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br><br>.. warning::<br>   Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>   solvers. See the parameter `solver` below, to know the compatibility between<br>   the penalty and solver.<br><br>.. versionchanged:: 1.8<br>    Default value changed from None to 0.0.<br><br>.. deprecated:: 1.8<br>    `None` is deprecated and will be removed in version 1.10. Always use<br>    `l1_ratio` to specify the penalty type.</span>
    </a>
</td>
        <td class="value">0.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('dual',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-dual;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse">
        dual
        <span class="param-doc-description"
        style="position-anchor: --doc-link-dual;">
        dual: bool, default=False<br><br>Dual (constrained) or primal (regularized, see also<br>:ref:`this equation &lt;regularized-logistic-loss&gt;`) formulation. Dual formulation<br>is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>when n_samples &gt; n_features.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('tol',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-tol;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4">
        tol
        <span class="param-doc-description"
        style="position-anchor: --doc-link-tol;">
        tol: float, default=1e-4<br><br>Tolerance for stopping criteria.</span>
    </a>
</td>
        <td class="value">0.0001</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('fit_intercept',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-fit_intercept;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue">
        fit_intercept
        <span class="param-doc-description"
        style="position-anchor: --doc-link-fit_intercept;">
        fit_intercept: bool, default=True<br><br>Specifies if a constant (a.k.a. bias or intercept) should be<br>added to the decision function.</span>
    </a>
</td>
        <td class="value">True</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('intercept_scaling',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_scaling;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1">
        intercept_scaling
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_scaling;">
        intercept_scaling: float, default=1<br><br>Useful only when the solver `liblinear` is used<br>and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>`[x, self.intercept_scaling]`,<br>i.e. a &quot;synthetic&quot; feature with constant value equal to<br>`intercept_scaling` is appended to the instance vector.<br>The intercept becomes<br>``intercept_scaling * synthetic_feature_weight``.<br><br>.. note::<br>    The synthetic feature weight is subject to L1 or L2<br>    regularization as all other features.<br>    To lessen the effect of regularization on synthetic feature weight<br>    (and therefore on the intercept) `intercept_scaling` has to be increased.</span>
    </a>
</td>
        <td class="value">1</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('class_weight',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-class_weight;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone">
        class_weight
        <span class="param-doc-description"
        style="position-anchor: --doc-link-class_weight;">
        class_weight: dict or &#x27;balanced&#x27;, default=None<br><br>Weights associated with classes in the form ``{class_label: weight}``.<br>If not given, all classes are supposed to have weight one.<br><br>The &quot;balanced&quot; mode uses the values of y to automatically adjust<br>weights inversely proportional to class frequencies in the input data<br>as ``n_samples / (n_classes * np.bincount(y))``.<br><br>Note that these weights will be multiplied with sample_weight (passed<br>through the fit method) if sample_weight is specified.<br><br>.. versionadded:: 0.17<br>   *class_weight=&#x27;balanced&#x27;*</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('solver',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-solver;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27">
        solver
        <span class="param-doc-description"
        style="position-anchor: --doc-link-solver;">
        solver: {&#x27;lbfgs&#x27;, &#x27;liblinear&#x27;, &#x27;newton-cg&#x27;, &#x27;newton-cholesky&#x27;, &#x27;sag&#x27;, &#x27;saga&#x27;},             default=&#x27;lbfgs&#x27;<br><br>Algorithm to use in the optimization problem. Default is &#x27;lbfgs&#x27;.<br>To choose a solver, you might want to consider the following aspects:<br><br>- &#x27;lbfgs&#x27; is a good default solver because it works reasonably well for a wide<br>  class of problems.<br>- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>  &#x27;liblinear&#x27; minimize the full multinomial loss, &#x27;liblinear&#x27; will raise an<br>  error.<br>- &#x27;newton-cholesky&#x27; is a good choice for<br>  `n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>  categorical features with rare categories. Be aware that the memory usage<br>  of this solver has a quadratic dependency on `n_features * n_classes`<br>  because it explicitly computes the full Hessian matrix.<br>- For small datasets, &#x27;liblinear&#x27; is a good choice, whereas &#x27;sag&#x27;<br>  and &#x27;saga&#x27; are faster for large ones;<br>- &#x27;liblinear&#x27; can only handle binary classification by default. To apply a<br>  one-versus-rest scheme for the multiclass setting one can wrap it with the<br>  :class:`~sklearn.multiclass.OneVsRestClassifier`.<br><br>.. warning::<br>   The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>   for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>   Elastic-Net) and on (multinomial) multiclass support:<br><br>   ================= ======================== ======================<br>   solver            l1_ratio                 multinomial multiclass<br>   ================= ======================== ======================<br>   &#x27;lbfgs&#x27;           l1_ratio=0               yes<br>   &#x27;liblinear&#x27;       l1_ratio=1 or l1_ratio=0 no<br>   &#x27;newton-cg&#x27;       l1_ratio=0               yes<br>   &#x27;newton-cholesky&#x27; l1_ratio=0               yes<br>   &#x27;sag&#x27;             l1_ratio=0               yes<br>   &#x27;saga&#x27;            0&lt;=l1_ratio&lt;=1           yes<br>   ================= ======================== ======================<br><br>.. note::<br>   &#x27;sag&#x27; and &#x27;saga&#x27; fast convergence is only guaranteed on features<br>   with approximately the same scale. You can preprocess the data with<br>   a scaler from :mod:`sklearn.preprocessing`.<br><br>.. seealso::<br>   Refer to the :ref:`User Guide &lt;Logistic_regression&gt;` for more<br>   information regarding :class:`LogisticRegression` and more specifically the<br>   :ref:`Table &lt;logistic_regression_solvers&gt;`<br>   summarizing solver/penalty supports.<br><br>.. versionadded:: 0.17<br>   Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>   version 0.18.<br>.. versionadded:: 0.19<br>   SAGA solver.<br>.. versionchanged:: 0.22<br>   The default solver changed from &#x27;liblinear&#x27; to &#x27;lbfgs&#x27; in 0.22.<br>.. versionadded:: 1.2<br>   newton-cholesky solver. Multinomial support in version 1.6.</span>
    </a>
</td>
        <td class="value">&#x27;lbfgs&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('max_iter',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-max_iter;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100">
        max_iter
        <span class="param-doc-description"
        style="position-anchor: --doc-link-max_iter;">
        max_iter: int, default=100<br><br>Maximum number of iterations taken for the solvers to converge.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('verbose',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-verbose;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0">
        verbose
        <span class="param-doc-description"
        style="position-anchor: --doc-link-verbose;">
        verbose: int, default=0<br><br>For the liblinear and lbfgs solvers set verbose to any positive<br>number for verbosity.</span>
    </a>
</td>
        <td class="value">0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('warm_start',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-warm_start;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse">
        warm_start
        <span class="param-doc-description"
        style="position-anchor: --doc-link-warm_start;">
        warm_start: bool, default=False<br><br>When set to True, reuse the solution of the previous call to fit as<br>initialization, otherwise, just erase the previous solution.<br>Useless for liblinear solver. See :term:`the Glossary &lt;warm_start&gt;`.<br><br>.. versionadded:: 0.17<br>   *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('n_jobs',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_jobs;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone">
        n_jobs
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_jobs;">
        n_jobs: int, default=None<br><br>Does not have any effect.<br><br>.. deprecated:: 1.8<br>   `n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>

              </tbody>
            </table>
        </details>
    </div>

    <div class="estimator-table">
        <details>
            <summary>Fitted attributes</summary>
            <table class="parameters-table">
                <tbody>
                    <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Value</th>
                    </tr>

   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-classes_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=classes_,-ndarray%20of%20shape%20%28n_classes%2C%20%29">
        classes_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-classes_;">
        classes_: ndarray of shape (n_classes, )<br><br>A list of class labels known to the classifier.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int64](2,)</td>
       <td>[0,1]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-coef_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=coef_,-ndarray%20or%20CSR%20matrix%20of%20shape%20%281%2C%20n_features%29%20or%20%28n_classes%2C%20n_features%29">
        coef_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-coef_;">
        coef_: ndarray or CSR matrix of shape (1, n_features) or (n_classes, n_features)<br><br>Coefficients of the features in the decision function.<br><br>`coef_` is of shape (1, n_features) when the given problem is binary.<br><br>By default, it will be created as a dense array, but can be turned to<br>sparse (CSR format) through :meth:`sparsify` (which can be beneficial<br>under L1 regularization when many coefficients are zero), and back to<br>dense through :meth:`densify`.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1, 1)</td>
       <td>[[-4.53]]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_,-ndarray%20of%20shape%20%281%2C%29%20or%20%28n_classes%2C%29">
        intercept_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_;">
        intercept_: ndarray of shape (1,) or (n_classes,)<br><br>Intercept (a.k.a. bias) added to the decision function.<br><br>If `fit_intercept` is set to False, the intercept is set to zero.<br>`intercept_` is of shape (1,) when the given problem is binary.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1,)</td>
       <td>[3.42]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_features_in_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_features_in_,-int">
        n_features_in_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_features_in_;">
        n_features_in_: int<br><br>Number of features seen during :term:`fit`.<br><br>.. versionadded:: 0.24</span>
    </a>
</td>
       <td class="fitted-att-type">int</td>
       <td>1</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_iter_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_iter_,-ndarray%20of%20shape%20%281%2C%20%29">
        n_iter_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_iter_;">
        n_iter_: ndarray of shape (1, )<br><br>Actual number of iterations for all classes.<br><br>.. versionchanged:: 0.20<br><br>    In SciPy &lt;= 1.0.0 the number of lbfgs iterations may exceed<br>    ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int32](1,)</td>
       <td>[9]</td>


   </tr>

                </tbody>
            </table>
        </details>
    </div>
</div></div></div></div></div><script>/*  Authors: The scikit-learn developers

SPDX-License-Identifier: BSD-3-Clause */

function copyToClipboard(text, element) { // Get the parameter prefix from the closest toggleable content const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : ''; const fullParamName = paramPrefix ? ${paramPrefix}${text} : text;

const originalStyle = element.style;
const computedStyle = window.getComputedStyle(element);
const originalWidth = computedStyle.width;
const originalHTML = element.innerHTML.replace('Copied!', '');

navigator.clipboard.writeText(fullParamName)
    .then(() => {
        element.style.width = originalWidth;
        element.style.color = 'green';
        element.innerHTML = "Copied!";

        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    })
    .catch(err => {
        console.error('Failed to copy:', err);
        element.style.color = 'red';
        element.innerHTML = "Failed!";
        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    });
return false;

}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) { const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';

const parent = element.parentElement;
if (!parent || !parent.nextElementSibling) {
    console.warn('Expected copy-paste icon is missing from the DOM structure');
    return;
}

const paramName = element.parentElement.nextElementSibling
    .textContent.trim().split(' ')[0];
const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

element.setAttribute('title', fullParamName);

});

/**

  • Copy the list of feature names formatted as a Python list.

  • @param {HTMLElement} element - The copy button inside a .features block; its siblings

  • contain a details element and a table containing feature named.

  • @returns {boolean} Always returns false so callers can prevent the default click behavior. */ function copyFeatureNamesToClipboard(element) { var detailsElem = element.closest('.features').querySelector('details'); var wasOpen = detailsElem.open; detailsElem.open = true; var content = element.closest('.features').querySelector('tbody') .innerText.trim(); if (!wasOpen) detailsElem.open = false; const rows = content.split('\n').map(row => "${row}"); const formattedText = [\n${rows.join(',\n')},\n]; const originalHTML = element.innerHTML.replace('✔', ''); const originalStyle = element.style; const copyMark = document.createElement('span'); copyMark.innerHTML = '✔'; copyMark.style.color = 'blue'; copyMark.style.fontSize = '1em';

    navigator.clipboard.writeText(formattedText) .then(() => { element.style.display = 'none'; element.parentElement.appendChild(copyMark);

         setTimeout(() => {
             copyMark.remove();
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     })
     .catch(err => {
         console.error('Failed to copy:', err);
         element.style.color = 'orange';
         element.innerHTML = "Failed!";
         setTimeout(() => {
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     });
    

    return false; } /**

  • Adapted from Skrub

  • 403466d1d5/skrub/_reporting/_data/templates/report.js (L789)

  • @returns "light" or "dark" */ function detectTheme(element) { const body = document.querySelector('body');

    // Check VSCode theme const themeKindAttr = body.getAttribute('data-vscode-theme-kind'); const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) { const themeKind = themeKindAttr.toLowerCase(); const themeName = themeNameAttr.toLowerCase();

     if (themeKind.includes("dark") || themeName.includes("dark")) {
         return "dark";
     }
     if (themeKind.includes("light") || themeName.includes("light")) {
         return "light";
     }
    

    }

    // Check Jupyter theme if (body.getAttribute('data-jp-theme-light') === 'false') { return 'dark'; } else if (body.getAttribute('data-jp-theme-light') === 'true') { return 'light'; }

    // Guess based on a parent element's color const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color'); const match = color.match(/^rgb\s*\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\s*$/i); if (match) { const [r, g, b] = [ parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]) ];

     // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
     const luma = 0.299 * r + 0.587 * g + 0.114 * b;
    
     if (luma > 180) {
         // If the text is very bright we have a dark theme
         return 'dark';
     }
     if (luma < 75) {
         // If the text is very dark we have a light theme
         return 'light';
     }
     // Otherwise fall back to the next heuristic.
    

    }

    // Fallback to system preference return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }

function forceTheme(elementId) { const estimatorElement = document.querySelector(#${elementId}); if (estimatorElement === null) { console.error(Element with id ${elementId} not found.); } else { const theme = detectTheme(estimatorElement); estimatorElement.classList.add(theme); } }

forceTheme('sk-container-id-1');

Xnew = np.linspace(-1,3,100).reshape(-1,1)
yPred = mylr.predict_proba(Xnew)
#plt.plot(Xnew, yPred[:,0], label= 'No Iris')
plt.plot(Xnew, yPred[:,1], label= 'Yes Iris')
plt.legend()
plt.plot(x,y,'*g')
plt.show()

png

This plot visualizes the trained model's Sigmoid prediction curve over the experimental dataset samples:

  • Sample Distribution (Green Stars): Represents the real dataset. Small petal widths (0.1 - 0.6 cm) belong to Iris setosa (y=1), while larger widths (1.0 - 2.5 cm) belong to the other species (y=0).
  • Sigmoid Mapping (Blue Curve): Displays an inverted logistic curve. It demonstrates the mathematical relationship: as petal width increases, the probability of the flower being Iris setosa drops sharply from 1.0 to 0.0.
  • Decision Boundary Threshold: The curve crosses the 0.5 probability threshold at approximately 0.75 cm. This inflection point defines the exact baseline boundary separating both classifications.

Model 2: Iris-Setosa Classifier based on petal length

Feature Shift Petal Length Isolation

The model configuration is updated to evaluate a different morphological predictor:

  • Feature Vector (X): Slicing index [:, 2:3] isolates Petal Length as the independent variable.
  • Target Continuity (y): The classification objective remains focused on Iris setosa (iris.target == 0) to compare the separation power of petal length against the previous petal width baseline.
x = iris.data[:, 2:3]
y = (iris.target == 0).astype(int)

from sklearn.linear_model import LogisticRegression
mylr = LogisticRegression(solver='lbfgs', random_state=42)
mylr.fit(x,y)
LogisticRegression(random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
    <div class="estimator-table">
        <details>
            <summary>Parameters</summary>
            <table class="parameters-table">
              <tbody>

    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('random_state',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-random_state;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone">
        random_state
        <span class="param-doc-description"
        style="position-anchor: --doc-link-random_state;">
        random_state: int, RandomState instance, default=None<br><br>Used when ``solver`` == &#x27;sag&#x27;, &#x27;saga&#x27; or &#x27;liblinear&#x27; to shuffle the<br>data. See :term:`Glossary &lt;random_state&gt;` for details.</span>
    </a>
</td>
        <td class="value">42</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('penalty',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-penalty;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27">
        penalty
        <span class="param-doc-description"
        style="position-anchor: --doc-link-penalty;">
        penalty: {&#x27;l1&#x27;, &#x27;l2&#x27;, &#x27;elasticnet&#x27;, None}, default=&#x27;l2&#x27;<br><br>Specify the norm of the penalty:<br><br>- `None`: no penalty is added;<br>- `&#x27;l2&#x27;`: add an L2 penalty term and it is the default choice;<br>- `&#x27;l1&#x27;`: add an L1 penalty term;<br>- `&#x27;elasticnet&#x27;`: both L1 and L2 penalty terms are added.<br><br>.. warning::<br>   Some penalties may not work with some solvers. See the parameter<br>   `solver` below, to know the compatibility between the penalty and<br>   solver.<br><br>.. versionadded:: 0.19<br>   l1 penalty with SAGA solver (allowing &#x27;multinomial&#x27; + L1)<br><br>.. deprecated:: 1.8<br>   `penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>   Use `l1_ratio` and `C` instead. `l1_ratio=0` for `penalty=&#x27;l2&#x27;`,<br>   `l1_ratio=1` for `penalty=&#x27;l1&#x27;`, `l1_ratio` set to any float between 0 and 1<br>   for `penalty=&#x27;elasticnet&#x27;`, and `C=np.inf` for `penalty=None`.</span>
    </a>
</td>
        <td class="value">&#x27;deprecated&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('C',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-C;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0">
        C
        <span class="param-doc-description"
        style="position-anchor: --doc-link-C;">
        C: float, default=1.0<br><br>Inverse of regularization strength; must be a positive float.<br>Like in support vector machines, smaller values specify stronger<br>regularization. `C=np.inf` results in unpenalized logistic regression.<br>For a visual example on the effect of tuning the `C` parameter<br>with an L1 penalty, see:<br>:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span>
    </a>
</td>
        <td class="value">1.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('l1_ratio',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-l1_ratio;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0">
        l1_ratio
        <span class="param-doc-description"
        style="position-anchor: --doc-link-l1_ratio;">
        l1_ratio: float, default=0.0<br><br>The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br><br>.. warning::<br>   Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>   solvers. See the parameter `solver` below, to know the compatibility between<br>   the penalty and solver.<br><br>.. versionchanged:: 1.8<br>    Default value changed from None to 0.0.<br><br>.. deprecated:: 1.8<br>    `None` is deprecated and will be removed in version 1.10. Always use<br>    `l1_ratio` to specify the penalty type.</span>
    </a>
</td>
        <td class="value">0.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('dual',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-dual;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse">
        dual
        <span class="param-doc-description"
        style="position-anchor: --doc-link-dual;">
        dual: bool, default=False<br><br>Dual (constrained) or primal (regularized, see also<br>:ref:`this equation &lt;regularized-logistic-loss&gt;`) formulation. Dual formulation<br>is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>when n_samples &gt; n_features.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('tol',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-tol;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4">
        tol
        <span class="param-doc-description"
        style="position-anchor: --doc-link-tol;">
        tol: float, default=1e-4<br><br>Tolerance for stopping criteria.</span>
    </a>
</td>
        <td class="value">0.0001</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('fit_intercept',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-fit_intercept;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue">
        fit_intercept
        <span class="param-doc-description"
        style="position-anchor: --doc-link-fit_intercept;">
        fit_intercept: bool, default=True<br><br>Specifies if a constant (a.k.a. bias or intercept) should be<br>added to the decision function.</span>
    </a>
</td>
        <td class="value">True</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('intercept_scaling',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_scaling;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1">
        intercept_scaling
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_scaling;">
        intercept_scaling: float, default=1<br><br>Useful only when the solver `liblinear` is used<br>and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>`[x, self.intercept_scaling]`,<br>i.e. a &quot;synthetic&quot; feature with constant value equal to<br>`intercept_scaling` is appended to the instance vector.<br>The intercept becomes<br>``intercept_scaling * synthetic_feature_weight``.<br><br>.. note::<br>    The synthetic feature weight is subject to L1 or L2<br>    regularization as all other features.<br>    To lessen the effect of regularization on synthetic feature weight<br>    (and therefore on the intercept) `intercept_scaling` has to be increased.</span>
    </a>
</td>
        <td class="value">1</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('class_weight',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-class_weight;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone">
        class_weight
        <span class="param-doc-description"
        style="position-anchor: --doc-link-class_weight;">
        class_weight: dict or &#x27;balanced&#x27;, default=None<br><br>Weights associated with classes in the form ``{class_label: weight}``.<br>If not given, all classes are supposed to have weight one.<br><br>The &quot;balanced&quot; mode uses the values of y to automatically adjust<br>weights inversely proportional to class frequencies in the input data<br>as ``n_samples / (n_classes * np.bincount(y))``.<br><br>Note that these weights will be multiplied with sample_weight (passed<br>through the fit method) if sample_weight is specified.<br><br>.. versionadded:: 0.17<br>   *class_weight=&#x27;balanced&#x27;*</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('solver',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-solver;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27">
        solver
        <span class="param-doc-description"
        style="position-anchor: --doc-link-solver;">
        solver: {&#x27;lbfgs&#x27;, &#x27;liblinear&#x27;, &#x27;newton-cg&#x27;, &#x27;newton-cholesky&#x27;, &#x27;sag&#x27;, &#x27;saga&#x27;},             default=&#x27;lbfgs&#x27;<br><br>Algorithm to use in the optimization problem. Default is &#x27;lbfgs&#x27;.<br>To choose a solver, you might want to consider the following aspects:<br><br>- &#x27;lbfgs&#x27; is a good default solver because it works reasonably well for a wide<br>  class of problems.<br>- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>  &#x27;liblinear&#x27; minimize the full multinomial loss, &#x27;liblinear&#x27; will raise an<br>  error.<br>- &#x27;newton-cholesky&#x27; is a good choice for<br>  `n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>  categorical features with rare categories. Be aware that the memory usage<br>  of this solver has a quadratic dependency on `n_features * n_classes`<br>  because it explicitly computes the full Hessian matrix.<br>- For small datasets, &#x27;liblinear&#x27; is a good choice, whereas &#x27;sag&#x27;<br>  and &#x27;saga&#x27; are faster for large ones;<br>- &#x27;liblinear&#x27; can only handle binary classification by default. To apply a<br>  one-versus-rest scheme for the multiclass setting one can wrap it with the<br>  :class:`~sklearn.multiclass.OneVsRestClassifier`.<br><br>.. warning::<br>   The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>   for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>   Elastic-Net) and on (multinomial) multiclass support:<br><br>   ================= ======================== ======================<br>   solver            l1_ratio                 multinomial multiclass<br>   ================= ======================== ======================<br>   &#x27;lbfgs&#x27;           l1_ratio=0               yes<br>   &#x27;liblinear&#x27;       l1_ratio=1 or l1_ratio=0 no<br>   &#x27;newton-cg&#x27;       l1_ratio=0               yes<br>   &#x27;newton-cholesky&#x27; l1_ratio=0               yes<br>   &#x27;sag&#x27;             l1_ratio=0               yes<br>   &#x27;saga&#x27;            0&lt;=l1_ratio&lt;=1           yes<br>   ================= ======================== ======================<br><br>.. note::<br>   &#x27;sag&#x27; and &#x27;saga&#x27; fast convergence is only guaranteed on features<br>   with approximately the same scale. You can preprocess the data with<br>   a scaler from :mod:`sklearn.preprocessing`.<br><br>.. seealso::<br>   Refer to the :ref:`User Guide &lt;Logistic_regression&gt;` for more<br>   information regarding :class:`LogisticRegression` and more specifically the<br>   :ref:`Table &lt;logistic_regression_solvers&gt;`<br>   summarizing solver/penalty supports.<br><br>.. versionadded:: 0.17<br>   Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>   version 0.18.<br>.. versionadded:: 0.19<br>   SAGA solver.<br>.. versionchanged:: 0.22<br>   The default solver changed from &#x27;liblinear&#x27; to &#x27;lbfgs&#x27; in 0.22.<br>.. versionadded:: 1.2<br>   newton-cholesky solver. Multinomial support in version 1.6.</span>
    </a>
</td>
        <td class="value">&#x27;lbfgs&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('max_iter',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-max_iter;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100">
        max_iter
        <span class="param-doc-description"
        style="position-anchor: --doc-link-max_iter;">
        max_iter: int, default=100<br><br>Maximum number of iterations taken for the solvers to converge.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('verbose',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-verbose;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0">
        verbose
        <span class="param-doc-description"
        style="position-anchor: --doc-link-verbose;">
        verbose: int, default=0<br><br>For the liblinear and lbfgs solvers set verbose to any positive<br>number for verbosity.</span>
    </a>
</td>
        <td class="value">0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('warm_start',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-warm_start;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse">
        warm_start
        <span class="param-doc-description"
        style="position-anchor: --doc-link-warm_start;">
        warm_start: bool, default=False<br><br>When set to True, reuse the solution of the previous call to fit as<br>initialization, otherwise, just erase the previous solution.<br>Useless for liblinear solver. See :term:`the Glossary &lt;warm_start&gt;`.<br><br>.. versionadded:: 0.17<br>   *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('n_jobs',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_jobs;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone">
        n_jobs
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_jobs;">
        n_jobs: int, default=None<br><br>Does not have any effect.<br><br>.. deprecated:: 1.8<br>   `n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>

              </tbody>
            </table>
        </details>
    </div>

    <div class="estimator-table">
        <details>
            <summary>Fitted attributes</summary>
            <table class="parameters-table">
                <tbody>
                    <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Value</th>
                    </tr>

   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-classes_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=classes_,-ndarray%20of%20shape%20%28n_classes%2C%20%29">
        classes_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-classes_;">
        classes_: ndarray of shape (n_classes, )<br><br>A list of class labels known to the classifier.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int64](2,)</td>
       <td>[0,1]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-coef_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=coef_,-ndarray%20or%20CSR%20matrix%20of%20shape%20%281%2C%20n_features%29%20or%20%28n_classes%2C%20n_features%29">
        coef_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-coef_;">
        coef_: ndarray or CSR matrix of shape (1, n_features) or (n_classes, n_features)<br><br>Coefficients of the features in the decision function.<br><br>`coef_` is of shape (1, n_features) when the given problem is binary.<br><br>By default, it will be created as a dense array, but can be turned to<br>sparse (CSR format) through :meth:`sparsify` (which can be beneficial<br>under L1 regularization when many coefficients are zero), and back to<br>dense through :meth:`densify`.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1, 1)</td>
       <td>[[-2.92]]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_,-ndarray%20of%20shape%20%281%2C%29%20or%20%28n_classes%2C%29">
        intercept_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_;">
        intercept_: ndarray of shape (1,) or (n_classes,)<br><br>Intercept (a.k.a. bias) added to the decision function.<br><br>If `fit_intercept` is set to False, the intercept is set to zero.<br>`intercept_` is of shape (1,) when the given problem is binary.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1,)</td>
       <td>[7.92]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_features_in_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_features_in_,-int">
        n_features_in_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_features_in_;">
        n_features_in_: int<br><br>Number of features seen during :term:`fit`.<br><br>.. versionadded:: 0.24</span>
    </a>
</td>
       <td class="fitted-att-type">int</td>
       <td>1</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_iter_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_iter_,-ndarray%20of%20shape%20%281%2C%20%29">
        n_iter_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_iter_;">
        n_iter_: ndarray of shape (1, )<br><br>Actual number of iterations for all classes.<br><br>.. versionchanged:: 0.20<br><br>    In SciPy &lt;= 1.0.0 the number of lbfgs iterations may exceed<br>    ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int32](1,)</td>
       <td>[17]</td>


   </tr>

                </tbody>
            </table>
        </details>
    </div>
</div></div></div></div></div><script>/*  Authors: The scikit-learn developers

SPDX-License-Identifier: BSD-3-Clause */

function copyToClipboard(text, element) { // Get the parameter prefix from the closest toggleable content const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : ''; const fullParamName = paramPrefix ? ${paramPrefix}${text} : text;

const originalStyle = element.style;
const computedStyle = window.getComputedStyle(element);
const originalWidth = computedStyle.width;
const originalHTML = element.innerHTML.replace('Copied!', '');

navigator.clipboard.writeText(fullParamName)
    .then(() => {
        element.style.width = originalWidth;
        element.style.color = 'green';
        element.innerHTML = "Copied!";

        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    })
    .catch(err => {
        console.error('Failed to copy:', err);
        element.style.color = 'red';
        element.innerHTML = "Failed!";
        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    });
return false;

}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) { const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';

const parent = element.parentElement;
if (!parent || !parent.nextElementSibling) {
    console.warn('Expected copy-paste icon is missing from the DOM structure');
    return;
}

const paramName = element.parentElement.nextElementSibling
    .textContent.trim().split(' ')[0];
const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

element.setAttribute('title', fullParamName);

});

/**

  • Copy the list of feature names formatted as a Python list.

  • @param {HTMLElement} element - The copy button inside a .features block; its siblings

  • contain a details element and a table containing feature named.

  • @returns {boolean} Always returns false so callers can prevent the default click behavior. */ function copyFeatureNamesToClipboard(element) { var detailsElem = element.closest('.features').querySelector('details'); var wasOpen = detailsElem.open; detailsElem.open = true; var content = element.closest('.features').querySelector('tbody') .innerText.trim(); if (!wasOpen) detailsElem.open = false; const rows = content.split('\n').map(row => "${row}"); const formattedText = [\n${rows.join(',\n')},\n]; const originalHTML = element.innerHTML.replace('✔', ''); const originalStyle = element.style; const copyMark = document.createElement('span'); copyMark.innerHTML = '✔'; copyMark.style.color = 'blue'; copyMark.style.fontSize = '1em';

    navigator.clipboard.writeText(formattedText) .then(() => { element.style.display = 'none'; element.parentElement.appendChild(copyMark);

         setTimeout(() => {
             copyMark.remove();
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     })
     .catch(err => {
         console.error('Failed to copy:', err);
         element.style.color = 'orange';
         element.innerHTML = "Failed!";
         setTimeout(() => {
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     });
    

    return false; } /**

  • Adapted from Skrub

  • 403466d1d5/skrub/_reporting/_data/templates/report.js (L789)

  • @returns "light" or "dark" */ function detectTheme(element) { const body = document.querySelector('body');

    // Check VSCode theme const themeKindAttr = body.getAttribute('data-vscode-theme-kind'); const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) { const themeKind = themeKindAttr.toLowerCase(); const themeName = themeNameAttr.toLowerCase();

     if (themeKind.includes("dark") || themeName.includes("dark")) {
         return "dark";
     }
     if (themeKind.includes("light") || themeName.includes("light")) {
         return "light";
     }
    

    }

    // Check Jupyter theme if (body.getAttribute('data-jp-theme-light') === 'false') { return 'dark'; } else if (body.getAttribute('data-jp-theme-light') === 'true') { return 'light'; }

    // Guess based on a parent element's color const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color'); const match = color.match(/^rgb\s*\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\s*$/i); if (match) { const [r, g, b] = [ parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]) ];

     // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
     const luma = 0.299 * r + 0.587 * g + 0.114 * b;
    
     if (luma > 180) {
         // If the text is very bright we have a dark theme
         return 'dark';
     }
     if (luma < 75) {
         // If the text is very dark we have a light theme
         return 'light';
     }
     // Otherwise fall back to the next heuristic.
    

    }

    // Fallback to system preference return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }

function forceTheme(elementId) { const estimatorElement = document.querySelector(#${elementId}); if (estimatorElement === null) { console.error(Element with id ${elementId} not found.); } else { const theme = detectTheme(estimatorElement); estimatorElement.classList.add(theme); } }

forceTheme('sk-container-id-2');

Xnew = np.linspace(0,8,100).reshape(-1,1)
yPred = mylr.predict_proba(Xnew)
#plt.plot(Xnew, yPred[:,0], label= 'No Iris')
plt.plot(Xnew, yPred[:,1], label= 'Yes Iris')
plt.legend()
plt.plot(x,y,'*g')
plt.axis([1.5, 5, -0.5, 1.5])
plt.show()

png

This plot illustrates the performance of the second univariable model using Petal Length:

  • Sample Distribution: Samples with short petal lengths (1.0 - 2.0 cm) are correctly clustered as Iris setosa (y=1), while samples with larger lengths (>3.0 cm) map to y=0.
  • Sigmoid Mapping: The descending blue curve demonstrates that as petal length increases, the probability of the sample being Iris setosa drops sharply from 1.0 to 0.0.
  • Decision Boundary: The curve crosses the 0.5 probability threshold at approximately 2.5 cm, marking the exact inflection point that separates the target class from the rest of the dataset.

Model 3: Iris-Setosa Classifier based on Sepal length

Feature Shift Sepal Length Isolation

The model evaluates a third morphological predictor independently:

  • Feature Vector (X): Slicing index [:, 0:1] isolates Sepal Length as the continuous independent variable.
  • Target Continuity (y): The objective remains focused on Iris setosa (y=1) to compare the separation power of sepal dimensions against the previous petal metrics.
x = iris.data[:, 0:1]
y = (iris.target == 0).astype(int)
from sklearn.linear_model import LogisticRegression
mylr = LogisticRegression(solver='lbfgs', random_state=42)
mylr.fit(x,y)
LogisticRegression(random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
    <div class="estimator-table">
        <details>
            <summary>Parameters</summary>
            <table class="parameters-table">
              <tbody>

    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('random_state',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-random_state;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone">
        random_state
        <span class="param-doc-description"
        style="position-anchor: --doc-link-random_state;">
        random_state: int, RandomState instance, default=None<br><br>Used when ``solver`` == &#x27;sag&#x27;, &#x27;saga&#x27; or &#x27;liblinear&#x27; to shuffle the<br>data. See :term:`Glossary &lt;random_state&gt;` for details.</span>
    </a>
</td>
        <td class="value">42</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('penalty',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-penalty;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27">
        penalty
        <span class="param-doc-description"
        style="position-anchor: --doc-link-penalty;">
        penalty: {&#x27;l1&#x27;, &#x27;l2&#x27;, &#x27;elasticnet&#x27;, None}, default=&#x27;l2&#x27;<br><br>Specify the norm of the penalty:<br><br>- `None`: no penalty is added;<br>- `&#x27;l2&#x27;`: add an L2 penalty term and it is the default choice;<br>- `&#x27;l1&#x27;`: add an L1 penalty term;<br>- `&#x27;elasticnet&#x27;`: both L1 and L2 penalty terms are added.<br><br>.. warning::<br>   Some penalties may not work with some solvers. See the parameter<br>   `solver` below, to know the compatibility between the penalty and<br>   solver.<br><br>.. versionadded:: 0.19<br>   l1 penalty with SAGA solver (allowing &#x27;multinomial&#x27; + L1)<br><br>.. deprecated:: 1.8<br>   `penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>   Use `l1_ratio` and `C` instead. `l1_ratio=0` for `penalty=&#x27;l2&#x27;`,<br>   `l1_ratio=1` for `penalty=&#x27;l1&#x27;`, `l1_ratio` set to any float between 0 and 1<br>   for `penalty=&#x27;elasticnet&#x27;`, and `C=np.inf` for `penalty=None`.</span>
    </a>
</td>
        <td class="value">&#x27;deprecated&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('C',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-C;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0">
        C
        <span class="param-doc-description"
        style="position-anchor: --doc-link-C;">
        C: float, default=1.0<br><br>Inverse of regularization strength; must be a positive float.<br>Like in support vector machines, smaller values specify stronger<br>regularization. `C=np.inf` results in unpenalized logistic regression.<br>For a visual example on the effect of tuning the `C` parameter<br>with an L1 penalty, see:<br>:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span>
    </a>
</td>
        <td class="value">1.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('l1_ratio',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-l1_ratio;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0">
        l1_ratio
        <span class="param-doc-description"
        style="position-anchor: --doc-link-l1_ratio;">
        l1_ratio: float, default=0.0<br><br>The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br><br>.. warning::<br>   Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>   solvers. See the parameter `solver` below, to know the compatibility between<br>   the penalty and solver.<br><br>.. versionchanged:: 1.8<br>    Default value changed from None to 0.0.<br><br>.. deprecated:: 1.8<br>    `None` is deprecated and will be removed in version 1.10. Always use<br>    `l1_ratio` to specify the penalty type.</span>
    </a>
</td>
        <td class="value">0.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('dual',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-dual;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse">
        dual
        <span class="param-doc-description"
        style="position-anchor: --doc-link-dual;">
        dual: bool, default=False<br><br>Dual (constrained) or primal (regularized, see also<br>:ref:`this equation &lt;regularized-logistic-loss&gt;`) formulation. Dual formulation<br>is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>when n_samples &gt; n_features.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('tol',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-tol;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4">
        tol
        <span class="param-doc-description"
        style="position-anchor: --doc-link-tol;">
        tol: float, default=1e-4<br><br>Tolerance for stopping criteria.</span>
    </a>
</td>
        <td class="value">0.0001</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('fit_intercept',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-fit_intercept;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue">
        fit_intercept
        <span class="param-doc-description"
        style="position-anchor: --doc-link-fit_intercept;">
        fit_intercept: bool, default=True<br><br>Specifies if a constant (a.k.a. bias or intercept) should be<br>added to the decision function.</span>
    </a>
</td>
        <td class="value">True</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('intercept_scaling',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_scaling;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1">
        intercept_scaling
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_scaling;">
        intercept_scaling: float, default=1<br><br>Useful only when the solver `liblinear` is used<br>and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>`[x, self.intercept_scaling]`,<br>i.e. a &quot;synthetic&quot; feature with constant value equal to<br>`intercept_scaling` is appended to the instance vector.<br>The intercept becomes<br>``intercept_scaling * synthetic_feature_weight``.<br><br>.. note::<br>    The synthetic feature weight is subject to L1 or L2<br>    regularization as all other features.<br>    To lessen the effect of regularization on synthetic feature weight<br>    (and therefore on the intercept) `intercept_scaling` has to be increased.</span>
    </a>
</td>
        <td class="value">1</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('class_weight',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-class_weight;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone">
        class_weight
        <span class="param-doc-description"
        style="position-anchor: --doc-link-class_weight;">
        class_weight: dict or &#x27;balanced&#x27;, default=None<br><br>Weights associated with classes in the form ``{class_label: weight}``.<br>If not given, all classes are supposed to have weight one.<br><br>The &quot;balanced&quot; mode uses the values of y to automatically adjust<br>weights inversely proportional to class frequencies in the input data<br>as ``n_samples / (n_classes * np.bincount(y))``.<br><br>Note that these weights will be multiplied with sample_weight (passed<br>through the fit method) if sample_weight is specified.<br><br>.. versionadded:: 0.17<br>   *class_weight=&#x27;balanced&#x27;*</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('solver',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-solver;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27">
        solver
        <span class="param-doc-description"
        style="position-anchor: --doc-link-solver;">
        solver: {&#x27;lbfgs&#x27;, &#x27;liblinear&#x27;, &#x27;newton-cg&#x27;, &#x27;newton-cholesky&#x27;, &#x27;sag&#x27;, &#x27;saga&#x27;},             default=&#x27;lbfgs&#x27;<br><br>Algorithm to use in the optimization problem. Default is &#x27;lbfgs&#x27;.<br>To choose a solver, you might want to consider the following aspects:<br><br>- &#x27;lbfgs&#x27; is a good default solver because it works reasonably well for a wide<br>  class of problems.<br>- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>  &#x27;liblinear&#x27; minimize the full multinomial loss, &#x27;liblinear&#x27; will raise an<br>  error.<br>- &#x27;newton-cholesky&#x27; is a good choice for<br>  `n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>  categorical features with rare categories. Be aware that the memory usage<br>  of this solver has a quadratic dependency on `n_features * n_classes`<br>  because it explicitly computes the full Hessian matrix.<br>- For small datasets, &#x27;liblinear&#x27; is a good choice, whereas &#x27;sag&#x27;<br>  and &#x27;saga&#x27; are faster for large ones;<br>- &#x27;liblinear&#x27; can only handle binary classification by default. To apply a<br>  one-versus-rest scheme for the multiclass setting one can wrap it with the<br>  :class:`~sklearn.multiclass.OneVsRestClassifier`.<br><br>.. warning::<br>   The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>   for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>   Elastic-Net) and on (multinomial) multiclass support:<br><br>   ================= ======================== ======================<br>   solver            l1_ratio                 multinomial multiclass<br>   ================= ======================== ======================<br>   &#x27;lbfgs&#x27;           l1_ratio=0               yes<br>   &#x27;liblinear&#x27;       l1_ratio=1 or l1_ratio=0 no<br>   &#x27;newton-cg&#x27;       l1_ratio=0               yes<br>   &#x27;newton-cholesky&#x27; l1_ratio=0               yes<br>   &#x27;sag&#x27;             l1_ratio=0               yes<br>   &#x27;saga&#x27;            0&lt;=l1_ratio&lt;=1           yes<br>   ================= ======================== ======================<br><br>.. note::<br>   &#x27;sag&#x27; and &#x27;saga&#x27; fast convergence is only guaranteed on features<br>   with approximately the same scale. You can preprocess the data with<br>   a scaler from :mod:`sklearn.preprocessing`.<br><br>.. seealso::<br>   Refer to the :ref:`User Guide &lt;Logistic_regression&gt;` for more<br>   information regarding :class:`LogisticRegression` and more specifically the<br>   :ref:`Table &lt;logistic_regression_solvers&gt;`<br>   summarizing solver/penalty supports.<br><br>.. versionadded:: 0.17<br>   Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>   version 0.18.<br>.. versionadded:: 0.19<br>   SAGA solver.<br>.. versionchanged:: 0.22<br>   The default solver changed from &#x27;liblinear&#x27; to &#x27;lbfgs&#x27; in 0.22.<br>.. versionadded:: 1.2<br>   newton-cholesky solver. Multinomial support in version 1.6.</span>
    </a>
</td>
        <td class="value">&#x27;lbfgs&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('max_iter',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-max_iter;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100">
        max_iter
        <span class="param-doc-description"
        style="position-anchor: --doc-link-max_iter;">
        max_iter: int, default=100<br><br>Maximum number of iterations taken for the solvers to converge.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('verbose',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-verbose;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0">
        verbose
        <span class="param-doc-description"
        style="position-anchor: --doc-link-verbose;">
        verbose: int, default=0<br><br>For the liblinear and lbfgs solvers set verbose to any positive<br>number for verbosity.</span>
    </a>
</td>
        <td class="value">0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('warm_start',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-warm_start;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse">
        warm_start
        <span class="param-doc-description"
        style="position-anchor: --doc-link-warm_start;">
        warm_start: bool, default=False<br><br>When set to True, reuse the solution of the previous call to fit as<br>initialization, otherwise, just erase the previous solution.<br>Useless for liblinear solver. See :term:`the Glossary &lt;warm_start&gt;`.<br><br>.. versionadded:: 0.17<br>   *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('n_jobs',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_jobs;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone">
        n_jobs
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_jobs;">
        n_jobs: int, default=None<br><br>Does not have any effect.<br><br>.. deprecated:: 1.8<br>   `n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>

              </tbody>
            </table>
        </details>
    </div>

    <div class="estimator-table">
        <details>
            <summary>Fitted attributes</summary>
            <table class="parameters-table">
                <tbody>
                    <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Value</th>
                    </tr>

   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-classes_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=classes_,-ndarray%20of%20shape%20%28n_classes%2C%20%29">
        classes_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-classes_;">
        classes_: ndarray of shape (n_classes, )<br><br>A list of class labels known to the classifier.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int64](2,)</td>
       <td>[0,1]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-coef_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=coef_,-ndarray%20or%20CSR%20matrix%20of%20shape%20%281%2C%20n_features%29%20or%20%28n_classes%2C%20n_features%29">
        coef_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-coef_;">
        coef_: ndarray or CSR matrix of shape (1, n_features) or (n_classes, n_features)<br><br>Coefficients of the features in the decision function.<br><br>`coef_` is of shape (1, n_features) when the given problem is binary.<br><br>By default, it will be created as a dense array, but can be turned to<br>sparse (CSR format) through :meth:`sparsify` (which can be beneficial<br>under L1 regularization when many coefficients are zero), and back to<br>dense through :meth:`densify`.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1, 1)</td>
       <td>[[-3.46]]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_,-ndarray%20of%20shape%20%281%2C%29%20or%20%28n_classes%2C%29">
        intercept_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_;">
        intercept_: ndarray of shape (1,) or (n_classes,)<br><br>Intercept (a.k.a. bias) added to the decision function.<br><br>If `fit_intercept` is set to False, the intercept is set to zero.<br>`intercept_` is of shape (1,) when the given problem is binary.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1,)</td>
       <td>[18.55]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_features_in_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_features_in_,-int">
        n_features_in_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_features_in_;">
        n_features_in_: int<br><br>Number of features seen during :term:`fit`.<br><br>.. versionadded:: 0.24</span>
    </a>
</td>
       <td class="fitted-att-type">int</td>
       <td>1</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_iter_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_iter_,-ndarray%20of%20shape%20%281%2C%20%29">
        n_iter_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_iter_;">
        n_iter_: ndarray of shape (1, )<br><br>Actual number of iterations for all classes.<br><br>.. versionchanged:: 0.20<br><br>    In SciPy &lt;= 1.0.0 the number of lbfgs iterations may exceed<br>    ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int32](1,)</td>
       <td>[17]</td>


   </tr>

                </tbody>
            </table>
        </details>
    </div>
</div></div></div></div></div><script>/*  Authors: The scikit-learn developers

SPDX-License-Identifier: BSD-3-Clause */

function copyToClipboard(text, element) { // Get the parameter prefix from the closest toggleable content const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : ''; const fullParamName = paramPrefix ? ${paramPrefix}${text} : text;

const originalStyle = element.style;
const computedStyle = window.getComputedStyle(element);
const originalWidth = computedStyle.width;
const originalHTML = element.innerHTML.replace('Copied!', '');

navigator.clipboard.writeText(fullParamName)
    .then(() => {
        element.style.width = originalWidth;
        element.style.color = 'green';
        element.innerHTML = "Copied!";

        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    })
    .catch(err => {
        console.error('Failed to copy:', err);
        element.style.color = 'red';
        element.innerHTML = "Failed!";
        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    });
return false;

}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) { const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';

const parent = element.parentElement;
if (!parent || !parent.nextElementSibling) {
    console.warn('Expected copy-paste icon is missing from the DOM structure');
    return;
}

const paramName = element.parentElement.nextElementSibling
    .textContent.trim().split(' ')[0];
const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

element.setAttribute('title', fullParamName);

});

/**

  • Copy the list of feature names formatted as a Python list.

  • @param {HTMLElement} element - The copy button inside a .features block; its siblings

  • contain a details element and a table containing feature named.

  • @returns {boolean} Always returns false so callers can prevent the default click behavior. */ function copyFeatureNamesToClipboard(element) { var detailsElem = element.closest('.features').querySelector('details'); var wasOpen = detailsElem.open; detailsElem.open = true; var content = element.closest('.features').querySelector('tbody') .innerText.trim(); if (!wasOpen) detailsElem.open = false; const rows = content.split('\n').map(row => "${row}"); const formattedText = [\n${rows.join(',\n')},\n]; const originalHTML = element.innerHTML.replace('✔', ''); const originalStyle = element.style; const copyMark = document.createElement('span'); copyMark.innerHTML = '✔'; copyMark.style.color = 'blue'; copyMark.style.fontSize = '1em';

    navigator.clipboard.writeText(formattedText) .then(() => { element.style.display = 'none'; element.parentElement.appendChild(copyMark);

         setTimeout(() => {
             copyMark.remove();
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     })
     .catch(err => {
         console.error('Failed to copy:', err);
         element.style.color = 'orange';
         element.innerHTML = "Failed!";
         setTimeout(() => {
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     });
    

    return false; } /**

  • Adapted from Skrub

  • 403466d1d5/skrub/_reporting/_data/templates/report.js (L789)

  • @returns "light" or "dark" */ function detectTheme(element) { const body = document.querySelector('body');

    // Check VSCode theme const themeKindAttr = body.getAttribute('data-vscode-theme-kind'); const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) { const themeKind = themeKindAttr.toLowerCase(); const themeName = themeNameAttr.toLowerCase();

     if (themeKind.includes("dark") || themeName.includes("dark")) {
         return "dark";
     }
     if (themeKind.includes("light") || themeName.includes("light")) {
         return "light";
     }
    

    }

    // Check Jupyter theme if (body.getAttribute('data-jp-theme-light') === 'false') { return 'dark'; } else if (body.getAttribute('data-jp-theme-light') === 'true') { return 'light'; }

    // Guess based on a parent element's color const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color'); const match = color.match(/^rgb\s*\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\s*$/i); if (match) { const [r, g, b] = [ parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]) ];

     // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
     const luma = 0.299 * r + 0.587 * g + 0.114 * b;
    
     if (luma > 180) {
         // If the text is very bright we have a dark theme
         return 'dark';
     }
     if (luma < 75) {
         // If the text is very dark we have a light theme
         return 'light';
     }
     // Otherwise fall back to the next heuristic.
    

    }

    // Fallback to system preference return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }

function forceTheme(elementId) { const estimatorElement = document.querySelector(#${elementId}); if (estimatorElement === null) { console.error(Element with id ${elementId} not found.); } else { const theme = detectTheme(estimatorElement); estimatorElement.classList.add(theme); } }

forceTheme('sk-container-id-3');

Xnew = np.linspace(0,8,100).reshape(-1,1)
yPred = mylr.predict_proba(Xnew)
#plt.plot(Xnew, yPred[:,0], label= 'No Iris')
plt.plot(Xnew, yPred[:,1], label= 'Yes Iris')
plt.legend()
plt.plot(x,y,'*g')
plt.axis([3.5, 7, -0.1, 1.1])
plt.show()

png

This plot displays the performance of the third univariable model using Sepal Length:

  • Sample Distribution: Samples representing Iris setosa (y=1) are concentrated at shorter lengths, but show a much higher spatial overlap with non-setosa samples (y=0) compared to the previous petal features.
  • Sigmoid Mapping: The descending curve shows the probability dropping as sepal length increases. Due to this significant data overlap, the slope is less steep, indicating a more gradual and less aggressive probabilistic transition.
  • Decision Boundary: The inflection point at \sigma = 0.5 establishes the final threshold. This boundary carries more classification uncertainty because sepal dimensions are naturally less distinct between these species.

Model 4: Multiple features classifier

Multi-Class Spatial Mapping (Sepal Features)

This cell upgrades the initial exploratory plot by adding the ground-truth class labels to the 2D sepal feature space:

  • Feature Interaction: Maps Sepal Length (sl) against Sepal Width (sw) simultaneously to analyze their combined distribution.
  • Class Color-Coding: Differentiates the three original species using distinct markers: Green for Setosa, Red for Versicolor, and Blue for Virginica.
  • Visual Separability Analysis: Allows immediate observation of the data structure, showing that while Setosa forms a perfectly isolated cluster, Versicolor and Virginica exhibit significant spatial overlap, justifying the need for optimization models.
import matplotlib.pyplot as plt
sl = iris.data[:,0:1]
sw = iris.data[:,1:2]
tg = iris.target
plt.plot(sl[tg==0,0], sw[tg==0,0],'.g' ,label='Set')
plt.plot(sl[tg==1,0], sw[tg==1,0],'.r', label='Ver')
plt.plot(sl[tg==2,0], sw[tg==2,0],'.b', label='Vir')
plt.legend()
plt.show()

png

Bivariate Model Training for Iris Virginica

This cell configures and trains a multi-feature logistic regression model utilizing tuned optimization parameters:

  • Bivariate Data Selection: * Features (X): Slices index [:, 0:2] to combine Sepal Length and Sepal Width into a two-dimensional feature space.
    • Target (y): Shifts the positive class focus exclusively to Iris virginica (iris.target == 2).
  • Hyperparameter Tuning (mylrvir):
    • solver='newton-cg': Uses the Newton-Conjugate Gradient method to compute accurate optimization paths.
    • C=100 & tol=1e-5: Applies high cost (low regularization) to allow a tighter fit to the data, paired with a strict tolerance for precise convergence.
  • mylrvir.fit(X, y): Trains the system to find the optimal weight vector w = [w_1, w_2] and bias (b), establishing the multi-variable benchmark line.
X = iris.data[:,0:2]
y = (iris.target==2).astype(int)
mylrvir = LogisticRegression(
    random_state=22,
    tol=1e-5,
    C=100,
    max_iter=100,
    solver='newton-cg'
)
mylrvir.fit(X,y)
LogisticRegression(C=100, random_state=22, solver='newton-cg', tol=1e-05)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
    <div class="estimator-table">
        <details>
            <summary>Parameters</summary>
            <table class="parameters-table">
              <tbody>

    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('C',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-C;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0">
        C
        <span class="param-doc-description"
        style="position-anchor: --doc-link-C;">
        C: float, default=1.0<br><br>Inverse of regularization strength; must be a positive float.<br>Like in support vector machines, smaller values specify stronger<br>regularization. `C=np.inf` results in unpenalized logistic regression.<br>For a visual example on the effect of tuning the `C` parameter<br>with an L1 penalty, see:<br>:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('tol',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-tol;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4">
        tol
        <span class="param-doc-description"
        style="position-anchor: --doc-link-tol;">
        tol: float, default=1e-4<br><br>Tolerance for stopping criteria.</span>
    </a>
</td>
        <td class="value">1e-05</td>
    </tr>


    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('random_state',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-random_state;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone">
        random_state
        <span class="param-doc-description"
        style="position-anchor: --doc-link-random_state;">
        random_state: int, RandomState instance, default=None<br><br>Used when ``solver`` == &#x27;sag&#x27;, &#x27;saga&#x27; or &#x27;liblinear&#x27; to shuffle the<br>data. See :term:`Glossary &lt;random_state&gt;` for details.</span>
    </a>
</td>
        <td class="value">22</td>
    </tr>


    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('solver',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-solver;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27">
        solver
        <span class="param-doc-description"
        style="position-anchor: --doc-link-solver;">
        solver: {&#x27;lbfgs&#x27;, &#x27;liblinear&#x27;, &#x27;newton-cg&#x27;, &#x27;newton-cholesky&#x27;, &#x27;sag&#x27;, &#x27;saga&#x27;},             default=&#x27;lbfgs&#x27;<br><br>Algorithm to use in the optimization problem. Default is &#x27;lbfgs&#x27;.<br>To choose a solver, you might want to consider the following aspects:<br><br>- &#x27;lbfgs&#x27; is a good default solver because it works reasonably well for a wide<br>  class of problems.<br>- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>  &#x27;liblinear&#x27; minimize the full multinomial loss, &#x27;liblinear&#x27; will raise an<br>  error.<br>- &#x27;newton-cholesky&#x27; is a good choice for<br>  `n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>  categorical features with rare categories. Be aware that the memory usage<br>  of this solver has a quadratic dependency on `n_features * n_classes`<br>  because it explicitly computes the full Hessian matrix.<br>- For small datasets, &#x27;liblinear&#x27; is a good choice, whereas &#x27;sag&#x27;<br>  and &#x27;saga&#x27; are faster for large ones;<br>- &#x27;liblinear&#x27; can only handle binary classification by default. To apply a<br>  one-versus-rest scheme for the multiclass setting one can wrap it with the<br>  :class:`~sklearn.multiclass.OneVsRestClassifier`.<br><br>.. warning::<br>   The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>   for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>   Elastic-Net) and on (multinomial) multiclass support:<br><br>   ================= ======================== ======================<br>   solver            l1_ratio                 multinomial multiclass<br>   ================= ======================== ======================<br>   &#x27;lbfgs&#x27;           l1_ratio=0               yes<br>   &#x27;liblinear&#x27;       l1_ratio=1 or l1_ratio=0 no<br>   &#x27;newton-cg&#x27;       l1_ratio=0               yes<br>   &#x27;newton-cholesky&#x27; l1_ratio=0               yes<br>   &#x27;sag&#x27;             l1_ratio=0               yes<br>   &#x27;saga&#x27;            0&lt;=l1_ratio&lt;=1           yes<br>   ================= ======================== ======================<br><br>.. note::<br>   &#x27;sag&#x27; and &#x27;saga&#x27; fast convergence is only guaranteed on features<br>   with approximately the same scale. You can preprocess the data with<br>   a scaler from :mod:`sklearn.preprocessing`.<br><br>.. seealso::<br>   Refer to the :ref:`User Guide &lt;Logistic_regression&gt;` for more<br>   information regarding :class:`LogisticRegression` and more specifically the<br>   :ref:`Table &lt;logistic_regression_solvers&gt;`<br>   summarizing solver/penalty supports.<br><br>.. versionadded:: 0.17<br>   Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>   version 0.18.<br>.. versionadded:: 0.19<br>   SAGA solver.<br>.. versionchanged:: 0.22<br>   The default solver changed from &#x27;liblinear&#x27; to &#x27;lbfgs&#x27; in 0.22.<br>.. versionadded:: 1.2<br>   newton-cholesky solver. Multinomial support in version 1.6.</span>
    </a>
</td>
        <td class="value">&#x27;newton-cg&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('penalty',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-penalty;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27">
        penalty
        <span class="param-doc-description"
        style="position-anchor: --doc-link-penalty;">
        penalty: {&#x27;l1&#x27;, &#x27;l2&#x27;, &#x27;elasticnet&#x27;, None}, default=&#x27;l2&#x27;<br><br>Specify the norm of the penalty:<br><br>- `None`: no penalty is added;<br>- `&#x27;l2&#x27;`: add an L2 penalty term and it is the default choice;<br>- `&#x27;l1&#x27;`: add an L1 penalty term;<br>- `&#x27;elasticnet&#x27;`: both L1 and L2 penalty terms are added.<br><br>.. warning::<br>   Some penalties may not work with some solvers. See the parameter<br>   `solver` below, to know the compatibility between the penalty and<br>   solver.<br><br>.. versionadded:: 0.19<br>   l1 penalty with SAGA solver (allowing &#x27;multinomial&#x27; + L1)<br><br>.. deprecated:: 1.8<br>   `penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>   Use `l1_ratio` and `C` instead. `l1_ratio=0` for `penalty=&#x27;l2&#x27;`,<br>   `l1_ratio=1` for `penalty=&#x27;l1&#x27;`, `l1_ratio` set to any float between 0 and 1<br>   for `penalty=&#x27;elasticnet&#x27;`, and `C=np.inf` for `penalty=None`.</span>
    </a>
</td>
        <td class="value">&#x27;deprecated&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('l1_ratio',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-l1_ratio;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0">
        l1_ratio
        <span class="param-doc-description"
        style="position-anchor: --doc-link-l1_ratio;">
        l1_ratio: float, default=0.0<br><br>The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br><br>.. warning::<br>   Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>   solvers. See the parameter `solver` below, to know the compatibility between<br>   the penalty and solver.<br><br>.. versionchanged:: 1.8<br>    Default value changed from None to 0.0.<br><br>.. deprecated:: 1.8<br>    `None` is deprecated and will be removed in version 1.10. Always use<br>    `l1_ratio` to specify the penalty type.</span>
    </a>
</td>
        <td class="value">0.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('dual',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-dual;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse">
        dual
        <span class="param-doc-description"
        style="position-anchor: --doc-link-dual;">
        dual: bool, default=False<br><br>Dual (constrained) or primal (regularized, see also<br>:ref:`this equation &lt;regularized-logistic-loss&gt;`) formulation. Dual formulation<br>is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>when n_samples &gt; n_features.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('fit_intercept',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-fit_intercept;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue">
        fit_intercept
        <span class="param-doc-description"
        style="position-anchor: --doc-link-fit_intercept;">
        fit_intercept: bool, default=True<br><br>Specifies if a constant (a.k.a. bias or intercept) should be<br>added to the decision function.</span>
    </a>
</td>
        <td class="value">True</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('intercept_scaling',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_scaling;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1">
        intercept_scaling
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_scaling;">
        intercept_scaling: float, default=1<br><br>Useful only when the solver `liblinear` is used<br>and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>`[x, self.intercept_scaling]`,<br>i.e. a &quot;synthetic&quot; feature with constant value equal to<br>`intercept_scaling` is appended to the instance vector.<br>The intercept becomes<br>``intercept_scaling * synthetic_feature_weight``.<br><br>.. note::<br>    The synthetic feature weight is subject to L1 or L2<br>    regularization as all other features.<br>    To lessen the effect of regularization on synthetic feature weight<br>    (and therefore on the intercept) `intercept_scaling` has to be increased.</span>
    </a>
</td>
        <td class="value">1</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('class_weight',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-class_weight;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone">
        class_weight
        <span class="param-doc-description"
        style="position-anchor: --doc-link-class_weight;">
        class_weight: dict or &#x27;balanced&#x27;, default=None<br><br>Weights associated with classes in the form ``{class_label: weight}``.<br>If not given, all classes are supposed to have weight one.<br><br>The &quot;balanced&quot; mode uses the values of y to automatically adjust<br>weights inversely proportional to class frequencies in the input data<br>as ``n_samples / (n_classes * np.bincount(y))``.<br><br>Note that these weights will be multiplied with sample_weight (passed<br>through the fit method) if sample_weight is specified.<br><br>.. versionadded:: 0.17<br>   *class_weight=&#x27;balanced&#x27;*</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('max_iter',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-max_iter;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100">
        max_iter
        <span class="param-doc-description"
        style="position-anchor: --doc-link-max_iter;">
        max_iter: int, default=100<br><br>Maximum number of iterations taken for the solvers to converge.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('verbose',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-verbose;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0">
        verbose
        <span class="param-doc-description"
        style="position-anchor: --doc-link-verbose;">
        verbose: int, default=0<br><br>For the liblinear and lbfgs solvers set verbose to any positive<br>number for verbosity.</span>
    </a>
</td>
        <td class="value">0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('warm_start',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-warm_start;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse">
        warm_start
        <span class="param-doc-description"
        style="position-anchor: --doc-link-warm_start;">
        warm_start: bool, default=False<br><br>When set to True, reuse the solution of the previous call to fit as<br>initialization, otherwise, just erase the previous solution.<br>Useless for liblinear solver. See :term:`the Glossary &lt;warm_start&gt;`.<br><br>.. versionadded:: 0.17<br>   *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('n_jobs',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_jobs;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone">
        n_jobs
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_jobs;">
        n_jobs: int, default=None<br><br>Does not have any effect.<br><br>.. deprecated:: 1.8<br>   `n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>

              </tbody>
            </table>
        </details>
    </div>

    <div class="estimator-table">
        <details>
            <summary>Fitted attributes</summary>
            <table class="parameters-table">
                <tbody>
                    <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Value</th>
                    </tr>

   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-classes_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=classes_,-ndarray%20of%20shape%20%28n_classes%2C%20%29">
        classes_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-classes_;">
        classes_: ndarray of shape (n_classes, )<br><br>A list of class labels known to the classifier.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int64](2,)</td>
       <td>[0,1]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-coef_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=coef_,-ndarray%20or%20CSR%20matrix%20of%20shape%20%281%2C%20n_features%29%20or%20%28n_classes%2C%20n_features%29">
        coef_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-coef_;">
        coef_: ndarray or CSR matrix of shape (1, n_features) or (n_classes, n_features)<br><br>Coefficients of the features in the decision function.<br><br>`coef_` is of shape (1, n_features) when the given problem is binary.<br><br>By default, it will be created as a dense array, but can be turned to<br>sparse (CSR format) through :meth:`sparsify` (which can be beneficial<br>under L1 regularization when many coefficients are zero), and back to<br>dense through :meth:`densify`.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1, 2)</td>
       <td>[[ 2.6 ,-0.74]]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_,-ndarray%20of%20shape%20%281%2C%29%20or%20%28n_classes%2C%29">
        intercept_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_;">
        intercept_: ndarray of shape (1,) or (n_classes,)<br><br>Intercept (a.k.a. bias) added to the decision function.<br><br>If `fit_intercept` is set to False, the intercept is set to zero.<br>`intercept_` is of shape (1,) when the given problem is binary.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](1,)</td>
       <td>[-14.16]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_features_in_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_features_in_,-int">
        n_features_in_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_features_in_;">
        n_features_in_: int<br><br>Number of features seen during :term:`fit`.<br><br>.. versionadded:: 0.24</span>
    </a>
</td>
       <td class="fitted-att-type">int</td>
       <td>2</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_iter_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_iter_,-ndarray%20of%20shape%20%281%2C%20%29">
        n_iter_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_iter_;">
        n_iter_: ndarray of shape (1, )<br><br>Actual number of iterations for all classes.<br><br>.. versionchanged:: 0.20<br><br>    In SciPy &lt;= 1.0.0 the number of lbfgs iterations may exceed<br>    ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int32](1,)</td>
       <td>[11]</td>


   </tr>

                </tbody>
            </table>
        </details>
    </div>
</div></div></div></div></div><script>/*  Authors: The scikit-learn developers

SPDX-License-Identifier: BSD-3-Clause */

function copyToClipboard(text, element) { // Get the parameter prefix from the closest toggleable content const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : ''; const fullParamName = paramPrefix ? ${paramPrefix}${text} : text;

const originalStyle = element.style;
const computedStyle = window.getComputedStyle(element);
const originalWidth = computedStyle.width;
const originalHTML = element.innerHTML.replace('Copied!', '');

navigator.clipboard.writeText(fullParamName)
    .then(() => {
        element.style.width = originalWidth;
        element.style.color = 'green';
        element.innerHTML = "Copied!";

        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    })
    .catch(err => {
        console.error('Failed to copy:', err);
        element.style.color = 'red';
        element.innerHTML = "Failed!";
        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    });
return false;

}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) { const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';

const parent = element.parentElement;
if (!parent || !parent.nextElementSibling) {
    console.warn('Expected copy-paste icon is missing from the DOM structure');
    return;
}

const paramName = element.parentElement.nextElementSibling
    .textContent.trim().split(' ')[0];
const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

element.setAttribute('title', fullParamName);

});

/**

  • Copy the list of feature names formatted as a Python list.

  • @param {HTMLElement} element - The copy button inside a .features block; its siblings

  • contain a details element and a table containing feature named.

  • @returns {boolean} Always returns false so callers can prevent the default click behavior. */ function copyFeatureNamesToClipboard(element) { var detailsElem = element.closest('.features').querySelector('details'); var wasOpen = detailsElem.open; detailsElem.open = true; var content = element.closest('.features').querySelector('tbody') .innerText.trim(); if (!wasOpen) detailsElem.open = false; const rows = content.split('\n').map(row => "${row}"); const formattedText = [\n${rows.join(',\n')},\n]; const originalHTML = element.innerHTML.replace('✔', ''); const originalStyle = element.style; const copyMark = document.createElement('span'); copyMark.innerHTML = '✔'; copyMark.style.color = 'blue'; copyMark.style.fontSize = '1em';

    navigator.clipboard.writeText(formattedText) .then(() => { element.style.display = 'none'; element.parentElement.appendChild(copyMark);

         setTimeout(() => {
             copyMark.remove();
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     })
     .catch(err => {
         console.error('Failed to copy:', err);
         element.style.color = 'orange';
         element.innerHTML = "Failed!";
         setTimeout(() => {
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     });
    

    return false; } /**

  • Adapted from Skrub

  • 403466d1d5/skrub/_reporting/_data/templates/report.js (L789)

  • @returns "light" or "dark" */ function detectTheme(element) { const body = document.querySelector('body');

    // Check VSCode theme const themeKindAttr = body.getAttribute('data-vscode-theme-kind'); const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) { const themeKind = themeKindAttr.toLowerCase(); const themeName = themeNameAttr.toLowerCase();

     if (themeKind.includes("dark") || themeName.includes("dark")) {
         return "dark";
     }
     if (themeKind.includes("light") || themeName.includes("light")) {
         return "light";
     }
    

    }

    // Check Jupyter theme if (body.getAttribute('data-jp-theme-light') === 'false') { return 'dark'; } else if (body.getAttribute('data-jp-theme-light') === 'true') { return 'light'; }

    // Guess based on a parent element's color const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color'); const match = color.match(/^rgb\s*\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\s*$/i); if (match) { const [r, g, b] = [ parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]) ];

     // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
     const luma = 0.299 * r + 0.587 * g + 0.114 * b;
    
     if (luma > 180) {
         // If the text is very bright we have a dark theme
         return 'dark';
     }
     if (luma < 75) {
         // If the text is very dark we have a light theme
         return 'light';
     }
     // Otherwise fall back to the next heuristic.
    

    }

    // Fallback to system preference return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }

function forceTheme(elementId) { const estimatorElement = document.querySelector(#${elementId}); if (estimatorElement === null) { console.error(Element with id ${elementId} not found.); } else { const theme = detectTheme(estimatorElement); estimatorElement.classList.add(theme); } }

forceTheme('sk-container-id-4');

Coordinate Grid Generation & Probability Mapping

This block builds the mathematical testing grid used to map out the complete probability landscape:

  • np.meshgrid: Generates a dense 100 \times 100 coordinate grid across the sepal feature space (Length: 38 cm, Width: 06 cm).
  • Xnew (np.c_): Flattens and couples the grid matrices into a matrix of 10,000 discrete 2D spatial coordinates.
  • predict_proba(Xnew): Evaluates the trained model across the entire grid, computing the continuous probabilities needed to render the decision contours and 3D surfaces.
x0, x1 = np.meshgrid(
    np.linspace(3,8,100).reshape(-1,1),
    np.linspace(0,6,100).reshape(-1,1)
)
Xnew = np.c_[x0.ravel(), x1.ravel()]
yPred = mylrvir.predict_proba(Xnew)
plt.figure(figsize=(10,4))
plt.plot(X[y==0,0], X[y==0,1],'bs',label='No Virg')
plt.plot(X[y==1,0], X[y==1,1],'g^',label='Virginica')
zz=yPred[:,1].reshape(x0.shape)
contour=plt.contour(x0,x1,zz)
plt.clabel(contour, inline=1,fontsize=15)
plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")
plt.legend()
plt.show()

png

This plot visualizes the continuous probability space generated by the trained bivariate model:

  • Sample Distribution: Blue squares represent non-virginica samples (y=0), and green triangles represent Iris virginica (y=1) mapped across Sepal Length and Sepal Width.
  • Probability Contours (plt.contour): The labeled contour lines map specific probability thresholds. They show how the model's prediction confidence transitions across the 2D space.
  • Decision Boundary: The contour line labeled 0.5 marks the exact geometric threshold. Any sample falling past this line is classified as Iris virginica, capturing the spatial trade-off between both sepal measurements.
fig, ax =plt.subplots(subplot_kw={"projection": "3d"})
surf = ax.plot_surface(x0,x1,zz, cmap='jet')
ax.scatter(iris.data[:,0:1], iris.data[:,1:2], y, 'or')
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x2a3c5a946e0>

png

This cell projects the bivariate logistic regression model into a 3D coordinate space to visualize the complete probability landscape:

  • Axis Dimensions: The horizontal axes represent Sepal Length (x_1) and Sepal Width (x_2), while the vertical axis (Z) tracks the continuous model probability \sigma(z) \in [0, 1].
  • Probability Surface (plot_surface): The Sigmoid function is rendered as a 3D sheet using the jet colormap. It displays the non-linear S-curve transition dynamically stretched across the two-dimensional feature plane.
  • True Labels Spatial Scatter (ax.scatter): The red markers plot the actual samples at their exact spatial coordinates and true binary height (z = 1 for Iris virginica, z = 0 for others). This highlights how the optimized surface splits the space to fit the data points.

Modelo 5: Multiple features and muticlass classifier

Multi-Feature & Multi-Class Model Training

This cell configures and trains the final baseline model to handle all three species simultaneously within a two-dimensional feature space:

  • Bivariate Inputs (X): Slices index [:, 0:2] to utilize both Sepal Length and Sepal Width as the predictor variables.
  • Multi-Class Target (y): Retains the original multi-class target labels (0, 1, 2) without applying binarization, expanding the task from a single boundary to a three-class decision space.
  • LogisticRegression(C=100, solver='lbfgs'): Trains a multinomial classifier. The algorithm optimizes a distinct set of weights and biases for each target category, preparing the model to partition the 2D plane into three distinct classification zones.
X = iris.data[:,0:2]
y = iris.target
lrmc = LogisticRegression( 
    solver='lbfgs',
    C=100,
    random_state=22
)
lrmc.fit(X,y)
LogisticRegression(C=100, random_state=22)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
    <div class="estimator-table">
        <details>
            <summary>Parameters</summary>
            <table class="parameters-table">
              <tbody>

    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('C',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-C;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0">
        C
        <span class="param-doc-description"
        style="position-anchor: --doc-link-C;">
        C: float, default=1.0<br><br>Inverse of regularization strength; must be a positive float.<br>Like in support vector machines, smaller values specify stronger<br>regularization. `C=np.inf` results in unpenalized logistic regression.<br>For a visual example on the effect of tuning the `C` parameter<br>with an L1 penalty, see:<br>:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="user-set">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('random_state',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-random_state;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone">
        random_state
        <span class="param-doc-description"
        style="position-anchor: --doc-link-random_state;">
        random_state: int, RandomState instance, default=None<br><br>Used when ``solver`` == &#x27;sag&#x27;, &#x27;saga&#x27; or &#x27;liblinear&#x27; to shuffle the<br>data. See :term:`Glossary &lt;random_state&gt;` for details.</span>
    </a>
</td>
        <td class="value">22</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('penalty',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-penalty;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27">
        penalty
        <span class="param-doc-description"
        style="position-anchor: --doc-link-penalty;">
        penalty: {&#x27;l1&#x27;, &#x27;l2&#x27;, &#x27;elasticnet&#x27;, None}, default=&#x27;l2&#x27;<br><br>Specify the norm of the penalty:<br><br>- `None`: no penalty is added;<br>- `&#x27;l2&#x27;`: add an L2 penalty term and it is the default choice;<br>- `&#x27;l1&#x27;`: add an L1 penalty term;<br>- `&#x27;elasticnet&#x27;`: both L1 and L2 penalty terms are added.<br><br>.. warning::<br>   Some penalties may not work with some solvers. See the parameter<br>   `solver` below, to know the compatibility between the penalty and<br>   solver.<br><br>.. versionadded:: 0.19<br>   l1 penalty with SAGA solver (allowing &#x27;multinomial&#x27; + L1)<br><br>.. deprecated:: 1.8<br>   `penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>   Use `l1_ratio` and `C` instead. `l1_ratio=0` for `penalty=&#x27;l2&#x27;`,<br>   `l1_ratio=1` for `penalty=&#x27;l1&#x27;`, `l1_ratio` set to any float between 0 and 1<br>   for `penalty=&#x27;elasticnet&#x27;`, and `C=np.inf` for `penalty=None`.</span>
    </a>
</td>
        <td class="value">&#x27;deprecated&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('l1_ratio',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-l1_ratio;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0">
        l1_ratio
        <span class="param-doc-description"
        style="position-anchor: --doc-link-l1_ratio;">
        l1_ratio: float, default=0.0<br><br>The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br><br>.. warning::<br>   Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>   solvers. See the parameter `solver` below, to know the compatibility between<br>   the penalty and solver.<br><br>.. versionchanged:: 1.8<br>    Default value changed from None to 0.0.<br><br>.. deprecated:: 1.8<br>    `None` is deprecated and will be removed in version 1.10. Always use<br>    `l1_ratio` to specify the penalty type.</span>
    </a>
</td>
        <td class="value">0.0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('dual',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-dual;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse">
        dual
        <span class="param-doc-description"
        style="position-anchor: --doc-link-dual;">
        dual: bool, default=False<br><br>Dual (constrained) or primal (regularized, see also<br>:ref:`this equation &lt;regularized-logistic-loss&gt;`) formulation. Dual formulation<br>is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>when n_samples &gt; n_features.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('tol',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-tol;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4">
        tol
        <span class="param-doc-description"
        style="position-anchor: --doc-link-tol;">
        tol: float, default=1e-4<br><br>Tolerance for stopping criteria.</span>
    </a>
</td>
        <td class="value">0.0001</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('fit_intercept',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-fit_intercept;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue">
        fit_intercept
        <span class="param-doc-description"
        style="position-anchor: --doc-link-fit_intercept;">
        fit_intercept: bool, default=True<br><br>Specifies if a constant (a.k.a. bias or intercept) should be<br>added to the decision function.</span>
    </a>
</td>
        <td class="value">True</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('intercept_scaling',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_scaling;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1">
        intercept_scaling
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_scaling;">
        intercept_scaling: float, default=1<br><br>Useful only when the solver `liblinear` is used<br>and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>`[x, self.intercept_scaling]`,<br>i.e. a &quot;synthetic&quot; feature with constant value equal to<br>`intercept_scaling` is appended to the instance vector.<br>The intercept becomes<br>``intercept_scaling * synthetic_feature_weight``.<br><br>.. note::<br>    The synthetic feature weight is subject to L1 or L2<br>    regularization as all other features.<br>    To lessen the effect of regularization on synthetic feature weight<br>    (and therefore on the intercept) `intercept_scaling` has to be increased.</span>
    </a>
</td>
        <td class="value">1</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('class_weight',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-class_weight;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone">
        class_weight
        <span class="param-doc-description"
        style="position-anchor: --doc-link-class_weight;">
        class_weight: dict or &#x27;balanced&#x27;, default=None<br><br>Weights associated with classes in the form ``{class_label: weight}``.<br>If not given, all classes are supposed to have weight one.<br><br>The &quot;balanced&quot; mode uses the values of y to automatically adjust<br>weights inversely proportional to class frequencies in the input data<br>as ``n_samples / (n_classes * np.bincount(y))``.<br><br>Note that these weights will be multiplied with sample_weight (passed<br>through the fit method) if sample_weight is specified.<br><br>.. versionadded:: 0.17<br>   *class_weight=&#x27;balanced&#x27;*</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('solver',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-solver;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27">
        solver
        <span class="param-doc-description"
        style="position-anchor: --doc-link-solver;">
        solver: {&#x27;lbfgs&#x27;, &#x27;liblinear&#x27;, &#x27;newton-cg&#x27;, &#x27;newton-cholesky&#x27;, &#x27;sag&#x27;, &#x27;saga&#x27;},             default=&#x27;lbfgs&#x27;<br><br>Algorithm to use in the optimization problem. Default is &#x27;lbfgs&#x27;.<br>To choose a solver, you might want to consider the following aspects:<br><br>- &#x27;lbfgs&#x27; is a good default solver because it works reasonably well for a wide<br>  class of problems.<br>- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>  &#x27;liblinear&#x27; minimize the full multinomial loss, &#x27;liblinear&#x27; will raise an<br>  error.<br>- &#x27;newton-cholesky&#x27; is a good choice for<br>  `n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>  categorical features with rare categories. Be aware that the memory usage<br>  of this solver has a quadratic dependency on `n_features * n_classes`<br>  because it explicitly computes the full Hessian matrix.<br>- For small datasets, &#x27;liblinear&#x27; is a good choice, whereas &#x27;sag&#x27;<br>  and &#x27;saga&#x27; are faster for large ones;<br>- &#x27;liblinear&#x27; can only handle binary classification by default. To apply a<br>  one-versus-rest scheme for the multiclass setting one can wrap it with the<br>  :class:`~sklearn.multiclass.OneVsRestClassifier`.<br><br>.. warning::<br>   The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>   for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>   Elastic-Net) and on (multinomial) multiclass support:<br><br>   ================= ======================== ======================<br>   solver            l1_ratio                 multinomial multiclass<br>   ================= ======================== ======================<br>   &#x27;lbfgs&#x27;           l1_ratio=0               yes<br>   &#x27;liblinear&#x27;       l1_ratio=1 or l1_ratio=0 no<br>   &#x27;newton-cg&#x27;       l1_ratio=0               yes<br>   &#x27;newton-cholesky&#x27; l1_ratio=0               yes<br>   &#x27;sag&#x27;             l1_ratio=0               yes<br>   &#x27;saga&#x27;            0&lt;=l1_ratio&lt;=1           yes<br>   ================= ======================== ======================<br><br>.. note::<br>   &#x27;sag&#x27; and &#x27;saga&#x27; fast convergence is only guaranteed on features<br>   with approximately the same scale. You can preprocess the data with<br>   a scaler from :mod:`sklearn.preprocessing`.<br><br>.. seealso::<br>   Refer to the :ref:`User Guide &lt;Logistic_regression&gt;` for more<br>   information regarding :class:`LogisticRegression` and more specifically the<br>   :ref:`Table &lt;logistic_regression_solvers&gt;`<br>   summarizing solver/penalty supports.<br><br>.. versionadded:: 0.17<br>   Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>   version 0.18.<br>.. versionadded:: 0.19<br>   SAGA solver.<br>.. versionchanged:: 0.22<br>   The default solver changed from &#x27;liblinear&#x27; to &#x27;lbfgs&#x27; in 0.22.<br>.. versionadded:: 1.2<br>   newton-cholesky solver. Multinomial support in version 1.6.</span>
    </a>
</td>
        <td class="value">&#x27;lbfgs&#x27;</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('max_iter',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-max_iter;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100">
        max_iter
        <span class="param-doc-description"
        style="position-anchor: --doc-link-max_iter;">
        max_iter: int, default=100<br><br>Maximum number of iterations taken for the solvers to converge.</span>
    </a>
</td>
        <td class="value">100</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('verbose',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-verbose;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0">
        verbose
        <span class="param-doc-description"
        style="position-anchor: --doc-link-verbose;">
        verbose: int, default=0<br><br>For the liblinear and lbfgs solvers set verbose to any positive<br>number for verbosity.</span>
    </a>
</td>
        <td class="value">0</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('warm_start',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-warm_start;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse">
        warm_start
        <span class="param-doc-description"
        style="position-anchor: --doc-link-warm_start;">
        warm_start: bool, default=False<br><br>When set to True, reuse the solution of the previous call to fit as<br>initialization, otherwise, just erase the previous solution.<br>Useless for liblinear solver. See :term:`the Glossary &lt;warm_start&gt;`.<br><br>.. versionadded:: 0.17<br>   *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</span>
    </a>
</td>
        <td class="value">False</td>
    </tr>


    <tr class="default">
        <td><i class="copy-paste-icon"
             onclick="copyToClipboard('n_jobs',
                      this.parentElement.nextElementSibling)"
        ></i></td>
        <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_jobs;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone">
        n_jobs
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_jobs;">
        n_jobs: int, default=None<br><br>Does not have any effect.<br><br>.. deprecated:: 1.8<br>   `n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span>
    </a>
</td>
        <td class="value">None</td>
    </tr>

              </tbody>
            </table>
        </details>
    </div>

    <div class="estimator-table">
        <details>
            <summary>Fitted attributes</summary>
            <table class="parameters-table">
                <tbody>
                    <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Value</th>
                    </tr>

   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-classes_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=classes_,-ndarray%20of%20shape%20%28n_classes%2C%20%29">
        classes_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-classes_;">
        classes_: ndarray of shape (n_classes, )<br><br>A list of class labels known to the classifier.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int64](3,)</td>
       <td>[0,1,2]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-coef_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=coef_,-ndarray%20or%20CSR%20matrix%20of%20shape%20%281%2C%20n_features%29%20or%20%28n_classes%2C%20n_features%29">
        coef_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-coef_;">
        coef_: ndarray or CSR matrix of shape (1, n_features) or (n_classes, n_features)<br><br>Coefficients of the features in the decision function.<br><br>`coef_` is of shape (1, n_features) when the given problem is binary.<br><br>By default, it will be created as a dense array, but can be turned to<br>sparse (CSR format) through :meth:`sparsify` (which can be beneficial<br>under L1 regularization when many coefficients are zero), and back to<br>dense through :meth:`densify`.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](3, 2)</td>
       <td>[[-9.33, 8.18],

[ 3.73,-4.3 ], [ 5.61,-3.88]]

   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-intercept_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_,-ndarray%20of%20shape%20%281%2C%29%20or%20%28n_classes%2C%29">
        intercept_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-intercept_;">
        intercept_: ndarray of shape (1,) or (n_classes,)<br><br>Intercept (a.k.a. bias) added to the decision function.<br><br>If `fit_intercept` is set to False, the intercept is set to zero.<br>`intercept_` is of shape (1,) when the given problem is binary.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[float64](3,)</td>
       <td>[ 25.2 , -6.11,-19.1 ]</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_features_in_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_features_in_,-int">
        n_features_in_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_features_in_;">
        n_features_in_: int<br><br>Number of features seen during :term:`fit`.<br><br>.. versionadded:: 0.24</span>
    </a>
</td>
       <td class="fitted-att-type">int</td>
       <td>2</td>


   </tr>


   <tr class="default">
       <td class="param">
    <a class="param-doc-link"
        style="anchor-name: --doc-link-n_iter_;"
        rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_iter_,-ndarray%20of%20shape%20%281%2C%20%29">
        n_iter_
        <span class="param-doc-description"
        style="position-anchor: --doc-link-n_iter_;">
        n_iter_: ndarray of shape (1, )<br><br>Actual number of iterations for all classes.<br><br>.. versionchanged:: 0.20<br><br>    In SciPy &lt;= 1.0.0 the number of lbfgs iterations may exceed<br>    ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.</span>
    </a>
</td>
       <td class="fitted-att-type">ndarray[int32](1,)</td>
       <td>[59]</td>


   </tr>

                </tbody>
            </table>
        </details>
    </div>
</div></div></div></div></div><script>/*  Authors: The scikit-learn developers

SPDX-License-Identifier: BSD-3-Clause */

function copyToClipboard(text, element) { // Get the parameter prefix from the closest toggleable content const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : ''; const fullParamName = paramPrefix ? ${paramPrefix}${text} : text;

const originalStyle = element.style;
const computedStyle = window.getComputedStyle(element);
const originalWidth = computedStyle.width;
const originalHTML = element.innerHTML.replace('Copied!', '');

navigator.clipboard.writeText(fullParamName)
    .then(() => {
        element.style.width = originalWidth;
        element.style.color = 'green';
        element.innerHTML = "Copied!";

        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    })
    .catch(err => {
        console.error('Failed to copy:', err);
        element.style.color = 'red';
        element.innerHTML = "Failed!";
        setTimeout(() => {
            element.innerHTML = originalHTML;
            element.style = originalStyle;
        }, 2000);
    });
return false;

}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) { const toggleableContent = element.closest('.sk-toggleable__content'); const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';

const parent = element.parentElement;
if (!parent || !parent.nextElementSibling) {
    console.warn('Expected copy-paste icon is missing from the DOM structure');
    return;
}

const paramName = element.parentElement.nextElementSibling
    .textContent.trim().split(' ')[0];
const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

element.setAttribute('title', fullParamName);

});

/**

  • Copy the list of feature names formatted as a Python list.

  • @param {HTMLElement} element - The copy button inside a .features block; its siblings

  • contain a details element and a table containing feature named.

  • @returns {boolean} Always returns false so callers can prevent the default click behavior. */ function copyFeatureNamesToClipboard(element) { var detailsElem = element.closest('.features').querySelector('details'); var wasOpen = detailsElem.open; detailsElem.open = true; var content = element.closest('.features').querySelector('tbody') .innerText.trim(); if (!wasOpen) detailsElem.open = false; const rows = content.split('\n').map(row => "${row}"); const formattedText = [\n${rows.join(',\n')},\n]; const originalHTML = element.innerHTML.replace('✔', ''); const originalStyle = element.style; const copyMark = document.createElement('span'); copyMark.innerHTML = '✔'; copyMark.style.color = 'blue'; copyMark.style.fontSize = '1em';

    navigator.clipboard.writeText(formattedText) .then(() => { element.style.display = 'none'; element.parentElement.appendChild(copyMark);

         setTimeout(() => {
             copyMark.remove();
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     })
     .catch(err => {
         console.error('Failed to copy:', err);
         element.style.color = 'orange';
         element.innerHTML = "Failed!";
         setTimeout(() => {
             element.innerHTML = originalHTML;
             element.style = originalStyle;
         }, 1000);
     });
    

    return false; } /**

  • Adapted from Skrub

  • 403466d1d5/skrub/_reporting/_data/templates/report.js (L789)

  • @returns "light" or "dark" */ function detectTheme(element) { const body = document.querySelector('body');

    // Check VSCode theme const themeKindAttr = body.getAttribute('data-vscode-theme-kind'); const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) { const themeKind = themeKindAttr.toLowerCase(); const themeName = themeNameAttr.toLowerCase();

     if (themeKind.includes("dark") || themeName.includes("dark")) {
         return "dark";
     }
     if (themeKind.includes("light") || themeName.includes("light")) {
         return "light";
     }
    

    }

    // Check Jupyter theme if (body.getAttribute('data-jp-theme-light') === 'false') { return 'dark'; } else if (body.getAttribute('data-jp-theme-light') === 'true') { return 'light'; }

    // Guess based on a parent element's color const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color'); const match = color.match(/^rgb\s*\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\s*$/i); if (match) { const [r, g, b] = [ parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]) ];

     // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
     const luma = 0.299 * r + 0.587 * g + 0.114 * b;
    
     if (luma > 180) {
         // If the text is very bright we have a dark theme
         return 'dark';
     }
     if (luma < 75) {
         // If the text is very dark we have a light theme
         return 'light';
     }
     // Otherwise fall back to the next heuristic.
    

    }

    // Fallback to system preference return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }

function forceTheme(elementId) { const estimatorElement = document.querySelector(#${elementId}); if (estimatorElement === null) { console.error(Element with id ${elementId} not found.); } else { const theme = detectTheme(estimatorElement); estimatorElement.classList.add(theme); } }

forceTheme('sk-container-id-5');

Multi-Class Grid Generation and Probability Evaluation

This cell sets up the coordinate testing matrix to evaluate the multi-class prediction behavior across the entire sepal feature space:

  • np.meshgrid: Constructs a dense 100 \times 100 coordinate grid bounding the Sepal Length (38 cm) and Sepal Width (06 cm) ranges.
  • Xnew (np.c_): Flattens and pairs the grid elements into a matrix of 10,000 distinct 2D spatial coordinates.
  • lrmc.predict_proba(Xnew): Computes a three-column probability matrix for each point. This mapping determines the exact multi-class boundaries by evaluating the localized likelihood for Setosa, Versicolor, and Virginica simultaneously.
x0, x1 = np.meshgrid(
    np.linspace(3,8,100).reshape(-1,1),
    np.linspace(0,6,100).reshape(-1,1)
)
Xnew = np.c_[x0.ravel(), x1.ravel()]
yPred = lrmc.predict_proba(Xnew)
plt.figure(figsize=(10,4))
plt.plot(X[y==0,0], X[y==0,1],'.b',label='Setosa')
plt.plot(X[y==1,0], X[y==1,1],'+g',label='Versi')
plt.plot(X[y==2,0], X[y==2,1],'*m',label='Virgi')
zz=yPred[:,1].reshape(x0.shape)
contour=plt.contour(x0,x1,zz)
plt.clabel(contour, inline=1,fontsize=15)
plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")
plt.legend()
plt.show()

png

This plot maps the continuous probability distribution of the middle class within the multi-class decision space:

  • Three-Class Distribution: Displays all species simultaneously using distinct markers: blue dots for Setosa (y=0), green pluses for Versicolor (y=1), and magenta stars for Virginica (y=2).
  • Target Class Extraction (yPred[:, 1]): Slicing the second column of the probability matrix isolates and tracks the specific localized likelihood of a sample being Iris versicolor.
  • Localized Probability Ridge: Unlike the linear boundaries seen in binary classification, the multinomial model creates a bounded peak or "ridge" to isolate the middle class. The highest contour line (0.90) tightly encapsulates the core Versicolor cluster, dropping off systematically as the features move toward Setosa (left) or Virginica (right) territories.
yPred = lrmc.predict(Xnew)
plt.figure(figsize=(10,6))
plt.plot(X[y==0,0], X[y==0,1],'bs',label='Setosa')
plt.plot(X[y==1,0], X[y==1,1],'g^',label='Versi')
plt.plot(X[y==2,0], X[y==2,1],'*m',label='Virgi')
zz=yPred.reshape(x0.shape)
contour=plt.contourf(x0,x1,zz, cmap='jet', alpha=0.3)
plt.clabel(contour, inline=1,fontsize=15)
plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")
plt.legend()
plt.show()

png

This plot visualizes the ultimate classification boundaries by partitioning the entire 2D feature space into hard decision zones:

  • Hard Class Assignment (lrmc.predict): Converts continuous probabilities into discrete class verdicts (0, 1, or 2) by applying an argmax function (selecting the class with the highest probability for each point).
  • Filled Decision Regions (plt.contourf): Shades the coordinate plane into three distinct, solid zones using the jet colormap:
    • Blue Region: Absolute classification space for Iris setosa.
    • Green Region: Absolute classification space for Iris versicolor.
    • Red/Orange Region: Absolute classification space for Iris virginica.
  • Boundary Analysis: The sharp geometric intersections between the colored blocks define the definitive decision thresholds. This layout explicitly reveals how the linear multi-class model manages the regional trade-offs and handles the spatial overlap between the Versicolor and Virginica samples.
fig, ax =plt.subplots(subplot_kw={"projection": "3d"})
surf = ax.plot_surface(x0,x1,zz, cmap='jet')
ax.scatter(iris.data[:,0:1], iris.data[:,1:2], y, 'or')
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x2a3c02451d0>

png

This cell integrates the actual dataset samples into the 3D hard decision space to visually evaluate the multi-class model's accuracy:

  • Discrete Vertical Alignment (Z): Both the staircase surface and the scatter markers use the integer multi-class taxonomy (0 for Setosa, 1 for Versicolor, and 2 for Virginica) instead of continuous probabilities.
  • Stepped Surface (plot_surface): Represents the geometric boundaries computed by the model. Each level dictates the categorical verdict zone based on the combination of sepal features.
  • True Labels Scatter (ax.scatter): Plots the real flower samples at their actual feature coordinates and true species height. This allows immediate visual verification of performance: samples resting on their matching colored step are correctly classified, while those caught on the wrong tier highlight the exact instances of classification error caused by spatial overlap.