danfo.MinMaxScaler
Transform features by scaling each feature to a range of max and min values.
class danfo.MinMaxScaler
danfo.js provides the MinMaxScaler class for standardization of DataFrame and Series. 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.
This transformation is often used as an alternative to zero mean, unit variance scaling like Standardscaler.
The API is similar to sklearn's MinMaxScaler, and provides a fit and transform method.
Examples
Standardize DataFrame Object using MinMaxScaler
const dfd = require("danfojs-node")
let scaler = new dfd.MinMaxScaler()
let data = [[100,1000,2000, 3000] ,
[20, 30, 20, 10],
[1, 1, 1, 0]]
let df = new dfd.DataFrame(data)
df.print()
scaler.fit(df)
let df_enc = scaler.transform(df)
df_enc.print()
โโโโโคโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโ
โ โ 0 โ 1 โ 2 โ 3 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 0 โ 100 โ 1000 โ 2000 โ 3000 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 1 โ 20 โ 30 โ 20 โ 10 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 2 โ 1 โ 1 โ 1 โ 0 โ
โโโโโงโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโ
Shape: (3,4)
โโโโโคโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโ
โ โ 0 โ 1 โ 2 โ 3 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 0 โ 1 โ 1 โ 1 โ 1 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 1 โ 0.19191919267... โ 0.02902902849... โ 0.00950475223... โ 0.00333333341... โ
โโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 2 โ 0 โ 0 โ 0 โ 0 โ
โโโโโงโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโ
Standardize Series Object Using MinMaxScaler
const dfd = require("danfojs-node")
let scaler = new dfd.MinMaxScaler()
let data = [[100,1000,2000, 3000] ,
[20, 30, 20, 10],
[1, 1, 1, 0]]
let df = new dfd.DataFrame(data)
let sf = df.iloc({columns: [0]})
scaler.fit(sf)
let df_enc = scaler.transform(sf)
df_enc.print()
Shape: (3,1)
โโโโโคโโโโโโโโโโโโโโโโโโโโ
โ โ 0 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 0 โ 1 โ
โโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 1 โ 0.19191919267... โ
โโโโโผโโโโโโโโโโโโโโโโโโโโข
โ 2 โ 0 โ
โโโโโงโโโโโโโโโโโโโโโโโโโโ
See also MinMaxScaler
Last updated