MinMaxScaler¶
yohou.preprocessing.sklearn_wrappers.MinMaxScaler
¶
Bases: SklearnScaler
Transform features by scaling each feature to a given range.
This estimator scales and translates each feature individually such that it is in the given range on the training set, e.g. between zero and one.
The transformation is given by::
X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min
where min, max = feature_range.
This transformation is often used as an alternative to zero mean, unit variance scaling.
MinMaxScaler doesn't reduce the effect of outliers, but it linearly
scales them down into a fixed range, where the largest occurring data point
corresponds to the maximum value and the smallest one corresponds to the
minimum value.
This is a Yohou wrapper that preserves the polars DataFrame structure and "time" column.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
feature_range
|
tuple(min, max)
|
Desired range of transformed data. |
(0, 1)
|
clip
|
bool
|
Set to True to clip transformed values of held-out data to the provided
|
False
|
Attributes¶
| Name | Type | Description |
|---|---|---|
instance_ |
MinMaxScaler
|
The fitted sklearn MinMaxScaler instance. |
min_ |
ndarray of shape (n_features,)
|
Per feature adjustment for minimum. |
scale_ |
ndarray of shape (n_features,)
|
Per feature relative scaling of the data. |
data_min_ |
ndarray of shape (n_features,)
|
Per feature minimum seen in the data. |
data_max_ |
ndarray of shape (n_features,)
|
Per feature maximum seen in the data. |
data_range_ |
ndarray of shape (n_features,)
|
Per feature range |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.preprocessing import MinMaxScaler
>>> X = pl.DataFrame({
... "time": [datetime(2024, 1, i) for i in range(1, 6)],
... "value": [10.0, 20.0, 30.0, 40.0, 50.0],
... })
>>> scaler = MinMaxScaler()
>>> scaler.fit(X)
MinMaxScaler(...)
>>> X_scaled = scaler.transform(X)
>>> # Values are scaled to [0, 1]
>>> X_scaled["value"].min()
0.0
>>> X_scaled["value"].max()
1.0
See Also¶
StandardScaler: Standardize features by removing mean and scaling to unit variance.MaxAbsScaler: Scale each feature by its maximum absolute value.
Source Code¶
Show/Hide source
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
Methods¶
Tutorials¶
The following example notebooks use this component:
-
How to Use Scikit-learn Scalers
Data-Features
Wrap sklearn scalers (StandardScaler, MinMaxScaler, RobustScaler, PowerTransformer, PolynomialFeatures) for polars DataFrames with inverse transforms.