Min-Max Scaler
easy· Machine Learningruns: 0Implement a feature scaler that maps each feature into a given range (default [0, 1]) using the formula (X - min) / (max - min). Provide fit, transform, and fit_transform.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 612
import numpy as np
class MinMaxScaler:
def __init__(self, feature_range: tuple[float, float] = (0.0, 1.0)):
self.low, self.high = feature_range
self.min_ = None
self.max_ = None
def fit(self, X):
self.min_ = X.min(axis=0)
self.max_ = X.max(axis=0)
return self
def transform(self, X):
scale = self.max_ - self.min_
scale = np.where(scale == 0, 1, scale)
normalized = (X - self.min_) / scale
return normalized * (self.high - self.low) + self.low
def fit_transform(self, X):
return self.fit(X).transform(X)
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.