# With scikit-learn pipelines

A `mlfeatures` recipe handles data preprocessing and feature engineering; the model that consumes those features often lives downstream in [scikit-learn](https://scikit-learn.org/). The [RecipeTransformer](../reference/RecipeTransformer.md#mlfeatures.RecipeTransformer) adapter bridges the two: it wraps a recipe so it behaves like any other scikit-learn transformer and drops straight into a `sklearn.pipeline.Pipeline`.


# The adapter

[RecipeTransformer](../reference/RecipeTransformer.md#mlfeatures.RecipeTransformer) wraps an *unfitted* recipe. It exposes the familiar scikit-learn [fit](../reference/Step.fit.md#mlfeatures.Step.fit) / [transform](../reference/Step.transform.md#mlfeatures.Step.transform) / `fit_transform` methods, so the recipe's `specify → fit → transform` lifecycle is driven by the pipeline rather than by hand.


``` python
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

X, y = load_breast_cancer(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
X_train.iloc[:5, :3]
```


|     | mean radius | mean texture | mean perimeter |
|-----|-------------|--------------|----------------|
| 293 | 11.85       | 17.46        | 75.54          |
| 332 | 11.22       | 19.86        | 71.94          |
| 565 | 20.13       | 28.25        | 131.20         |
| 278 | 13.59       | 17.84        | 86.24          |
| 489 | 16.69       | 20.20        | 107.10         |


scikit-learn keeps the features `X` and the target `y` apart, while `mlfeatures` identifies the target by its **role**. Build the recipe with the target role assigned; the adapter re-joins `y` onto `X` under that name at fit time and strips it back out of the transformed output, so [transform](../reference/Step.transform.md#mlfeatures.Step.transform) returns the feature matrix only.


``` python
from mlfeatures import Recipe, StepNormalize
from mlfeatures import Selectors as s

recipe = (
    Recipe(data=X_train.assign(target=y_train), target="target")
    .add(StepNormalize(s.numeric_features()))
)
```


# Inside a `Pipeline`

Wrap the recipe in [RecipeTransformer](../reference/RecipeTransformer.md#mlfeatures.RecipeTransformer) and place it ahead of an estimator. The pipeline's [fit](../reference/Step.fit.md#mlfeatures.Step.fit) flows `X`/`y` through the recipe, then fits the model on the engineered features:


``` python
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline

from mlfeatures import RecipeTransformer

pipe = Pipeline(
    [
        ("recipe", RecipeTransformer(recipe)),
        ("model", LogisticRegression(max_iter=1000)),
    ]
)
pipe.fit(X_train, y_train)
pipe.score(X_test, y_test)
```


    0.958041958041958


The statistics the recipe estimated (here the means and standard deviations) come from the training data only, and the test data is transformed with them.

Displaying the fitted pipeline renders scikit-learn's diagram. The recipe shows up as a labelled `RecipeTransformer (trained)` block that expands to the recipe and its steps:


``` python
pipe
```


<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>


    Pipeline(steps=[('recipe',
                     RecipeTransformer(recipe=Recipe (untrained)
      Inputs: 31 columns (1 target)
      Steps:
        step_normalize(select(role='feature', type=NumericType))  [untrained])),
                    ('model', LogisticRegression(max_iter=1000))])

**In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.\
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.**


Pipeline


<a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html" class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank">?<span>Documentation for Pipeline</span></a>iFitted


Parameters

<table class="parameters-table">
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<tbody>
<tr class="user-set">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=steps,-list%20of%20tuples" class="param-doc-link" style="anchor-name: --doc-link-steps;" rel="noreferrer" target="_blank">steps <span class="param-doc-description" style="position-anchor: --doc-link-steps;"> steps: list of tuples<br />
<br />
List of (name of step, estimator) tuples that are to be chained in<br />
sequential order. To be compatible with the scikit-learn API, all steps<br />
must define `fit`. All non-last steps must also define `transform`. See<br />
:ref:`Combining Estimators <combining_estimators>` for more details.</span></a></td>
<td class="value">[('recipe', ...), ('model', ...)]</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=transform_input,-list%20of%20str%2C%20default%3DNone" class="param-doc-link" style="anchor-name: --doc-link-transform_input;" rel="noreferrer" target="_blank">transform_input <span class="param-doc-description" style="position-anchor: --doc-link-transform_input;"> transform_input: list of str, default=None<br />
<br />
The names of the :term:`metadata` parameters that should be transformed by the<br />
pipeline before passing it to the step consuming it.<br />
<br />
This enables transforming some input arguments to ``fit`` (other than ``X``)<br />
to be transformed by the steps of the pipeline up to the step which requires<br />
them. Requirement is defined via :ref:`metadata routing <metadata_routing>`.<br />
For instance, this can be used to pass a validation set through the pipeline.<br />
<br />
You can only set this if metadata routing is enabled, which you<br />
can enable using ``sklearn.set_config(enable_metadata_routing=True)``.<br />
<br />
.. versionadded:: 1.6</span></a></td>
<td class="value">None</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=memory,-str%20or%20object%20with%20the%20joblib.Memory%20interface%2C%20default%3DNone" class="param-doc-link" style="anchor-name: --doc-link-memory;" rel="noreferrer" target="_blank">memory <span class="param-doc-description" style="position-anchor: --doc-link-memory;"> memory: str or object with the joblib.Memory interface, default=None<br />
<br />
Used to cache the fitted transformers of the pipeline. The last step<br />
will never be cached, even if it is a transformer. By default, no<br />
caching is performed. If a string is given, it is the path to the<br />
caching directory. Enabling caching triggers a clone of the transformers<br />
before fitting. Therefore, the transformer instance given to the<br />
pipeline cannot be inspected directly. Use the attribute ``named_steps``<br />
or ``steps`` to inspect estimators within the pipeline. Caching the<br />
transformers is advantageous when fitting is time consuming. See<br />
:ref:`sphx_glr_auto_examples_neighbors_plot_caching_nearest_neighbors.py`<br />
for an example on how to enable caching.</span></a></td>
<td class="value">None</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=verbose,-bool%2C%20default%3DFalse" class="param-doc-link" style="anchor-name: --doc-link-verbose;" rel="noreferrer" target="_blank">verbose <span class="param-doc-description" style="position-anchor: --doc-link-verbose;"> verbose: bool, default=False<br />
<br />
If True, the time elapsed while fitting each step will be printed as it<br />
is completed.</span></a></td>
<td class="value">False</td>
</tr>
</tbody>
</table>


Fitted attributes

<table class="parameters-table">
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<tbody>
<tr>
<th>Name</th>
<th>Type</th>
<th>Value</th>
</tr>

<tr class="default">
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=classes_,-ndarray%20of%20shape%20%28n_classes%2C%29" class="param-doc-link" style="anchor-name: --doc-link-classes_;" rel="noreferrer" target="_blank">classes_ <span class="param-doc-description" style="position-anchor: --doc-link-classes_;"> classes_: ndarray of shape (n_classes,)<br />
<br />
The classes labels. Only exist if the last step of the pipeline is a<br />
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 href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=feature_names_in_,-ndarray%20of%20shape%20%28n_features_in_%2C%29" class="param-doc-link" style="anchor-name: --doc-link-feature_names_in_;" rel="noreferrer" target="_blank">feature_names_in_ <span class="param-doc-description" style="position-anchor: --doc-link-feature_names_in_;"> feature_names_in_: ndarray of shape (`n_features_in_`,)<br />
<br />
Names of features seen during :term:`fit`. Only defined if the<br />
underlying estimator exposes such an attribute when fit.<br />
<br />
.. versionadded:: 1.0</span></a></td>
<td class="fitted-att-type">list</td>
<td>['me...us', 'me...re', 'me...er', 'me...ea', ...]</td>
</tr>
<tr class="default">
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.pipeline.Pipeline.html#:~:text=n_features_in_,-int" class="param-doc-link" style="anchor-name: --doc-link-n_features_in_;" rel="noreferrer" target="_blank">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`. Only defined if the<br />
underlying first estimator in `steps` exposes such an attribute<br />
when fit.<br />
<br />
.. versionadded:: 0.24</span></a></td>
<td class="fitted-att-type">int</td>
<td>30</td>
</tr>
</tbody>
</table>


RecipeTransformer (trained)


Parameters

|     |        |                                 |
|-----|--------|---------------------------------|
|     | recipe | Recipe (untra...) \[untrained\] |


Fitted attributes

|  |  |  |
|----|----|----|
| Name | Type | Value |
| <span class="param-doc-link" style="text-decoration:none;">feature_names_in\_</span> | list | \['me...us', 'me...re', 'me...er', 'me...ea', ...\] |
| <span class="param-doc-link" style="text-decoration:none;">feature_names_out\_</span> | list | \['me...us', 'me...re', 'me...er', 'me...ea', ...\] |
| <span class="param-doc-link" style="text-decoration:none;">fitted\_</span> | FittedRecipe | Recipe (train...on) \[trained\] |
| <span class="param-doc-link" style="text-decoration:none;">n_features_in\_</span> | int | 30 |


30 features


|                         |
|-------------------------|
| mean radius             |
| mean texture            |
| mean perimeter          |
| mean area               |
| mean smoothness         |
| mean compactness        |
| mean concavity          |
| mean concave points     |
| mean symmetry           |
| mean fractal dimension  |
| radius error            |
| texture error           |
| perimeter error         |
| area error              |
| smoothness error        |
| compactness error       |
| concavity error         |
| concave points error    |
| symmetry error          |
| fractal dimension error |
| worst radius            |
| worst texture           |
| worst perimeter         |
| worst area              |
| worst smoothness        |
| worst compactness       |
| worst concavity         |
| worst concave points    |
| worst symmetry          |
| worst fractal dimension |


LogisticRegression


<a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html" class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank">?<span>Documentation for LogisticRegression</span></a>


Parameters

<table class="parameters-table">
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<tbody>
<tr class="user-set">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100" class="param-doc-link" style="anchor-name: --doc-link-max_iter;" rel="noreferrer" target="_blank">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">1000</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a 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" class="param-doc-link" style="anchor-name: --doc-link-penalty;" rel="noreferrer" target="_blank">penalty <span class="param-doc-description" style="position-anchor: --doc-link-penalty;"> penalty: {'l1', 'l2', 'elasticnet', None}, default='l2'<br />
<br />
Specify the norm of the penalty:<br />
<br />
- `None`: no penalty is added;<br />
- `'l2'`: add an L2 penalty term and it is the default choice;<br />
- `'l1'`: add an L1 penalty term;<br />
- `'elasticnet'`: 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 'multinomial' + 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='l2'`,<br />
`l1_ratio=1` for `penalty='l1'`, `l1_ratio` set to any float between 0 and 1<br />
for `penalty='elasticnet'`, and `C=np.inf` for `penalty=None`.</span></a></td>
<td class="value">'deprecated'</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0" class="param-doc-link" style="anchor-name: --doc-link-C;" rel="noreferrer" target="_blank">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><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0" class="param-doc-link" style="anchor-name: --doc-link-l1_ratio;" rel="noreferrer" target="_blank">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 <= l1_ratio <= 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><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse" class="param-doc-link" style="anchor-name: --doc-link-dual;" rel="noreferrer" target="_blank">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 <regularized-logistic-loss>`) formulation. Dual formulation<br />
is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br />
when n_samples > n_features.</span></a></td>
<td class="value">False</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4" class="param-doc-link" style="anchor-name: --doc-link-tol;" rel="noreferrer" target="_blank">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><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue" class="param-doc-link" style="anchor-name: --doc-link-fit_intercept;" rel="noreferrer" target="_blank">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><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1" class="param-doc-link" style="anchor-name: --doc-link-intercept_scaling;" rel="noreferrer" target="_blank">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 "synthetic" 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><em></em></td>
<td class="param"><a 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="param-doc-link" style="anchor-name: --doc-link-class_weight;" rel="noreferrer" target="_blank">class_weight <span class="param-doc-description" style="position-anchor: --doc-link-class_weight;"> class_weight: dict or 'balanced', 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 "balanced" 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='balanced'*</span></a></td>
<td class="value">None</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone" class="param-doc-link" style="anchor-name: --doc-link-random_state;" rel="noreferrer" target="_blank">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`` == 'sag', 'saga' or 'liblinear' to shuffle the<br />
data. See :term:`Glossary <random_state>` for details.</span></a></td>
<td class="value">None</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a 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" class="param-doc-link" style="anchor-name: --doc-link-solver;" rel="noreferrer" target="_blank">solver <span class="param-doc-description" style="position-anchor: --doc-link-solver;"> solver: {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'}, default='lbfgs'<br />
<br />
Algorithm to use in the optimization problem. Default is 'lbfgs'.<br />
To choose a solver, you might want to consider the following aspects:<br />
<br />
- 'lbfgs' is a good default solver because it works reasonably well for a wide<br />
class of problems.<br />
- For :term:`multiclass` problems (`n_classes >= 3`), all solvers except<br />
'liblinear' minimize the full multinomial loss, 'liblinear' will raise an<br />
error.<br />
- 'newton-cholesky' is a good choice for<br />
`n_samples` >> `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, 'liblinear' is a good choice, whereas 'sag'<br />
and 'saga' are faster for large ones;<br />
- 'liblinear' 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 < l1_ratio < 1` for<br />
Elastic-Net) and on (multinomial) multiclass support:<br />
<br />
================= ======================== ======================<br />
solver l1_ratio multinomial multiclass<br />
================= ======================== ======================<br />
'lbfgs' l1_ratio=0 yes<br />
'liblinear' l1_ratio=1 or l1_ratio=0 no<br />
'newton-cg' l1_ratio=0 yes<br />
'newton-cholesky' l1_ratio=0 yes<br />
'sag' l1_ratio=0 yes<br />
'saga' 0<=l1_ratio<=1 yes<br />
================= ======================== ======================<br />
<br />
.. note::<br />
'sag' and 'saga' 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 <Logistic_regression>` for more<br />
information regarding :class:`LogisticRegression` and more specifically the<br />
:ref:`Table <logistic_regression_solvers>`<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 'liblinear' to 'lbfgs' in 0.22.<br />
.. versionadded:: 1.2<br />
newton-cholesky solver. Multinomial support in version 1.6.</span></a></td>
<td class="value">'lbfgs'</td>
</tr>
<tr class="default">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0" class="param-doc-link" style="anchor-name: --doc-link-verbose;" rel="noreferrer" target="_blank">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><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse" class="param-doc-link" style="anchor-name: --doc-link-warm_start;" rel="noreferrer" target="_blank">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 <warm_start>`.<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><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone" class="param-doc-link" style="anchor-name: --doc-link-n_jobs;" rel="noreferrer" target="_blank">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>


Fitted attributes

<table class="parameters-table">
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<tbody>
<tr>
<th>Name</th>
<th>Type</th>
<th>Value</th>
</tr>

<tr class="default">
<td class="param"><a 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" class="param-doc-link" style="anchor-name: --doc-link-classes_;" rel="noreferrer" target="_blank">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 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" class="param-doc-link" style="anchor-name: --doc-link-coef_;" rel="noreferrer" target="_blank">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, 30)</td>
<td>[[-0.31,-0.58,-0.32,...,-0.99,-0.59,-0.62]]</td>
</tr>
<tr class="default">
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=feature_names_in_,-ndarray%20of%20shape%20%28n_features_in_%2C%29" class="param-doc-link" style="anchor-name: --doc-link-feature_names_in_;" rel="noreferrer" target="_blank">feature_names_in_ <span class="param-doc-description" style="position-anchor: --doc-link-feature_names_in_;"> feature_names_in_: ndarray of shape (`n_features_in_`,)<br />
<br />
Names of features seen during :term:`fit`. Defined only when `X`<br />
has feature names that are all strings.<br />
<br />
.. versionadded:: 1.0</span></a></td>
<td class="fitted-att-type">ndarray[object](30,)</td>
<td>['mean radius','mean texture','mean perimeter',...,'worst concave points', 'worst symmetry','worst fractal dimension']</td>
</tr>
<tr class="default">
<td class="param"><a 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" class="param-doc-link" style="anchor-name: --doc-link-intercept_;" rel="noreferrer" target="_blank">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>[0.03]</td>
</tr>
<tr class="default">
<td class="param"><a href="https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_features_in_,-int" class="param-doc-link" style="anchor-name: --doc-link-n_features_in_;" rel="noreferrer" target="_blank">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>30</td>
</tr>
<tr class="default">
<td class="param"><a 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" class="param-doc-link" style="anchor-name: --doc-link-n_iter_;" rel="noreferrer" target="_blank">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 <= 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>


# The target

The target needs a little care, because scikit-learn's `transform(X)` never receives `y`. The adapter handles the common cases for you and raises a `ValueError` for the ones it cannot support:

- Passing `y` to a recipe with no `"target"` role raises, since there is no column to join it onto. Name the column with `Recipe(target=...)`, or assign the role with `set_roles(target=...)` before the first step (a role assignment written after a step cannot define the target). If the recipe needs no target, call `fit(X)` without `y` instead.
- A recipe with more than one target column raises, since scikit-learn passes a single `y`.
- A step that applies to the target column as one of its input columns raises at fit time, because that step could not run when `transform(X)` is called without the target. Transform the target outside the pipeline instead, for example with `sklearn.compose.TransformedTargetRegressor`.

Steps that use the target only while fitting are fine, because they need `y` at fit time and nothing at transform time. [StepPls](../reference/StepPls.md#mlfeatures.StepPls) and [StepClassDistance](../reference/StepClassDistance.md#mlfeatures.StepClassDistance) are the two examples: they learn from the target, and the columns they produce are computed from the features alone.


``` python
from mlfeatures import StepPls

pls_recipe = (
    Recipe(data=X_train.assign(target=y_train), target="target")
    .add(StepPls(s.numeric_features(), target="target", num_comp=2))
)
pls_pipe = Pipeline(
    [
        ("recipe", RecipeTransformer(pls_recipe)),
        ("model", LogisticRegression(max_iter=1000)),
    ]
)
pls_pipe.fit(X_train, y_train)
pls_pipe.score(X_test, y_test)
```


    0.9230769230769231


A recipe that needs no target works without `y`: call `fit(X)` and `X` is used as given.


``` python
unsupervised_recipe = (
    Recipe(data=X_train)
    .add(StepNormalize(s.numeric_features()))
)
transformer = RecipeTransformer(unsupervised_recipe)
```


Fit on the training data, then apply the stored statistics to the held-out data:


``` python
transformer.fit(X_train)
```


<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>


    RecipeTransformer
      Recipe (trained)
        Inputs: 30 columns (30 features)
        Steps:
          step_normalize(mean radius, mean texture, mean perimeter, mean area, mean smoothness, mean compactness, mean concavity, mean concave points, mean symmetry, mean fractal dimension, radius error, texture error, perimeter error, area error, smoothness error, compactness error, concavity error, concave points error, symmetry error, fractal dimension error, worst radius, worst texture, worst perimeter, worst area, worst smoothness, worst compactness, worst concavity, worst concave points, worst symmetry, worst fractal dimension)  [trained]

**In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.\
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.**


RecipeTransformer (trained)


iFitted


Parameters

|     |        |                                 |
|-----|--------|---------------------------------|
|     | recipe | Recipe (untra...) \[untrained\] |


Fitted attributes

|  |  |  |
|----|----|----|
| Name | Type | Value |
| <span class="param-doc-link" style="text-decoration:none;">feature_names_in\_</span> | list | \['me...us', 'me...re', 'me...er', 'me...ea', ...\] |
| <span class="param-doc-link" style="text-decoration:none;">feature_names_out\_</span> | list | \['me...us', 'me...re', 'me...er', 'me...ea', ...\] |
| <span class="param-doc-link" style="text-decoration:none;">fitted\_</span> | FittedRecipe | Recipe (train...on) \[trained\] |
| <span class="param-doc-link" style="text-decoration:none;">n_features_in\_</span> | int | 30 |


30 features


|                         |
|-------------------------|
| mean radius             |
| mean texture            |
| mean perimeter          |
| mean area               |
| mean smoothness         |
| mean compactness        |
| mean concavity          |
| mean concave points     |
| mean symmetry           |
| mean fractal dimension  |
| radius error            |
| texture error           |
| perimeter error         |
| area error              |
| smoothness error        |
| compactness error       |
| concavity error         |
| concave points error    |
| symmetry error          |
| fractal dimension error |
| worst radius            |
| worst texture           |
| worst perimeter         |
| worst area              |
| worst smoothness        |
| worst compactness       |
| worst concavity         |
| worst concave points    |
| worst symmetry          |
| worst fractal dimension |


``` python
result = transformer.transform(X_test)
result
```


|  | mean radius | mean texture | mean perimeter | mean area | mean smoothness | mean compactness | mean concavity | mean concave points | mean symmetry | mean fractal dimension | ... | worst radius | worst texture | worst perimeter | worst area | worst smoothness | worst compactness | worst concavity | worst concave points | worst symmetry | worst fractal dimension |
|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
| 512 | -0.213708 | 0.312179 | -0.143383 | -0.282209 | 1.027364 | 0.852955 | 0.711305 | 0.839185 | 1.124014 | 1.551743 | ... | 0.019037 | 0.663188 | 0.171967 | -0.073757 | 1.085748 | 0.874025 | 1.215573 | 1.368828 | 1.087833 | 1.537475 |
| 457 | -0.267193 | 1.459508 | -0.329165 | -0.334369 | -0.610325 | -1.018477 | -0.776008 | -0.733260 | -0.670696 | -0.989010 | ... | -0.401817 | 1.416733 | -0.476052 | -0.434462 | -0.157145 | -0.964695 | -0.657806 | -0.841671 | -0.714933 | -0.880025 |
| 439 | -0.039177 | -0.866683 | -0.104508 | -0.144038 | -1.205783 | -0.944291 | -0.863249 | -0.582816 | -0.779028 | -0.986092 | ... | -0.287410 | -1.043417 | -0.321776 | -0.338956 | -1.269208 | -0.994978 | -1.042968 | -0.504725 | -1.201569 | -0.923857 |
| 298 | 0.028383 | -0.257847 | -0.037807 | -0.070237 | -2.209040 | -1.015518 | -0.813834 | -0.912040 | -0.612918 | -0.986092 | ... | -0.019780 | -0.062325 | -0.048848 | -0.115882 | -1.659520 | -0.237897 | -0.569582 | -0.609268 | -0.411576 | -0.381015 |
| 37 | -0.317863 | -0.197206 | -0.390137 | -0.373490 | -0.471746 | -1.302398 | -0.802753 | -0.513004 | -1.219581 | -0.581848 | ... | -0.616330 | -0.466304 | -0.677141 | -0.582836 | -1.547878 | -1.360418 | -1.114908 | -0.992848 | -1.436988 | -1.227871 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 236 | 2.547820 | 1.876718 | 2.510759 | 2.806644 | -0.092096 | 1.273213 | 1.354474 | 1.920627 | 0.376519 | 0.069029 | ... | 3.001789 | 1.462902 | 2.901242 | 3.507021 | 0.680172 | 1.051774 | 1.575528 | 2.194813 | 0.326279 | 0.181495 |
| 113 | -1.027247 | 0.232133 | -0.961805 | -0.899535 | 1.142847 | 0.525429 | -0.304265 | -0.475651 | 0.423464 | 2.218672 | ... | -1.053528 | -0.476197 | -1.025734 | -0.875322 | -0.109174 | -0.315580 | -0.705699 | -0.821708 | -0.811313 | 0.377615 |
| 527 | -0.512099 | -1.688976 | -0.540318 | -0.526920 | -0.457311 | -0.801048 | -0.752319 | -0.584104 | -0.417920 | -0.662113 | ... | -0.552998 | -1.050013 | -0.595881 | -0.550433 | -0.144062 | -0.299122 | -0.455646 | -0.126174 | 0.337338 | -0.428219 |
| 76 | -0.177113 | -2.011586 | -0.173256 | -0.275272 | 2.362634 | 0.020330 | -0.253194 | 0.422889 | 2.160396 | 0.553538 | ... | -0.456977 | -2.167963 | -0.473991 | -0.481191 | 0.549341 | -0.756662 | -0.928075 | -0.628013 | -0.294657 | -0.653560 |
| 162 | 1.528785 | -0.262698 | 1.577758 | 1.541472 | 1.128412 | 1.241644 | 2.065144 | 2.046856 | 0.802628 | -0.262247 | ... | 2.127393 | 0.124000 | 1.985595 | 2.292735 | 0.492648 | 0.867441 | 2.074626 | 1.667524 | 1.179472 | 0.488318 |

143 rows × 30 columns


# Cross-validation and tuning

Because the adapter stores the recipe verbatim, it clones cleanly, so it works inside `GridSearchCV` and any other tool that re-fits across folds:


``` python
from sklearn.model_selection import GridSearchCV

search = GridSearchCV(pipe, {"model__C": [0.1, 1.0]}, cv=3)
search.fit(X_train, y_train)
search.best_params_
```


    {'model__C': 1.0}


## Tuning step hyperparameters

Step hyperparameters are reachable through scikit-learn's nested parameter names, so a grid can vary a step's argument directly. Steps are addressed by their `id`, never by position, giving keys of the form `<pipeline step>__recipe__<step id>__<parameter>`: the name you gave the [RecipeTransformer](../reference/RecipeTransformer.md#mlfeatures.RecipeTransformer) in the pipeline, the `recipe` it wraps, the step, and the step's parameter. Each step has a default `id` ([StepDropCorr](../reference/StepDropCorr.md#mlfeatures.StepDropCorr) uses `"corr"`) that you can replace with the step's `id=` argument. A step's `id` and `columns` are not tunable.


``` python
from mlfeatures import StepDropCorr

tuned_recipe = (
    Recipe(data=X_train.assign(target=y_train), target="target")
    .add(StepDropCorr(s.numeric_features(), threshold=0.9))
    .add(StepNormalize(s.numeric_features()))
)
tuned_pipe = Pipeline(
    [
        ("prep", RecipeTransformer(tuned_recipe)),
        ("model", LogisticRegression(max_iter=1000)),
    ]
)
```


The tunable keys are listed by [get_params](../reference/Step.get_params.md#mlfeatures.Step.get_params). Here `prep` is the pipeline step, `corr` is the [StepDropCorr](../reference/StepDropCorr.md#mlfeatures.StepDropCorr) step's `id`, and `threshold` and `method` are its parameters:


``` python
[k for k in tuned_pipe.get_params() if k.startswith("prep__recipe__")]
```


    ['prep__recipe__corr__threshold', 'prep__recipe__corr__method']


``` python
grid = {"prep__recipe__corr__threshold": [0.8, 0.95]}
search = GridSearchCV(tuned_pipe, grid, cv=3)
search.fit(X_train, y_train)
search.best_params_
```


    {'prep__recipe__corr__threshold': 0.95}


# Feature names and `set_output`

[RecipeTransformer](../reference/RecipeTransformer.md#mlfeatures.RecipeTransformer) implements `get_feature_names_out`, so it composes inside a `ColumnTransformer` and supports the `set_output` API for choosing the container type returned by [transform](../reference/Step.transform.md#mlfeatures.Step.transform) (`"pandas"` or `"polars"`):


``` python
rt = RecipeTransformer(tuned_recipe).set_output(transform="pandas")
rt.fit(X_train, y_train).transform(X_test).iloc[:5, :3]
```


|     | mean texture | mean area | mean smoothness |
|-----|--------------|-----------|-----------------|
| 512 | 0.312179     | -0.282209 | 1.027364        |
| 457 | 1.459508     | -0.334369 | -0.610325       |
| 439 | -0.866683    | -0.144038 | -1.205783       |
| 298 | -0.257847    | -0.070237 | -2.209040       |
| 37  | -0.197206    | -0.373490 | -0.471746       |
