oversamplers

Module Contents

Classes Summary

SMOTENCOversampler

SMOTENC Oversampler component. Uses SMOTENC to generate synthetic samples. Works on a mix of numerical and categorical columns.

SMOTENOversampler

SMOTEN Oversampler component. Uses SMOTEN to generate synthetic samples. Works for purely categorical datasets.

SMOTEOversampler

SMOTE Oversampler component. Works on numerical datasets only. This component is only run during training and not during predict.

Contents

class evalml.pipelines.components.transformers.samplers.oversamplers.SMOTENCOversampler(sampling_ratio=0.25, k_neighbors_default=5, n_jobs=- 1, random_seed=0, **kwargs)[source]

SMOTENC Oversampler component. Uses SMOTENC to generate synthetic samples. Works on a mix of numerical and categorical columns. Input data must be Woodwork type, and this component is only run during training and not during predict.

Parameters
  • sampling_ratio (float) – This is the goal ratio of the minority to majority class, with range (0, 1]. A value of 0.25 means we want a 1:4 ratio of the minority to majority class after oversampling. We will create the a sampling dictionary using this ratio, with the keys corresponding to the class and the values responding to the number of samples. Defaults to 0.25.

  • k_neighbors_default (int) – The number of nearest neighbors used to construct synthetic samples. This is the default value used, but the actual k_neighbors value might be smaller if there are less samples. Defaults to 5.

  • n_jobs (int) – The number of CPU cores to use. Defaults to -1.

  • random_seed (int) – The seed to use for random sampling. Defaults to 0.

Attributes

hyperparameter_ranges

{}

model_family

ModelFamily.NONE

modifies_features

True

modifies_target

True

name

SMOTENC Oversampler

Methods

clone

Constructs a new component with the same parameters and random state.

default_parameters

Returns the default parameters for this component.

describe

Describe a component and its parameters

fit

Fits the sampler to the data.

fit_transform

Fits on X and transforms X

load

Loads component at file path

needs_fitting

Returns boolean determining if component needs fitting before

parameters

Returns the parameters which were used to initialize the component

save

Saves component at file path

transform

Transforms the input data by sampling the data.

clone(self)

Constructs a new component with the same parameters and random state.

Returns

A new instance of this component with identical parameters and random state.

default_parameters(cls)

Returns the default parameters for this component.

Our convention is that Component.default_parameters == Component().parameters.

Returns

default parameters for this component.

Return type

dict

describe(self, print_name=False, return_dict=False)

Describe a component and its parameters

Parameters
  • print_name (bool, optional) – whether to print name of component

  • return_dict (bool, optional) – whether to return description as dictionary in the format {“name”: name, “parameters”: parameters}

Returns

prints and returns dictionary

Return type

None or dict

fit(self, X, y)[source]

Fits the sampler to the data.

Parameters
  • X (pd.DataFrame) – Input features.

  • y (pd.Series) – Target.

Returns

self

fit_transform(self, X, y)

Fits on X and transforms X

Parameters
  • X (pd.DataFrame) – Data to fit and transform

  • y (pd.Series) – Target data

Returns

Transformed X

Return type

pd.DataFrame

static load(file_path)

Loads component at file path

Parameters

file_path (str) – Location to load file

Returns

ComponentBase object

needs_fitting(self)

Returns boolean determining if component needs fitting before calling predict, predict_proba, transform, or feature_importances. This can be overridden to False for components that do not need to be fit or whose fit methods do nothing.

property parameters(self)

Returns the parameters which were used to initialize the component

save(self, file_path, pickle_protocol=cloudpickle.DEFAULT_PROTOCOL)

Saves component at file path

Parameters
  • file_path (str) – Location to save file

  • pickle_protocol (int) – The pickle data stream format.

Returns

None

transform(self, X, y=None)

Transforms the input data by sampling the data.

Parameters
  • X (pd.DataFrame) – Training features.

  • y (pd.Series) – Target.

Returns

Transformed features and target.

Return type

pd.DataFrame, pd.Series

class evalml.pipelines.components.transformers.samplers.oversamplers.SMOTENOversampler(sampling_ratio=0.25, k_neighbors_default=5, n_jobs=- 1, random_seed=0, **kwargs)[source]

SMOTEN Oversampler component. Uses SMOTEN to generate synthetic samples. Works for purely categorical datasets. This component is only run during training and not during predict.

Parameters
  • sampling_ratio (float) – This is the goal ratio of the minority to majority class, with range (0, 1]. A value of 0.25 means we want a 1:4 ratio of the minority to majority class after oversampling. We will create the a sampling dictionary using this ratio, with the keys corresponding to the class and the values responding to the number of samples. Defaults to 0.25.

  • k_neighbors_default (int) – The number of nearest neighbors used to construct synthetic samples. This is the default value used, but the actual k_neighbors value might be smaller if there are less samples. Defaults to 5.

  • n_jobs (int) – The number of CPU cores to use. Defaults to -1.

  • random_seed (int) – The seed to use for random sampling. Defaults to 0.

Attributes

hyperparameter_ranges

{}

model_family

ModelFamily.NONE

modifies_features

True

modifies_target

True

name

SMOTEN Oversampler

Methods

clone

Constructs a new component with the same parameters and random state.

default_parameters

Returns the default parameters for this component.

describe

Describe a component and its parameters

fit

Fits the sampler to the data.

fit_transform

Fits on X and transforms X

load

Loads component at file path

needs_fitting

Returns boolean determining if component needs fitting before

parameters

Returns the parameters which were used to initialize the component

save

Saves component at file path

transform

Transforms the input data by sampling the data.

clone(self)

Constructs a new component with the same parameters and random state.

Returns

A new instance of this component with identical parameters and random state.

default_parameters(cls)

Returns the default parameters for this component.

Our convention is that Component.default_parameters == Component().parameters.

Returns

default parameters for this component.

Return type

dict

describe(self, print_name=False, return_dict=False)

Describe a component and its parameters

Parameters
  • print_name (bool, optional) – whether to print name of component

  • return_dict (bool, optional) – whether to return description as dictionary in the format {“name”: name, “parameters”: parameters}

Returns

prints and returns dictionary

Return type

None or dict

fit(self, X, y)

Fits the sampler to the data.

Parameters
  • X (pd.DataFrame) – Input features.

  • y (pd.Series) – Target.

Returns

self

fit_transform(self, X, y)

Fits on X and transforms X

Parameters
  • X (pd.DataFrame) – Data to fit and transform

  • y (pd.Series) – Target data

Returns

Transformed X

Return type

pd.DataFrame

static load(file_path)

Loads component at file path

Parameters

file_path (str) – Location to load file

Returns

ComponentBase object

needs_fitting(self)

Returns boolean determining if component needs fitting before calling predict, predict_proba, transform, or feature_importances. This can be overridden to False for components that do not need to be fit or whose fit methods do nothing.

property parameters(self)

Returns the parameters which were used to initialize the component

save(self, file_path, pickle_protocol=cloudpickle.DEFAULT_PROTOCOL)

Saves component at file path

Parameters
  • file_path (str) – Location to save file

  • pickle_protocol (int) – The pickle data stream format.

Returns

None

transform(self, X, y=None)

Transforms the input data by sampling the data.

Parameters
  • X (pd.DataFrame) – Training features.

  • y (pd.Series) – Target.

Returns

Transformed features and target.

Return type

pd.DataFrame, pd.Series

class evalml.pipelines.components.transformers.samplers.oversamplers.SMOTEOversampler(sampling_ratio=0.25, k_neighbors_default=5, n_jobs=- 1, random_seed=0, **kwargs)[source]

SMOTE Oversampler component. Works on numerical datasets only. This component is only run during training and not during predict.

Parameters
  • sampling_ratio (float) – This is the goal ratio of the minority to majority class, with range (0, 1]. A value of 0.25 means we want a 1:4 ratio of the minority to majority class after oversampling. We will create the a sampling dictionary using this ratio, with the keys corresponding to the class and the values responding to the number of samples. Defaults to 0.25.

  • k_neighbors_default (int) – The number of nearest neighbors used to construct synthetic samples. This is the default value used, but the actual k_neighbors value might be smaller if there are less samples. Defaults to 5.

  • n_jobs (int) – The number of CPU cores to use. Defaults to -1.

  • random_seed (int) – The seed to use for random sampling. Defaults to 0.

Attributes

hyperparameter_ranges

{}

model_family

ModelFamily.NONE

modifies_features

True

modifies_target

True

name

SMOTE Oversampler

Methods

clone

Constructs a new component with the same parameters and random state.

default_parameters

Returns the default parameters for this component.

describe

Describe a component and its parameters

fit

Fits the sampler to the data.

fit_transform

Fits on X and transforms X

load

Loads component at file path

needs_fitting

Returns boolean determining if component needs fitting before

parameters

Returns the parameters which were used to initialize the component

save

Saves component at file path

transform

Transforms the input data by sampling the data.

clone(self)

Constructs a new component with the same parameters and random state.

Returns

A new instance of this component with identical parameters and random state.

default_parameters(cls)

Returns the default parameters for this component.

Our convention is that Component.default_parameters == Component().parameters.

Returns

default parameters for this component.

Return type

dict

describe(self, print_name=False, return_dict=False)

Describe a component and its parameters

Parameters
  • print_name (bool, optional) – whether to print name of component

  • return_dict (bool, optional) – whether to return description as dictionary in the format {“name”: name, “parameters”: parameters}

Returns

prints and returns dictionary

Return type

None or dict

fit(self, X, y)

Fits the sampler to the data.

Parameters
  • X (pd.DataFrame) – Input features.

  • y (pd.Series) – Target.

Returns

self

fit_transform(self, X, y)

Fits on X and transforms X

Parameters
  • X (pd.DataFrame) – Data to fit and transform

  • y (pd.Series) – Target data

Returns

Transformed X

Return type

pd.DataFrame

static load(file_path)

Loads component at file path

Parameters

file_path (str) – Location to load file

Returns

ComponentBase object

needs_fitting(self)

Returns boolean determining if component needs fitting before calling predict, predict_proba, transform, or feature_importances. This can be overridden to False for components that do not need to be fit or whose fit methods do nothing.

property parameters(self)

Returns the parameters which were used to initialize the component

save(self, file_path, pickle_protocol=cloudpickle.DEFAULT_PROTOCOL)

Saves component at file path

Parameters
  • file_path (str) – Location to save file

  • pickle_protocol (int) – The pickle data stream format.

Returns

None

transform(self, X, y=None)

Transforms the input data by sampling the data.

Parameters
  • X (pd.DataFrame) – Training features.

  • y (pd.Series) – Target.

Returns

Transformed features and target.

Return type

pd.DataFrame, pd.Series