## StepIntercept


Add a constant column with a fixed value.


Usage

``` python
StepIntercept(
    *,
    value=1.0,
    name="intercept",
    role="feature",
    id=None,
)
```


A single constant column is added, by default a column of ones named `"intercept"`.

See [Arguments shared across steps](../user-guide/common-step-arguments.md) for the arguments this step shares with the others.


## Parameters


`value: float = ``1.0`  
The constant to fill the new column with. Default `1.0`. The column's dtype follows the literal, so an `int` gives an integer column.

`name: str = ``"intercept"`  
Name of the new column. Default `"intercept"`. A [Recipe](Recipe.md#mlfeatures.Recipe) rejects the step if the data frame already has a column of this name.

`role: str | None = ``"feature"`  
Role assigned to the new column (see [Roles](Roles.md#mlfeatures.Roles)). Default `"feature"`.

`id: str | None = None`  
Stable step identifier. Defaults to `"intercept"`; a second step of this type in the same recipe becomes `"intercept_2"`, and passing an `id` already used in the recipe is an error.


## Examples

A constant `intercept` column of ones is added; the input columns pass through untouched:


``` python
df = pd.DataFrame({"x": [1.0, 2.0, 3.0]})
df
```


|     | x   |
|-----|-----|
| 0   | 1.0 |
| 1   | 2.0 |
| 2   | 3.0 |


Specifying the step touches no data:


``` python
recipe = Recipe().add(StepIntercept())
recipe
```


    Recipe (untrained)
      Inputs: no roles assigned
      Steps:
        step_intercept()  [untrained]


[fit()](Step.fit.md#mlfeatures.Step.fit) has nothing to estimate; the step is constant:


``` python
fitted = recipe.fit(df)
fitted
```


    Recipe (trained)
      Inputs: 1 columns (1 feature)
      Steps:
        step_intercept(intercept)  [trained]


[transform()](Step.transform.md#mlfeatures.Step.transform) adds the column:


``` python
fitted.transform(df)
```


|     | x   | intercept |
|-----|-----|-----------|
| 0   | 1.0 | 1.0       |
| 1   | 2.0 | 1.0       |
| 2   | 3.0 | 1.0       |


`value` and `name` control what is added:


``` python
recipe = Recipe().add(StepIntercept(value=0.0, name="bias"))
fitted = recipe.fit(df)
fitted.transform(df)
```


|     | x   | bias |
|-----|-----|------|
| 0   | 1.0 | 0.0  |
| 1   | 2.0 | 0.0  |
| 2   | 3.0 | 0.0  |
