scalers

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package scalers provides data normalization and standardization transformers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxAbsScaler

type MaxAbsScaler struct {
	// Columns to scale. If nil, all numeric columns are scaled.
	Columns []string
	// contains filtered or unexported fields
}

MaxAbsScaler scales each feature by its maximum absolute value. This scaler is particularly suited for sparse data as it preserves zero values. The transformation is: X_scaled = X / max(abs(X))

func NewMaxAbsScaler

func NewMaxAbsScaler(columns []string) *MaxAbsScaler

NewMaxAbsScaler creates a new MaxAbsScaler.

func (*MaxAbsScaler) Fit

func (m *MaxAbsScaler) Fit(df *dataframe.DataFrame, _ ...string) error

Fit computes the maximum absolute value for each column.

func (*MaxAbsScaler) FitTransform

func (m *MaxAbsScaler) FitTransform(df *dataframe.DataFrame, target ...string) (*dataframe.DataFrame, error)

FitTransform fits the scaler and transforms the data in one step.

func (*MaxAbsScaler) GetMaxAbss

func (m *MaxAbsScaler) GetMaxAbss() map[string]float64

GetMaxAbss returns the computed maximum absolute values.

func (*MaxAbsScaler) IsFitted

func (m *MaxAbsScaler) IsFitted() bool

IsFitted returns true if the scaler has been fitted.

func (*MaxAbsScaler) Transform

func (m *MaxAbsScaler) Transform(df *dataframe.DataFrame) (*dataframe.DataFrame, error)

Transform applies the max-abs scaling to the data.

type MinMaxScaler

type MinMaxScaler struct {
	// Columns to scale. If nil, all numeric columns are scaled.
	Columns []string

	// FeatureRange defines the desired range of transformed data.
	// Default: [0, 1]
	FeatureMin float64
	FeatureMax float64
	// contains filtered or unexported fields
}

MinMaxScaler scales features to a given range (default: [0, 1]). The transformation is given by: X_scaled = (X - X_min) / (X_max - X_min) * (max - min) + min

func NewMinMaxScaler

func NewMinMaxScaler(columns []string) *MinMaxScaler

NewMinMaxScaler creates a new MinMaxScaler with default range [0, 1].

func (*MinMaxScaler) Fit

func (m *MinMaxScaler) Fit(df *dataframe.DataFrame, _ ...string) error

Fit computes the min and max for each column.

func (*MinMaxScaler) FitTransform

func (m *MinMaxScaler) FitTransform(df *dataframe.DataFrame, target ...string) (*dataframe.DataFrame, error)

FitTransform fits the scaler and transforms the data in one step.

func (*MinMaxScaler) GetMaxs

func (m *MinMaxScaler) GetMaxs() map[string]float64

GetMaxs returns the computed maximums.

func (*MinMaxScaler) GetMins

func (m *MinMaxScaler) GetMins() map[string]float64

GetMins returns the computed minimums.

func (*MinMaxScaler) IsFitted

func (m *MinMaxScaler) IsFitted() bool

IsFitted returns true if the scaler has been fitted.

func (*MinMaxScaler) Transform

func (m *MinMaxScaler) Transform(df *dataframe.DataFrame) (*dataframe.DataFrame, error)

Transform applies the min-max scaling to the data.

type RobustScaler

type RobustScaler struct {
	// Columns to scale. If nil, all numeric columns are scaled.
	Columns []string

	// WithCentering centers the data before scaling. Default: true
	WithCentering bool

	// WithScaling scales the data to IQR. Default: true
	WithScaling bool

	// QuantileRange for IQR calculation. Default: [25.0, 75.0]
	QuantileRange [2]float64
	// contains filtered or unexported fields
}

RobustScaler scales features using statistics that are robust to outliers. It removes the median and scales the data according to the Interquartile Range (IQR). The transformation is: X_scaled = (X - median) / IQR

func NewRobustScaler

func NewRobustScaler(columns []string) *RobustScaler

NewRobustScaler creates a new RobustScaler with default settings.

func (*RobustScaler) Fit

func (r *RobustScaler) Fit(df *dataframe.DataFrame, _ ...string) error

Fit computes the median and IQR for each column.

func (*RobustScaler) FitTransform

func (r *RobustScaler) FitTransform(df *dataframe.DataFrame, target ...string) (*dataframe.DataFrame, error)

FitTransform fits the scaler and transforms the data in one step.

func (*RobustScaler) GetIQRs

func (r *RobustScaler) GetIQRs() map[string]float64

GetIQRs returns the computed IQRs.

func (*RobustScaler) GetMedians

func (r *RobustScaler) GetMedians() map[string]float64

GetMedians returns the computed medians.

func (*RobustScaler) IsFitted

func (r *RobustScaler) IsFitted() bool

IsFitted returns true if the scaler has been fitted.

func (*RobustScaler) Transform

func (r *RobustScaler) Transform(df *dataframe.DataFrame) (*dataframe.DataFrame, error)

Transform applies the robust scaling to the data.

type StandardScaler

type StandardScaler struct {
	// Columns to scale. If nil, all numeric columns are scaled.
	Columns []string

	// WithMean centers the data before scaling. Default: true
	WithMean bool

	// WithStd scales the data to unit variance. Default: true
	WithStd bool
	// contains filtered or unexported fields
}

StandardScaler standardizes features by removing the mean and scaling to unit variance. The standard score of a sample x is calculated as: z = (x - μ) / σ where μ is the mean and σ is the standard deviation.

func NewStandardScaler

func NewStandardScaler(columns []string) *StandardScaler

NewStandardScaler creates a new StandardScaler with default settings.

func (*StandardScaler) Fit

func (s *StandardScaler) Fit(df *dataframe.DataFrame, _ ...string) error

Fit computes the mean and standard deviation for each column.

func (*StandardScaler) FitTransform

func (s *StandardScaler) FitTransform(df *dataframe.DataFrame, target ...string) (*dataframe.DataFrame, error)

FitTransform fits the scaler and transforms the data in one step.

func (*StandardScaler) GetMeans

func (s *StandardScaler) GetMeans() map[string]float64

GetMeans returns the computed means.

func (*StandardScaler) GetStds

func (s *StandardScaler) GetStds() map[string]float64

GetStds returns the computed standard deviations.

func (*StandardScaler) IsFitted

func (s *StandardScaler) IsFitted() bool

IsFitted returns true if the scaler has been fitted.

func (*StandardScaler) Transform

Transform applies the standardization to the data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL