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.

6882 lines
264 KiB
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 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.
```python
!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.
```python
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.
```python
sl = iris.data[:, 0:1]
sw = iris.data[:, 1:2]
plt.plot(sl,sw,'.k')
plt.show()
```
![png](README_files/README_10_0.png)
```python
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.
```python
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](README_files/README_13_0.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.
```python
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.
```python
from sklearn.linear_model import LogisticRegression
mylr = LogisticRegression(solver='lbfgs', random_state=42)
mylr.fit(x,y)
```
<style>.sk-global {
/* Definition of color scheme common for light and dark mode */
--sklearn-color-text: #000;
--sklearn-color-text-muted: #666;
--sklearn-color-line: gray;
/* Definition of color scheme for unfitted estimators */
--sklearn-color-unfitted-level-0: #fff5e6;
--sklearn-color-unfitted-level-1: #f6e4d2;
--sklearn-color-unfitted-level-2: #ffe0b3;
--sklearn-color-unfitted-level-3: chocolate;
/* Definition of color scheme for fitted estimators */
--sklearn-color-fitted-level-0: #f0f8ff;
--sklearn-color-fitted-level-1: #d4ebff;
--sklearn-color-fitted-level-2: #b3dbfd;
--sklearn-color-fitted-level-3: cornflowerblue;
}
.sk-global.light {
/* Specific color for light theme */
--sklearn-color-text-on-default-background: black;
--sklearn-color-background: white;
--sklearn-color-border-box: black;
--sklearn-color-icon: #696969;
}
.sk-global.dark {
--sklearn-color-text-on-default-background: white;
--sklearn-color-background: #111;
--sklearn-color-border-box: white;
--sklearn-color-icon: #878787;
}
.sk-global {
color: var(--sklearn-color-text);
}
.sk-global pre {
padding: 0;
}
.sk-global input.sk-hidden--visually {
border: 0;
clip-path: inset(100%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.sk-global div.sk-dashed-wrapped {
border: 1px dashed var(--sklearn-color-line);
margin: 0 0.4em 0.5em 0.4em;
box-sizing: border-box;
padding-bottom: 0.4em;
background-color: var(--sklearn-color-background);
}
.sk-global div.sk-container {
/* jupyter's `normalize.less` sets `[hidden] { display: none; }`
but bootstrap.min.css set `[hidden] { display: none !important; }`
so we also need the `!important` here to be able to override the
default hidden behavior on the sphinx rendered scikit-learn.org.
See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
display: inline-block !important;
position: relative;
}
.sk-global div.sk-text-repr-fallback {
display: none;
}
div.sk-parallel-item,
div.sk-serial,
div.sk-item {
/* draw centered vertical line to link estimators */
background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
/* Parallel-specific style estimator block */
.sk-global div.sk-parallel-item::after {
content: "";
width: 100%;
border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
flex-grow: 1;
}
.sk-global div.sk-parallel {
display: flex;
align-items: stretch;
justify-content: center;
background-color: var(--sklearn-color-background);
position: relative;
}
.sk-global div.sk-parallel-item {
display: flex;
flex-direction: column;
}
.sk-global div.sk-parallel-item:first-child::after {
align-self: flex-end;
width: 50%;
}
.sk-global div.sk-parallel-item:last-child::after {
align-self: flex-start;
width: 50%;
}
.sk-global div.sk-parallel-item:only-child::after {
width: 0;
}
/* Serial-specific style estimator block */
.sk-global div.sk-serial {
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--sklearn-color-background);
padding-right: 1em;
padding-left: 1em;
}
/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/
/* Pipeline and ColumnTransformer style (default) */
.sk-global div.sk-toggleable {
/* Default theme specific background. It is overwritten whether we have a
specific estimator or a Pipeline/ColumnTransformer */
background-color: var(--sklearn-color-background);
}
/* Toggleable label */
.sk-global label.sk-toggleable__label {
cursor: pointer;
display: flex;
width: 100%;
margin-bottom: 0;
padding: 0.5em;
box-sizing: border-box;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
}
.sk-global label.sk-toggleable__label .caption {
font-size: 0.6rem;
font-weight: lighter;
color: var(--sklearn-color-text-muted);
}
.sk-global label.sk-toggleable__label-arrow:before {
/* Arrow on the left of the label */
content: "▸";
float: left;
margin-right: 0.25em;
color: var(--sklearn-color-icon);
}
.sk-global label.sk-toggleable__label-arrow:hover:before {
color: var(--sklearn-color-text);
}
/* Toggleable content - dropdown */
.sk-global div.sk-toggleable__content {
display: none;
text-align: left;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global div.sk-toggleable__content pre {
margin: 0.2em;
border-radius: 0.25em;
color: var(--sklearn-color-text);
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted pre {
/* unfitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global input.sk-toggleable__control:checked~div.sk-toggleable__content {
/* Expand drop-down */
display: block;
width: 100%;
overflow: visible;
}
.sk-global input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
content: "▾";
}
/* Pipeline/ColumnTransformer-specific style */
.sk-global div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator-specific style */
/* Colorize estimator box */
.sk-global div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
.sk-global div.sk-label label.sk-toggleable__label,
.sk-global div.sk-label label {
/* The background is the default theme color */
color: var(--sklearn-color-text-on-default-background);
}
/* On hover, darken the color of the background */
.sk-global div.sk-label:hover label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
/* Label box, darken color on hover, fitted */
.sk-global div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator label */
.sk-global div.sk-label label {
font-family: monospace;
font-weight: bold;
line-height: 1.2em;
}
.sk-global div.sk-label-container {
text-align: center;
}
/* Estimator-specific */
.sk-global div.sk-estimator {
font-family: monospace;
border: 1px dotted var(--sklearn-color-border-box);
border-radius: 0.25em;
box-sizing: border-box;
margin-bottom: 0.5em;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-estimator.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
/* on hover */
.sk-global div.sk-estimator:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
/* Specification for estimator info (e.g. "i" and "?") */
/* Common style for "i" and "?" */
.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
float: right;
font-size: smaller;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1em;
height: 1em;
width: 1em;
text-decoration: none !important;
margin-left: 0.5em;
text-align: center;
/* unfitted */
border: var(--sklearn-color-unfitted-level-3) 1pt solid;
color: var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3) 1pt solid;
color: var(--sklearn-color-fitted-level-3);
}
/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-unfitted-level-0);
text-decoration: none;
}
div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-fitted-level-0);
text-decoration: none;
}
/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
display: none;
z-index: 9999;
position: relative;
font-weight: normal;
right: .2ex;
padding: .5ex;
margin: .5ex;
width: min-content;
min-width: 20ex;
max-width: 50ex;
color: var(--sklearn-color-text);
box-shadow: 2pt 2pt 4pt #999;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: .5pt solid var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted span {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3);
}
.sk-estimator-doc-link:hover span {
display: block;
}
/* "?"-specific style due to the `<a>` HTML tag */
.sk-global a.estimator_doc_link {
float: right;
font-size: 1rem;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1rem;
height: 1rem;
width: 1rem;
text-decoration: none;
/* unfitted */
color: var(--sklearn-color-unfitted-level-1);
border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}
.sk-global a.estimator_doc_link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-1) 1pt solid;
color: var(--sklearn-color-fitted-level-1);
}
/* On hover */
.sk-global a.estimator_doc_link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
color: var(--sklearn-color-background);
text-decoration: none;
}
.sk-global a.estimator_doc_link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
}
.sk-top-container.sk-global {
/* pydata-sphinx-theme hides overflow, so scrolling is disabled.
We need to set it to !important and add tabindex="0" in the HTML
to allow keyboard-only users to navigate the display. */
overflow-x: scroll !important;
max-width: 100%;
}
.estimator-table {
font-family: monospace;
}
.estimator-table summary {
padding: .5rem;
cursor: pointer;
}
.estimator-table summary::marker {
font-size: 0.7rem;
}
.estimator-table details[open] {
padding-left: 0.1rem;
padding-right: 0.1rem;
padding-bottom: 0.3rem;
}
.estimator-table .parameters-table {
margin-left: auto !important;
margin-right: auto !important;
margin-top: 0;
}
.estimator-table .parameters-table tr:nth-child(odd) {
background-color: #fff;
}
.estimator-table .parameters-table tr:nth-child(even) {
background-color: #f6f6f6;
}
.estimator-table .parameters-table tr:hover td {
background-color: #e0e0e0;
}
.estimator-table table :is(td, th) {
border: 1px solid rgba(106, 105, 104, 0.232);
}
/*
`table td`is set in notebook with right text-align.
We need to overwrite it.
*/
.estimator-table table td.param {
text-align: left;
position: relative;
padding: 0;
}
.user-set td {
color:rgb(255, 94, 0);
text-align: left !important;
}
.user-set td.value {
color:rgb(255, 94, 0);
background-color: transparent;
}
.default td, .estimator-table th {
color: black;
text-align: left !important;
}
.user-set td i,
.default td i {
color: black;
}
td.fitted-att-type {
white-space: preserve nowrap;
}
/*
Styles for parameter documentation links
We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
text-decoration: underline dashed;
text-underline-offset: .3em;
color: inherit;
display: block;
padding: .5em;
}
@supports(anchor-name: --doc-link) {
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
anchor-name: --doc-link;
}
}
/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
position: absolute;
content: "";
inset: 0;
}
.param-doc-description {
display: none;
position: absolute;
z-index: 9999;
left: 0;
padding: .5ex;
margin-left: 1.5em;
color: var(--sklearn-color-text);
box-shadow: .3em .3em .4em #999;
width: max-content;
text-align: left;
max-height: 10em;
overflow-y: auto;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: thin solid var(--sklearn-color-unfitted-level-3);
}
@supports(position-area: center right) {
.param-doc-description {
position-area: center right;
position: fixed;
margin-left: 0;
}
}
/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: thin solid var(--sklearn-color-fitted-level-3);
}
.param-doc-link:hover .param-doc-description {
display: block;
}
.copy-paste-icon {
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
background-repeat: no-repeat;
background-size: 14px 14px;
background-position: 0;
display: inline-block;
width: 14px;
height: 14px;
cursor: pointer;
}
.features {
font-family: monospace;
cursor: pointer;
background-color: var(--sklearn-color-unfitted-level-0);
border: 1px dotted var(--sklearn-color-border-box);
border-radius: .20em;
margin-bottom: 0.5em;
font-size: inherit; /* Needed for jupyter */
}
.features.fitted {
background-color: var(--sklearn-color-fitted-level-0);
}
.features summary {
cursor: pointer;
display: flex;
margin-bottom: 0;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: .25em;
}
.features details[open] > summary {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
border-radius: .20em 0 0 0;
}
.features.fitted details[open] > summary {
background-color: var(--sklearn-color-fitted-level-2);
border-radius: .20em 0 0 0;
}
.features details > summary .arrow::before {
content: "▸";
color: grey;
}
.features details[open] > summary .arrow::before {
content: "▾";
}
.features details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-unfitted-level-2);
}
.features.fitted details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-fitted-level-2);
}
.features .features-container {
max-width: 15em;
max-height: 10em;
overflow: auto;
scrollbar-width: thin;
padding: .25em 0.1rem;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 0 0 .5em .5em;
}
.features.fitted .features-container {
background-color: var(--sklearn-color-fitted-level-0);
}
.features .image-container {
block-size: 1em;
inline-size: 1em;
padding: 0;
margin: 0%;
display: flex;
justify-content: center;
align-items: center;
}
.features .copy-paste-icon {
background-size: 1em 1em;
width: 1em;
height: 1em;
filter: grayscale(100%) opacity(60%);
}
.features .features-container table {
width: 100%;
margin: 0.01em;
}
.features .features-container table tr:nth-child(odd) {
background-color: #fff;
}
.features .features-container table tr:nth-child(even) {
background-color: #f6f6f6;
}
.features .features-container table tr:hover {
background-color: #e0e0e0;
}
.features .features-container table {
table-layout: inherit;
}
.features .features-container table td {
text-align: left;
padding: 0 0.5em;
border: 1px solid rgba(106, 105, 104, 0.232);
white-space: nowrap;
color: var(--sklearn-color-text);
}
.total_features {
display: flex;
justify-content: center;
margin-top: 0.5em;
}
</style><body><div id="sk-container-id-1" tabindex="0" class="sk-top-container sk-global"><div class="sk-text-repr-fallback"><pre>LogisticRegression(random_state=42)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually sk-global" id="sk-estimator-id-1" type="checkbox" checked><label for="sk-estimator-id-1" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
<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
* https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/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');</script></body>
```python
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](README_files/README_20_0.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.
```python
x = iris.data[:, 2:3]
y = (iris.target == 0).astype(int)
```
```python
from sklearn.linear_model import LogisticRegression
mylr = LogisticRegression(solver='lbfgs', random_state=42)
mylr.fit(x,y)
```
<style>.sk-global {
/* Definition of color scheme common for light and dark mode */
--sklearn-color-text: #000;
--sklearn-color-text-muted: #666;
--sklearn-color-line: gray;
/* Definition of color scheme for unfitted estimators */
--sklearn-color-unfitted-level-0: #fff5e6;
--sklearn-color-unfitted-level-1: #f6e4d2;
--sklearn-color-unfitted-level-2: #ffe0b3;
--sklearn-color-unfitted-level-3: chocolate;
/* Definition of color scheme for fitted estimators */
--sklearn-color-fitted-level-0: #f0f8ff;
--sklearn-color-fitted-level-1: #d4ebff;
--sklearn-color-fitted-level-2: #b3dbfd;
--sklearn-color-fitted-level-3: cornflowerblue;
}
.sk-global.light {
/* Specific color for light theme */
--sklearn-color-text-on-default-background: black;
--sklearn-color-background: white;
--sklearn-color-border-box: black;
--sklearn-color-icon: #696969;
}
.sk-global.dark {
--sklearn-color-text-on-default-background: white;
--sklearn-color-background: #111;
--sklearn-color-border-box: white;
--sklearn-color-icon: #878787;
}
.sk-global {
color: var(--sklearn-color-text);
}
.sk-global pre {
padding: 0;
}
.sk-global input.sk-hidden--visually {
border: 0;
clip-path: inset(100%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.sk-global div.sk-dashed-wrapped {
border: 1px dashed var(--sklearn-color-line);
margin: 0 0.4em 0.5em 0.4em;
box-sizing: border-box;
padding-bottom: 0.4em;
background-color: var(--sklearn-color-background);
}
.sk-global div.sk-container {
/* jupyter's `normalize.less` sets `[hidden] { display: none; }`
but bootstrap.min.css set `[hidden] { display: none !important; }`
so we also need the `!important` here to be able to override the
default hidden behavior on the sphinx rendered scikit-learn.org.
See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
display: inline-block !important;
position: relative;
}
.sk-global div.sk-text-repr-fallback {
display: none;
}
div.sk-parallel-item,
div.sk-serial,
div.sk-item {
/* draw centered vertical line to link estimators */
background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
/* Parallel-specific style estimator block */
.sk-global div.sk-parallel-item::after {
content: "";
width: 100%;
border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
flex-grow: 1;
}
.sk-global div.sk-parallel {
display: flex;
align-items: stretch;
justify-content: center;
background-color: var(--sklearn-color-background);
position: relative;
}
.sk-global div.sk-parallel-item {
display: flex;
flex-direction: column;
}
.sk-global div.sk-parallel-item:first-child::after {
align-self: flex-end;
width: 50%;
}
.sk-global div.sk-parallel-item:last-child::after {
align-self: flex-start;
width: 50%;
}
.sk-global div.sk-parallel-item:only-child::after {
width: 0;
}
/* Serial-specific style estimator block */
.sk-global div.sk-serial {
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--sklearn-color-background);
padding-right: 1em;
padding-left: 1em;
}
/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/
/* Pipeline and ColumnTransformer style (default) */
.sk-global div.sk-toggleable {
/* Default theme specific background. It is overwritten whether we have a
specific estimator or a Pipeline/ColumnTransformer */
background-color: var(--sklearn-color-background);
}
/* Toggleable label */
.sk-global label.sk-toggleable__label {
cursor: pointer;
display: flex;
width: 100%;
margin-bottom: 0;
padding: 0.5em;
box-sizing: border-box;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
}
.sk-global label.sk-toggleable__label .caption {
font-size: 0.6rem;
font-weight: lighter;
color: var(--sklearn-color-text-muted);
}
.sk-global label.sk-toggleable__label-arrow:before {
/* Arrow on the left of the label */
content: "▸";
float: left;
margin-right: 0.25em;
color: var(--sklearn-color-icon);
}
.sk-global label.sk-toggleable__label-arrow:hover:before {
color: var(--sklearn-color-text);
}
/* Toggleable content - dropdown */
.sk-global div.sk-toggleable__content {
display: none;
text-align: left;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global div.sk-toggleable__content pre {
margin: 0.2em;
border-radius: 0.25em;
color: var(--sklearn-color-text);
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted pre {
/* unfitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global input.sk-toggleable__control:checked~div.sk-toggleable__content {
/* Expand drop-down */
display: block;
width: 100%;
overflow: visible;
}
.sk-global input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
content: "▾";
}
/* Pipeline/ColumnTransformer-specific style */
.sk-global div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator-specific style */
/* Colorize estimator box */
.sk-global div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
.sk-global div.sk-label label.sk-toggleable__label,
.sk-global div.sk-label label {
/* The background is the default theme color */
color: var(--sklearn-color-text-on-default-background);
}
/* On hover, darken the color of the background */
.sk-global div.sk-label:hover label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
/* Label box, darken color on hover, fitted */
.sk-global div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator label */
.sk-global div.sk-label label {
font-family: monospace;
font-weight: bold;
line-height: 1.2em;
}
.sk-global div.sk-label-container {
text-align: center;
}
/* Estimator-specific */
.sk-global div.sk-estimator {
font-family: monospace;
border: 1px dotted var(--sklearn-color-border-box);
border-radius: 0.25em;
box-sizing: border-box;
margin-bottom: 0.5em;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-estimator.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
/* on hover */
.sk-global div.sk-estimator:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
/* Specification for estimator info (e.g. "i" and "?") */
/* Common style for "i" and "?" */
.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
float: right;
font-size: smaller;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1em;
height: 1em;
width: 1em;
text-decoration: none !important;
margin-left: 0.5em;
text-align: center;
/* unfitted */
border: var(--sklearn-color-unfitted-level-3) 1pt solid;
color: var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3) 1pt solid;
color: var(--sklearn-color-fitted-level-3);
}
/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-unfitted-level-0);
text-decoration: none;
}
div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-fitted-level-0);
text-decoration: none;
}
/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
display: none;
z-index: 9999;
position: relative;
font-weight: normal;
right: .2ex;
padding: .5ex;
margin: .5ex;
width: min-content;
min-width: 20ex;
max-width: 50ex;
color: var(--sklearn-color-text);
box-shadow: 2pt 2pt 4pt #999;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: .5pt solid var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted span {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3);
}
.sk-estimator-doc-link:hover span {
display: block;
}
/* "?"-specific style due to the `<a>` HTML tag */
.sk-global a.estimator_doc_link {
float: right;
font-size: 1rem;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1rem;
height: 1rem;
width: 1rem;
text-decoration: none;
/* unfitted */
color: var(--sklearn-color-unfitted-level-1);
border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}
.sk-global a.estimator_doc_link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-1) 1pt solid;
color: var(--sklearn-color-fitted-level-1);
}
/* On hover */
.sk-global a.estimator_doc_link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
color: var(--sklearn-color-background);
text-decoration: none;
}
.sk-global a.estimator_doc_link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
}
.sk-top-container.sk-global {
/* pydata-sphinx-theme hides overflow, so scrolling is disabled.
We need to set it to !important and add tabindex="0" in the HTML
to allow keyboard-only users to navigate the display. */
overflow-x: scroll !important;
max-width: 100%;
}
.estimator-table {
font-family: monospace;
}
.estimator-table summary {
padding: .5rem;
cursor: pointer;
}
.estimator-table summary::marker {
font-size: 0.7rem;
}
.estimator-table details[open] {
padding-left: 0.1rem;
padding-right: 0.1rem;
padding-bottom: 0.3rem;
}
.estimator-table .parameters-table {
margin-left: auto !important;
margin-right: auto !important;
margin-top: 0;
}
.estimator-table .parameters-table tr:nth-child(odd) {
background-color: #fff;
}
.estimator-table .parameters-table tr:nth-child(even) {
background-color: #f6f6f6;
}
.estimator-table .parameters-table tr:hover td {
background-color: #e0e0e0;
}
.estimator-table table :is(td, th) {
border: 1px solid rgba(106, 105, 104, 0.232);
}
/*
`table td`is set in notebook with right text-align.
We need to overwrite it.
*/
.estimator-table table td.param {
text-align: left;
position: relative;
padding: 0;
}
.user-set td {
color:rgb(255, 94, 0);
text-align: left !important;
}
.user-set td.value {
color:rgb(255, 94, 0);
background-color: transparent;
}
.default td, .estimator-table th {
color: black;
text-align: left !important;
}
.user-set td i,
.default td i {
color: black;
}
td.fitted-att-type {
white-space: preserve nowrap;
}
/*
Styles for parameter documentation links
We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
text-decoration: underline dashed;
text-underline-offset: .3em;
color: inherit;
display: block;
padding: .5em;
}
@supports(anchor-name: --doc-link) {
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
anchor-name: --doc-link;
}
}
/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
position: absolute;
content: "";
inset: 0;
}
.param-doc-description {
display: none;
position: absolute;
z-index: 9999;
left: 0;
padding: .5ex;
margin-left: 1.5em;
color: var(--sklearn-color-text);
box-shadow: .3em .3em .4em #999;
width: max-content;
text-align: left;
max-height: 10em;
overflow-y: auto;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: thin solid var(--sklearn-color-unfitted-level-3);
}
@supports(position-area: center right) {
.param-doc-description {
position-area: center right;
position: fixed;
margin-left: 0;
}
}
/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: thin solid var(--sklearn-color-fitted-level-3);
}
.param-doc-link:hover .param-doc-description {
display: block;
}
.copy-paste-icon {
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
background-repeat: no-repeat;
background-size: 14px 14px;
background-position: 0;
display: inline-block;
width: 14px;
height: 14px;
cursor: pointer;
}
.features {
font-family: monospace;
cursor: pointer;
background-color: var(--sklearn-color-unfitted-level-0);
border: 1px dotted var(--sklearn-color-border-box);
border-radius: .20em;
margin-bottom: 0.5em;
font-size: inherit; /* Needed for jupyter */
}
.features.fitted {
background-color: var(--sklearn-color-fitted-level-0);
}
.features summary {
cursor: pointer;
display: flex;
margin-bottom: 0;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: .25em;
}
.features details[open] > summary {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
border-radius: .20em 0 0 0;
}
.features.fitted details[open] > summary {
background-color: var(--sklearn-color-fitted-level-2);
border-radius: .20em 0 0 0;
}
.features details > summary .arrow::before {
content: "▸";
color: grey;
}
.features details[open] > summary .arrow::before {
content: "▾";
}
.features details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-unfitted-level-2);
}
.features.fitted details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-fitted-level-2);
}
.features .features-container {
max-width: 15em;
max-height: 10em;
overflow: auto;
scrollbar-width: thin;
padding: .25em 0.1rem;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 0 0 .5em .5em;
}
.features.fitted .features-container {
background-color: var(--sklearn-color-fitted-level-0);
}
.features .image-container {
block-size: 1em;
inline-size: 1em;
padding: 0;
margin: 0%;
display: flex;
justify-content: center;
align-items: center;
}
.features .copy-paste-icon {
background-size: 1em 1em;
width: 1em;
height: 1em;
filter: grayscale(100%) opacity(60%);
}
.features .features-container table {
width: 100%;
margin: 0.01em;
}
.features .features-container table tr:nth-child(odd) {
background-color: #fff;
}
.features .features-container table tr:nth-child(even) {
background-color: #f6f6f6;
}
.features .features-container table tr:hover {
background-color: #e0e0e0;
}
.features .features-container table {
table-layout: inherit;
}
.features .features-container table td {
text-align: left;
padding: 0 0.5em;
border: 1px solid rgba(106, 105, 104, 0.232);
white-space: nowrap;
color: var(--sklearn-color-text);
}
.total_features {
display: flex;
justify-content: center;
margin-top: 0.5em;
}
</style><body><div id="sk-container-id-2" tabindex="0" class="sk-top-container sk-global"><div class="sk-text-repr-fallback"><pre>LogisticRegression(random_state=42)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually sk-global" id="sk-estimator-id-2" type="checkbox" checked><label for="sk-estimator-id-2" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
<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
* https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/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');</script></body>
```python
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](README_files/README_26_0.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.
```python
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)
```
<style>.sk-global {
/* Definition of color scheme common for light and dark mode */
--sklearn-color-text: #000;
--sklearn-color-text-muted: #666;
--sklearn-color-line: gray;
/* Definition of color scheme for unfitted estimators */
--sklearn-color-unfitted-level-0: #fff5e6;
--sklearn-color-unfitted-level-1: #f6e4d2;
--sklearn-color-unfitted-level-2: #ffe0b3;
--sklearn-color-unfitted-level-3: chocolate;
/* Definition of color scheme for fitted estimators */
--sklearn-color-fitted-level-0: #f0f8ff;
--sklearn-color-fitted-level-1: #d4ebff;
--sklearn-color-fitted-level-2: #b3dbfd;
--sklearn-color-fitted-level-3: cornflowerblue;
}
.sk-global.light {
/* Specific color for light theme */
--sklearn-color-text-on-default-background: black;
--sklearn-color-background: white;
--sklearn-color-border-box: black;
--sklearn-color-icon: #696969;
}
.sk-global.dark {
--sklearn-color-text-on-default-background: white;
--sklearn-color-background: #111;
--sklearn-color-border-box: white;
--sklearn-color-icon: #878787;
}
.sk-global {
color: var(--sklearn-color-text);
}
.sk-global pre {
padding: 0;
}
.sk-global input.sk-hidden--visually {
border: 0;
clip-path: inset(100%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.sk-global div.sk-dashed-wrapped {
border: 1px dashed var(--sklearn-color-line);
margin: 0 0.4em 0.5em 0.4em;
box-sizing: border-box;
padding-bottom: 0.4em;
background-color: var(--sklearn-color-background);
}
.sk-global div.sk-container {
/* jupyter's `normalize.less` sets `[hidden] { display: none; }`
but bootstrap.min.css set `[hidden] { display: none !important; }`
so we also need the `!important` here to be able to override the
default hidden behavior on the sphinx rendered scikit-learn.org.
See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
display: inline-block !important;
position: relative;
}
.sk-global div.sk-text-repr-fallback {
display: none;
}
div.sk-parallel-item,
div.sk-serial,
div.sk-item {
/* draw centered vertical line to link estimators */
background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
/* Parallel-specific style estimator block */
.sk-global div.sk-parallel-item::after {
content: "";
width: 100%;
border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
flex-grow: 1;
}
.sk-global div.sk-parallel {
display: flex;
align-items: stretch;
justify-content: center;
background-color: var(--sklearn-color-background);
position: relative;
}
.sk-global div.sk-parallel-item {
display: flex;
flex-direction: column;
}
.sk-global div.sk-parallel-item:first-child::after {
align-self: flex-end;
width: 50%;
}
.sk-global div.sk-parallel-item:last-child::after {
align-self: flex-start;
width: 50%;
}
.sk-global div.sk-parallel-item:only-child::after {
width: 0;
}
/* Serial-specific style estimator block */
.sk-global div.sk-serial {
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--sklearn-color-background);
padding-right: 1em;
padding-left: 1em;
}
/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/
/* Pipeline and ColumnTransformer style (default) */
.sk-global div.sk-toggleable {
/* Default theme specific background. It is overwritten whether we have a
specific estimator or a Pipeline/ColumnTransformer */
background-color: var(--sklearn-color-background);
}
/* Toggleable label */
.sk-global label.sk-toggleable__label {
cursor: pointer;
display: flex;
width: 100%;
margin-bottom: 0;
padding: 0.5em;
box-sizing: border-box;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
}
.sk-global label.sk-toggleable__label .caption {
font-size: 0.6rem;
font-weight: lighter;
color: var(--sklearn-color-text-muted);
}
.sk-global label.sk-toggleable__label-arrow:before {
/* Arrow on the left of the label */
content: "▸";
float: left;
margin-right: 0.25em;
color: var(--sklearn-color-icon);
}
.sk-global label.sk-toggleable__label-arrow:hover:before {
color: var(--sklearn-color-text);
}
/* Toggleable content - dropdown */
.sk-global div.sk-toggleable__content {
display: none;
text-align: left;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global div.sk-toggleable__content pre {
margin: 0.2em;
border-radius: 0.25em;
color: var(--sklearn-color-text);
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted pre {
/* unfitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global input.sk-toggleable__control:checked~div.sk-toggleable__content {
/* Expand drop-down */
display: block;
width: 100%;
overflow: visible;
}
.sk-global input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
content: "▾";
}
/* Pipeline/ColumnTransformer-specific style */
.sk-global div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator-specific style */
/* Colorize estimator box */
.sk-global div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
.sk-global div.sk-label label.sk-toggleable__label,
.sk-global div.sk-label label {
/* The background is the default theme color */
color: var(--sklearn-color-text-on-default-background);
}
/* On hover, darken the color of the background */
.sk-global div.sk-label:hover label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
/* Label box, darken color on hover, fitted */
.sk-global div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator label */
.sk-global div.sk-label label {
font-family: monospace;
font-weight: bold;
line-height: 1.2em;
}
.sk-global div.sk-label-container {
text-align: center;
}
/* Estimator-specific */
.sk-global div.sk-estimator {
font-family: monospace;
border: 1px dotted var(--sklearn-color-border-box);
border-radius: 0.25em;
box-sizing: border-box;
margin-bottom: 0.5em;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-estimator.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
/* on hover */
.sk-global div.sk-estimator:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
/* Specification for estimator info (e.g. "i" and "?") */
/* Common style for "i" and "?" */
.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
float: right;
font-size: smaller;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1em;
height: 1em;
width: 1em;
text-decoration: none !important;
margin-left: 0.5em;
text-align: center;
/* unfitted */
border: var(--sklearn-color-unfitted-level-3) 1pt solid;
color: var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3) 1pt solid;
color: var(--sklearn-color-fitted-level-3);
}
/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-unfitted-level-0);
text-decoration: none;
}
div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-fitted-level-0);
text-decoration: none;
}
/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
display: none;
z-index: 9999;
position: relative;
font-weight: normal;
right: .2ex;
padding: .5ex;
margin: .5ex;
width: min-content;
min-width: 20ex;
max-width: 50ex;
color: var(--sklearn-color-text);
box-shadow: 2pt 2pt 4pt #999;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: .5pt solid var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted span {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3);
}
.sk-estimator-doc-link:hover span {
display: block;
}
/* "?"-specific style due to the `<a>` HTML tag */
.sk-global a.estimator_doc_link {
float: right;
font-size: 1rem;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1rem;
height: 1rem;
width: 1rem;
text-decoration: none;
/* unfitted */
color: var(--sklearn-color-unfitted-level-1);
border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}
.sk-global a.estimator_doc_link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-1) 1pt solid;
color: var(--sklearn-color-fitted-level-1);
}
/* On hover */
.sk-global a.estimator_doc_link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
color: var(--sklearn-color-background);
text-decoration: none;
}
.sk-global a.estimator_doc_link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
}
.sk-top-container.sk-global {
/* pydata-sphinx-theme hides overflow, so scrolling is disabled.
We need to set it to !important and add tabindex="0" in the HTML
to allow keyboard-only users to navigate the display. */
overflow-x: scroll !important;
max-width: 100%;
}
.estimator-table {
font-family: monospace;
}
.estimator-table summary {
padding: .5rem;
cursor: pointer;
}
.estimator-table summary::marker {
font-size: 0.7rem;
}
.estimator-table details[open] {
padding-left: 0.1rem;
padding-right: 0.1rem;
padding-bottom: 0.3rem;
}
.estimator-table .parameters-table {
margin-left: auto !important;
margin-right: auto !important;
margin-top: 0;
}
.estimator-table .parameters-table tr:nth-child(odd) {
background-color: #fff;
}
.estimator-table .parameters-table tr:nth-child(even) {
background-color: #f6f6f6;
}
.estimator-table .parameters-table tr:hover td {
background-color: #e0e0e0;
}
.estimator-table table :is(td, th) {
border: 1px solid rgba(106, 105, 104, 0.232);
}
/*
`table td`is set in notebook with right text-align.
We need to overwrite it.
*/
.estimator-table table td.param {
text-align: left;
position: relative;
padding: 0;
}
.user-set td {
color:rgb(255, 94, 0);
text-align: left !important;
}
.user-set td.value {
color:rgb(255, 94, 0);
background-color: transparent;
}
.default td, .estimator-table th {
color: black;
text-align: left !important;
}
.user-set td i,
.default td i {
color: black;
}
td.fitted-att-type {
white-space: preserve nowrap;
}
/*
Styles for parameter documentation links
We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
text-decoration: underline dashed;
text-underline-offset: .3em;
color: inherit;
display: block;
padding: .5em;
}
@supports(anchor-name: --doc-link) {
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
anchor-name: --doc-link;
}
}
/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
position: absolute;
content: "";
inset: 0;
}
.param-doc-description {
display: none;
position: absolute;
z-index: 9999;
left: 0;
padding: .5ex;
margin-left: 1.5em;
color: var(--sklearn-color-text);
box-shadow: .3em .3em .4em #999;
width: max-content;
text-align: left;
max-height: 10em;
overflow-y: auto;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: thin solid var(--sklearn-color-unfitted-level-3);
}
@supports(position-area: center right) {
.param-doc-description {
position-area: center right;
position: fixed;
margin-left: 0;
}
}
/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: thin solid var(--sklearn-color-fitted-level-3);
}
.param-doc-link:hover .param-doc-description {
display: block;
}
.copy-paste-icon {
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
background-repeat: no-repeat;
background-size: 14px 14px;
background-position: 0;
display: inline-block;
width: 14px;
height: 14px;
cursor: pointer;
}
.features {
font-family: monospace;
cursor: pointer;
background-color: var(--sklearn-color-unfitted-level-0);
border: 1px dotted var(--sklearn-color-border-box);
border-radius: .20em;
margin-bottom: 0.5em;
font-size: inherit; /* Needed for jupyter */
}
.features.fitted {
background-color: var(--sklearn-color-fitted-level-0);
}
.features summary {
cursor: pointer;
display: flex;
margin-bottom: 0;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: .25em;
}
.features details[open] > summary {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
border-radius: .20em 0 0 0;
}
.features.fitted details[open] > summary {
background-color: var(--sklearn-color-fitted-level-2);
border-radius: .20em 0 0 0;
}
.features details > summary .arrow::before {
content: "▸";
color: grey;
}
.features details[open] > summary .arrow::before {
content: "▾";
}
.features details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-unfitted-level-2);
}
.features.fitted details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-fitted-level-2);
}
.features .features-container {
max-width: 15em;
max-height: 10em;
overflow: auto;
scrollbar-width: thin;
padding: .25em 0.1rem;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 0 0 .5em .5em;
}
.features.fitted .features-container {
background-color: var(--sklearn-color-fitted-level-0);
}
.features .image-container {
block-size: 1em;
inline-size: 1em;
padding: 0;
margin: 0%;
display: flex;
justify-content: center;
align-items: center;
}
.features .copy-paste-icon {
background-size: 1em 1em;
width: 1em;
height: 1em;
filter: grayscale(100%) opacity(60%);
}
.features .features-container table {
width: 100%;
margin: 0.01em;
}
.features .features-container table tr:nth-child(odd) {
background-color: #fff;
}
.features .features-container table tr:nth-child(even) {
background-color: #f6f6f6;
}
.features .features-container table tr:hover {
background-color: #e0e0e0;
}
.features .features-container table {
table-layout: inherit;
}
.features .features-container table td {
text-align: left;
padding: 0 0.5em;
border: 1px solid rgba(106, 105, 104, 0.232);
white-space: nowrap;
color: var(--sklearn-color-text);
}
.total_features {
display: flex;
justify-content: center;
margin-top: 0.5em;
}
</style><body><div id="sk-container-id-3" tabindex="0" class="sk-top-container sk-global"><div class="sk-text-repr-fallback"><pre>LogisticRegression(random_state=42)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually sk-global" id="sk-estimator-id-3" type="checkbox" checked><label for="sk-estimator-id-3" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
<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
* https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/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');</script></body>
```python
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](README_files/README_31_0.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.
```python
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](README_files/README_35_0.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.
```python
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)
```
<style>.sk-global {
/* Definition of color scheme common for light and dark mode */
--sklearn-color-text: #000;
--sklearn-color-text-muted: #666;
--sklearn-color-line: gray;
/* Definition of color scheme for unfitted estimators */
--sklearn-color-unfitted-level-0: #fff5e6;
--sklearn-color-unfitted-level-1: #f6e4d2;
--sklearn-color-unfitted-level-2: #ffe0b3;
--sklearn-color-unfitted-level-3: chocolate;
/* Definition of color scheme for fitted estimators */
--sklearn-color-fitted-level-0: #f0f8ff;
--sklearn-color-fitted-level-1: #d4ebff;
--sklearn-color-fitted-level-2: #b3dbfd;
--sklearn-color-fitted-level-3: cornflowerblue;
}
.sk-global.light {
/* Specific color for light theme */
--sklearn-color-text-on-default-background: black;
--sklearn-color-background: white;
--sklearn-color-border-box: black;
--sklearn-color-icon: #696969;
}
.sk-global.dark {
--sklearn-color-text-on-default-background: white;
--sklearn-color-background: #111;
--sklearn-color-border-box: white;
--sklearn-color-icon: #878787;
}
.sk-global {
color: var(--sklearn-color-text);
}
.sk-global pre {
padding: 0;
}
.sk-global input.sk-hidden--visually {
border: 0;
clip-path: inset(100%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.sk-global div.sk-dashed-wrapped {
border: 1px dashed var(--sklearn-color-line);
margin: 0 0.4em 0.5em 0.4em;
box-sizing: border-box;
padding-bottom: 0.4em;
background-color: var(--sklearn-color-background);
}
.sk-global div.sk-container {
/* jupyter's `normalize.less` sets `[hidden] { display: none; }`
but bootstrap.min.css set `[hidden] { display: none !important; }`
so we also need the `!important` here to be able to override the
default hidden behavior on the sphinx rendered scikit-learn.org.
See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
display: inline-block !important;
position: relative;
}
.sk-global div.sk-text-repr-fallback {
display: none;
}
div.sk-parallel-item,
div.sk-serial,
div.sk-item {
/* draw centered vertical line to link estimators */
background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
/* Parallel-specific style estimator block */
.sk-global div.sk-parallel-item::after {
content: "";
width: 100%;
border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
flex-grow: 1;
}
.sk-global div.sk-parallel {
display: flex;
align-items: stretch;
justify-content: center;
background-color: var(--sklearn-color-background);
position: relative;
}
.sk-global div.sk-parallel-item {
display: flex;
flex-direction: column;
}
.sk-global div.sk-parallel-item:first-child::after {
align-self: flex-end;
width: 50%;
}
.sk-global div.sk-parallel-item:last-child::after {
align-self: flex-start;
width: 50%;
}
.sk-global div.sk-parallel-item:only-child::after {
width: 0;
}
/* Serial-specific style estimator block */
.sk-global div.sk-serial {
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--sklearn-color-background);
padding-right: 1em;
padding-left: 1em;
}
/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/
/* Pipeline and ColumnTransformer style (default) */
.sk-global div.sk-toggleable {
/* Default theme specific background. It is overwritten whether we have a
specific estimator or a Pipeline/ColumnTransformer */
background-color: var(--sklearn-color-background);
}
/* Toggleable label */
.sk-global label.sk-toggleable__label {
cursor: pointer;
display: flex;
width: 100%;
margin-bottom: 0;
padding: 0.5em;
box-sizing: border-box;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
}
.sk-global label.sk-toggleable__label .caption {
font-size: 0.6rem;
font-weight: lighter;
color: var(--sklearn-color-text-muted);
}
.sk-global label.sk-toggleable__label-arrow:before {
/* Arrow on the left of the label */
content: "▸";
float: left;
margin-right: 0.25em;
color: var(--sklearn-color-icon);
}
.sk-global label.sk-toggleable__label-arrow:hover:before {
color: var(--sklearn-color-text);
}
/* Toggleable content - dropdown */
.sk-global div.sk-toggleable__content {
display: none;
text-align: left;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global div.sk-toggleable__content pre {
margin: 0.2em;
border-radius: 0.25em;
color: var(--sklearn-color-text);
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted pre {
/* unfitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global input.sk-toggleable__control:checked~div.sk-toggleable__content {
/* Expand drop-down */
display: block;
width: 100%;
overflow: visible;
}
.sk-global input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
content: "▾";
}
/* Pipeline/ColumnTransformer-specific style */
.sk-global div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator-specific style */
/* Colorize estimator box */
.sk-global div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
.sk-global div.sk-label label.sk-toggleable__label,
.sk-global div.sk-label label {
/* The background is the default theme color */
color: var(--sklearn-color-text-on-default-background);
}
/* On hover, darken the color of the background */
.sk-global div.sk-label:hover label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
/* Label box, darken color on hover, fitted */
.sk-global div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator label */
.sk-global div.sk-label label {
font-family: monospace;
font-weight: bold;
line-height: 1.2em;
}
.sk-global div.sk-label-container {
text-align: center;
}
/* Estimator-specific */
.sk-global div.sk-estimator {
font-family: monospace;
border: 1px dotted var(--sklearn-color-border-box);
border-radius: 0.25em;
box-sizing: border-box;
margin-bottom: 0.5em;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-estimator.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
/* on hover */
.sk-global div.sk-estimator:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
/* Specification for estimator info (e.g. "i" and "?") */
/* Common style for "i" and "?" */
.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
float: right;
font-size: smaller;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1em;
height: 1em;
width: 1em;
text-decoration: none !important;
margin-left: 0.5em;
text-align: center;
/* unfitted */
border: var(--sklearn-color-unfitted-level-3) 1pt solid;
color: var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3) 1pt solid;
color: var(--sklearn-color-fitted-level-3);
}
/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-unfitted-level-0);
text-decoration: none;
}
div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-fitted-level-0);
text-decoration: none;
}
/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
display: none;
z-index: 9999;
position: relative;
font-weight: normal;
right: .2ex;
padding: .5ex;
margin: .5ex;
width: min-content;
min-width: 20ex;
max-width: 50ex;
color: var(--sklearn-color-text);
box-shadow: 2pt 2pt 4pt #999;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: .5pt solid var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted span {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3);
}
.sk-estimator-doc-link:hover span {
display: block;
}
/* "?"-specific style due to the `<a>` HTML tag */
.sk-global a.estimator_doc_link {
float: right;
font-size: 1rem;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1rem;
height: 1rem;
width: 1rem;
text-decoration: none;
/* unfitted */
color: var(--sklearn-color-unfitted-level-1);
border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}
.sk-global a.estimator_doc_link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-1) 1pt solid;
color: var(--sklearn-color-fitted-level-1);
}
/* On hover */
.sk-global a.estimator_doc_link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
color: var(--sklearn-color-background);
text-decoration: none;
}
.sk-global a.estimator_doc_link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
}
.sk-top-container.sk-global {
/* pydata-sphinx-theme hides overflow, so scrolling is disabled.
We need to set it to !important and add tabindex="0" in the HTML
to allow keyboard-only users to navigate the display. */
overflow-x: scroll !important;
max-width: 100%;
}
.estimator-table {
font-family: monospace;
}
.estimator-table summary {
padding: .5rem;
cursor: pointer;
}
.estimator-table summary::marker {
font-size: 0.7rem;
}
.estimator-table details[open] {
padding-left: 0.1rem;
padding-right: 0.1rem;
padding-bottom: 0.3rem;
}
.estimator-table .parameters-table {
margin-left: auto !important;
margin-right: auto !important;
margin-top: 0;
}
.estimator-table .parameters-table tr:nth-child(odd) {
background-color: #fff;
}
.estimator-table .parameters-table tr:nth-child(even) {
background-color: #f6f6f6;
}
.estimator-table .parameters-table tr:hover td {
background-color: #e0e0e0;
}
.estimator-table table :is(td, th) {
border: 1px solid rgba(106, 105, 104, 0.232);
}
/*
`table td`is set in notebook with right text-align.
We need to overwrite it.
*/
.estimator-table table td.param {
text-align: left;
position: relative;
padding: 0;
}
.user-set td {
color:rgb(255, 94, 0);
text-align: left !important;
}
.user-set td.value {
color:rgb(255, 94, 0);
background-color: transparent;
}
.default td, .estimator-table th {
color: black;
text-align: left !important;
}
.user-set td i,
.default td i {
color: black;
}
td.fitted-att-type {
white-space: preserve nowrap;
}
/*
Styles for parameter documentation links
We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
text-decoration: underline dashed;
text-underline-offset: .3em;
color: inherit;
display: block;
padding: .5em;
}
@supports(anchor-name: --doc-link) {
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
anchor-name: --doc-link;
}
}
/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
position: absolute;
content: "";
inset: 0;
}
.param-doc-description {
display: none;
position: absolute;
z-index: 9999;
left: 0;
padding: .5ex;
margin-left: 1.5em;
color: var(--sklearn-color-text);
box-shadow: .3em .3em .4em #999;
width: max-content;
text-align: left;
max-height: 10em;
overflow-y: auto;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: thin solid var(--sklearn-color-unfitted-level-3);
}
@supports(position-area: center right) {
.param-doc-description {
position-area: center right;
position: fixed;
margin-left: 0;
}
}
/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: thin solid var(--sklearn-color-fitted-level-3);
}
.param-doc-link:hover .param-doc-description {
display: block;
}
.copy-paste-icon {
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
background-repeat: no-repeat;
background-size: 14px 14px;
background-position: 0;
display: inline-block;
width: 14px;
height: 14px;
cursor: pointer;
}
.features {
font-family: monospace;
cursor: pointer;
background-color: var(--sklearn-color-unfitted-level-0);
border: 1px dotted var(--sklearn-color-border-box);
border-radius: .20em;
margin-bottom: 0.5em;
font-size: inherit; /* Needed for jupyter */
}
.features.fitted {
background-color: var(--sklearn-color-fitted-level-0);
}
.features summary {
cursor: pointer;
display: flex;
margin-bottom: 0;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: .25em;
}
.features details[open] > summary {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
border-radius: .20em 0 0 0;
}
.features.fitted details[open] > summary {
background-color: var(--sklearn-color-fitted-level-2);
border-radius: .20em 0 0 0;
}
.features details > summary .arrow::before {
content: "▸";
color: grey;
}
.features details[open] > summary .arrow::before {
content: "▾";
}
.features details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-unfitted-level-2);
}
.features.fitted details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-fitted-level-2);
}
.features .features-container {
max-width: 15em;
max-height: 10em;
overflow: auto;
scrollbar-width: thin;
padding: .25em 0.1rem;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 0 0 .5em .5em;
}
.features.fitted .features-container {
background-color: var(--sklearn-color-fitted-level-0);
}
.features .image-container {
block-size: 1em;
inline-size: 1em;
padding: 0;
margin: 0%;
display: flex;
justify-content: center;
align-items: center;
}
.features .copy-paste-icon {
background-size: 1em 1em;
width: 1em;
height: 1em;
filter: grayscale(100%) opacity(60%);
}
.features .features-container table {
width: 100%;
margin: 0.01em;
}
.features .features-container table tr:nth-child(odd) {
background-color: #fff;
}
.features .features-container table tr:nth-child(even) {
background-color: #f6f6f6;
}
.features .features-container table tr:hover {
background-color: #e0e0e0;
}
.features .features-container table {
table-layout: inherit;
}
.features .features-container table td {
text-align: left;
padding: 0 0.5em;
border: 1px solid rgba(106, 105, 104, 0.232);
white-space: nowrap;
color: var(--sklearn-color-text);
}
.total_features {
display: flex;
justify-content: center;
margin-top: 0.5em;
}
</style><body><div id="sk-container-id-4" tabindex="0" class="sk-top-container sk-global"><div class="sk-text-repr-fallback"><pre>LogisticRegression(C=100, random_state=22, solver=&#x27;newton-cg&#x27;, tol=1e-05)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually sk-global" id="sk-estimator-id-4" type="checkbox" checked><label for="sk-estimator-id-4" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
<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
* https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/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');</script></body>
#### 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.
```python
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)
```
```python
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](README_files/README_40_0.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.
```python
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](README_files/README_42_1.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.
```python
X = iris.data[:,0:2]
y = iris.target
lrmc = LogisticRegression(
solver='lbfgs',
C=100,
random_state=22
)
lrmc.fit(X,y)
```
<style>.sk-global {
/* Definition of color scheme common for light and dark mode */
--sklearn-color-text: #000;
--sklearn-color-text-muted: #666;
--sklearn-color-line: gray;
/* Definition of color scheme for unfitted estimators */
--sklearn-color-unfitted-level-0: #fff5e6;
--sklearn-color-unfitted-level-1: #f6e4d2;
--sklearn-color-unfitted-level-2: #ffe0b3;
--sklearn-color-unfitted-level-3: chocolate;
/* Definition of color scheme for fitted estimators */
--sklearn-color-fitted-level-0: #f0f8ff;
--sklearn-color-fitted-level-1: #d4ebff;
--sklearn-color-fitted-level-2: #b3dbfd;
--sklearn-color-fitted-level-3: cornflowerblue;
}
.sk-global.light {
/* Specific color for light theme */
--sklearn-color-text-on-default-background: black;
--sklearn-color-background: white;
--sklearn-color-border-box: black;
--sklearn-color-icon: #696969;
}
.sk-global.dark {
--sklearn-color-text-on-default-background: white;
--sklearn-color-background: #111;
--sklearn-color-border-box: white;
--sklearn-color-icon: #878787;
}
.sk-global {
color: var(--sklearn-color-text);
}
.sk-global pre {
padding: 0;
}
.sk-global input.sk-hidden--visually {
border: 0;
clip-path: inset(100%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.sk-global div.sk-dashed-wrapped {
border: 1px dashed var(--sklearn-color-line);
margin: 0 0.4em 0.5em 0.4em;
box-sizing: border-box;
padding-bottom: 0.4em;
background-color: var(--sklearn-color-background);
}
.sk-global div.sk-container {
/* jupyter's `normalize.less` sets `[hidden] { display: none; }`
but bootstrap.min.css set `[hidden] { display: none !important; }`
so we also need the `!important` here to be able to override the
default hidden behavior on the sphinx rendered scikit-learn.org.
See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
display: inline-block !important;
position: relative;
}
.sk-global div.sk-text-repr-fallback {
display: none;
}
div.sk-parallel-item,
div.sk-serial,
div.sk-item {
/* draw centered vertical line to link estimators */
background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
/* Parallel-specific style estimator block */
.sk-global div.sk-parallel-item::after {
content: "";
width: 100%;
border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
flex-grow: 1;
}
.sk-global div.sk-parallel {
display: flex;
align-items: stretch;
justify-content: center;
background-color: var(--sklearn-color-background);
position: relative;
}
.sk-global div.sk-parallel-item {
display: flex;
flex-direction: column;
}
.sk-global div.sk-parallel-item:first-child::after {
align-self: flex-end;
width: 50%;
}
.sk-global div.sk-parallel-item:last-child::after {
align-self: flex-start;
width: 50%;
}
.sk-global div.sk-parallel-item:only-child::after {
width: 0;
}
/* Serial-specific style estimator block */
.sk-global div.sk-serial {
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--sklearn-color-background);
padding-right: 1em;
padding-left: 1em;
}
/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/
/* Pipeline and ColumnTransformer style (default) */
.sk-global div.sk-toggleable {
/* Default theme specific background. It is overwritten whether we have a
specific estimator or a Pipeline/ColumnTransformer */
background-color: var(--sklearn-color-background);
}
/* Toggleable label */
.sk-global label.sk-toggleable__label {
cursor: pointer;
display: flex;
width: 100%;
margin-bottom: 0;
padding: 0.5em;
box-sizing: border-box;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
}
.sk-global label.sk-toggleable__label .caption {
font-size: 0.6rem;
font-weight: lighter;
color: var(--sklearn-color-text-muted);
}
.sk-global label.sk-toggleable__label-arrow:before {
/* Arrow on the left of the label */
content: "▸";
float: left;
margin-right: 0.25em;
color: var(--sklearn-color-icon);
}
.sk-global label.sk-toggleable__label-arrow:hover:before {
color: var(--sklearn-color-text);
}
/* Toggleable content - dropdown */
.sk-global div.sk-toggleable__content {
display: none;
text-align: left;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global div.sk-toggleable__content pre {
margin: 0.2em;
border-radius: 0.25em;
color: var(--sklearn-color-text);
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-toggleable__content.fitted pre {
/* unfitted */
background-color: var(--sklearn-color-fitted-level-0);
}
.sk-global input.sk-toggleable__control:checked~div.sk-toggleable__content {
/* Expand drop-down */
display: block;
width: 100%;
overflow: visible;
}
.sk-global input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
content: "▾";
}
/* Pipeline/ColumnTransformer-specific style */
.sk-global div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator-specific style */
/* Colorize estimator box */
.sk-global div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
.sk-global div.sk-label label.sk-toggleable__label,
.sk-global div.sk-label label {
/* The background is the default theme color */
color: var(--sklearn-color-text-on-default-background);
}
/* On hover, darken the color of the background */
.sk-global div.sk-label:hover label.sk-toggleable__label {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
}
/* Label box, darken color on hover, fitted */
.sk-global div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-fitted-level-2);
}
/* Estimator label */
.sk-global div.sk-label label {
font-family: monospace;
font-weight: bold;
line-height: 1.2em;
}
.sk-global div.sk-label-container {
text-align: center;
}
/* Estimator-specific */
.sk-global div.sk-estimator {
font-family: monospace;
border: 1px dotted var(--sklearn-color-border-box);
border-radius: 0.25em;
box-sizing: border-box;
margin-bottom: 0.5em;
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-0);
}
.sk-global div.sk-estimator.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
}
/* on hover */
.sk-global div.sk-estimator:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-2);
}
.sk-global div.sk-estimator.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-2);
}
/* Specification for estimator info (e.g. "i" and "?") */
/* Common style for "i" and "?" */
.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
float: right;
font-size: smaller;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1em;
height: 1em;
width: 1em;
text-decoration: none !important;
margin-left: 0.5em;
text-align: center;
/* unfitted */
border: var(--sklearn-color-unfitted-level-3) 1pt solid;
color: var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3) 1pt solid;
color: var(--sklearn-color-fitted-level-3);
}
/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-unfitted-level-0);
text-decoration: none;
}
div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
border: var(--sklearn-color-fitted-level-0) 1pt solid;
color: var(--sklearn-color-fitted-level-0);
text-decoration: none;
}
/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
display: none;
z-index: 9999;
position: relative;
font-weight: normal;
right: .2ex;
padding: .5ex;
margin: .5ex;
width: min-content;
min-width: 20ex;
max-width: 50ex;
color: var(--sklearn-color-text);
box-shadow: 2pt 2pt 4pt #999;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: .5pt solid var(--sklearn-color-unfitted-level-3);
}
.sk-estimator-doc-link.fitted span {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-3);
}
.sk-estimator-doc-link:hover span {
display: block;
}
/* "?"-specific style due to the `<a>` HTML tag */
.sk-global a.estimator_doc_link {
float: right;
font-size: 1rem;
line-height: 1em;
font-family: monospace;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 1rem;
height: 1rem;
width: 1rem;
text-decoration: none;
/* unfitted */
color: var(--sklearn-color-unfitted-level-1);
border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}
.sk-global a.estimator_doc_link.fitted {
/* fitted */
background-color: var(--sklearn-color-fitted-level-0);
border: var(--sklearn-color-fitted-level-1) 1pt solid;
color: var(--sklearn-color-fitted-level-1);
}
/* On hover */
.sk-global a.estimator_doc_link:hover {
/* unfitted */
background-color: var(--sklearn-color-unfitted-level-3);
color: var(--sklearn-color-background);
text-decoration: none;
}
.sk-global a.estimator_doc_link.fitted:hover {
/* fitted */
background-color: var(--sklearn-color-fitted-level-3);
}
.sk-top-container.sk-global {
/* pydata-sphinx-theme hides overflow, so scrolling is disabled.
We need to set it to !important and add tabindex="0" in the HTML
to allow keyboard-only users to navigate the display. */
overflow-x: scroll !important;
max-width: 100%;
}
.estimator-table {
font-family: monospace;
}
.estimator-table summary {
padding: .5rem;
cursor: pointer;
}
.estimator-table summary::marker {
font-size: 0.7rem;
}
.estimator-table details[open] {
padding-left: 0.1rem;
padding-right: 0.1rem;
padding-bottom: 0.3rem;
}
.estimator-table .parameters-table {
margin-left: auto !important;
margin-right: auto !important;
margin-top: 0;
}
.estimator-table .parameters-table tr:nth-child(odd) {
background-color: #fff;
}
.estimator-table .parameters-table tr:nth-child(even) {
background-color: #f6f6f6;
}
.estimator-table .parameters-table tr:hover td {
background-color: #e0e0e0;
}
.estimator-table table :is(td, th) {
border: 1px solid rgba(106, 105, 104, 0.232);
}
/*
`table td`is set in notebook with right text-align.
We need to overwrite it.
*/
.estimator-table table td.param {
text-align: left;
position: relative;
padding: 0;
}
.user-set td {
color:rgb(255, 94, 0);
text-align: left !important;
}
.user-set td.value {
color:rgb(255, 94, 0);
background-color: transparent;
}
.default td, .estimator-table th {
color: black;
text-align: left !important;
}
.user-set td i,
.default td i {
color: black;
}
td.fitted-att-type {
white-space: preserve nowrap;
}
/*
Styles for parameter documentation links
We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
text-decoration: underline dashed;
text-underline-offset: .3em;
color: inherit;
display: block;
padding: .5em;
}
@supports(anchor-name: --doc-link) {
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
anchor-name: --doc-link;
}
}
/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
position: absolute;
content: "";
inset: 0;
}
.param-doc-description {
display: none;
position: absolute;
z-index: 9999;
left: 0;
padding: .5ex;
margin-left: 1.5em;
color: var(--sklearn-color-text);
box-shadow: .3em .3em .4em #999;
width: max-content;
text-align: left;
max-height: 10em;
overflow-y: auto;
/* unfitted */
background: var(--sklearn-color-unfitted-level-0);
border: thin solid var(--sklearn-color-unfitted-level-3);
}
@supports(position-area: center right) {
.param-doc-description {
position-area: center right;
position: fixed;
margin-left: 0;
}
}
/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
/* fitted */
background: var(--sklearn-color-fitted-level-0);
border: thin solid var(--sklearn-color-fitted-level-3);
}
.param-doc-link:hover .param-doc-description {
display: block;
}
.copy-paste-icon {
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
background-repeat: no-repeat;
background-size: 14px 14px;
background-position: 0;
display: inline-block;
width: 14px;
height: 14px;
cursor: pointer;
}
.features {
font-family: monospace;
cursor: pointer;
background-color: var(--sklearn-color-unfitted-level-0);
border: 1px dotted var(--sklearn-color-border-box);
border-radius: .20em;
margin-bottom: 0.5em;
font-size: inherit; /* Needed for jupyter */
}
.features.fitted {
background-color: var(--sklearn-color-fitted-level-0);
}
.features summary {
cursor: pointer;
display: flex;
margin-bottom: 0;
text-align: center;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: .25em;
}
.features details[open] > summary {
color: var(--sklearn-color-text);
background-color: var(--sklearn-color-unfitted-level-2);
border-radius: .20em 0 0 0;
}
.features.fitted details[open] > summary {
background-color: var(--sklearn-color-fitted-level-2);
border-radius: .20em 0 0 0;
}
.features details > summary .arrow::before {
content: "▸";
color: grey;
}
.features details[open] > summary .arrow::before {
content: "▾";
}
.features details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-unfitted-level-2);
}
.features.fitted details:hover > summary {
margin: 0;
background-color: var(--sklearn-color-fitted-level-2);
}
.features .features-container {
max-width: 15em;
max-height: 10em;
overflow: auto;
scrollbar-width: thin;
padding: .25em 0.1rem;
background-color: var(--sklearn-color-unfitted-level-0);
border-radius: 0 0 .5em .5em;
}
.features.fitted .features-container {
background-color: var(--sklearn-color-fitted-level-0);
}
.features .image-container {
block-size: 1em;
inline-size: 1em;
padding: 0;
margin: 0%;
display: flex;
justify-content: center;
align-items: center;
}
.features .copy-paste-icon {
background-size: 1em 1em;
width: 1em;
height: 1em;
filter: grayscale(100%) opacity(60%);
}
.features .features-container table {
width: 100%;
margin: 0.01em;
}
.features .features-container table tr:nth-child(odd) {
background-color: #fff;
}
.features .features-container table tr:nth-child(even) {
background-color: #f6f6f6;
}
.features .features-container table tr:hover {
background-color: #e0e0e0;
}
.features .features-container table {
table-layout: inherit;
}
.features .features-container table td {
text-align: left;
padding: 0 0.5em;
border: 1px solid rgba(106, 105, 104, 0.232);
white-space: nowrap;
color: var(--sklearn-color-text);
}
.total_features {
display: flex;
justify-content: center;
margin-top: 0.5em;
}
</style><body><div id="sk-container-id-5" tabindex="0" class="sk-top-container sk-global"><div class="sk-text-repr-fallback"><pre>LogisticRegression(C=100, random_state=22)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually sk-global" id="sk-estimator-id-5" type="checkbox" checked><label for="sk-estimator-id-5" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
<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]]</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](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
* https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/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');</script></body>
#### 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.
```python
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)
```
```python
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](README_files/README_49_0.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.
```python
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](README_files/README_51_0.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.
```python
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](README_files/README_53_1.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.