oversamplers

Module Contents

Classes Summary

SMOTENCSampler

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

SMOTENSampler

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

SMOTESampler

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.SMOTENCSampler(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 nomerical 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 Oversampler to the data.

fit_transform

Fit and transform the data using the data sampler. Used during training of the pipeline

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

No transformation needs to be done here.

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 Oversampler to the data.

Parameters
  • X (pd.DataFrame) – Training features

  • y (pd.Series) – Target features

Returns

self

fit_transform(self, X, y)

Fit and transform the data using the data sampler. Used during training of the pipeline

Parameters
  • X (pd.DataFrame) – Training features

  • y – Target features

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)

No transformation needs to be done here.

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

  • y (pd.Series) – Target features. Ignored.

Returns

X and y data that was passed in.

Return type

pd.DataFrame, pd.Series

class evalml.pipelines.components.transformers.samplers.oversamplers.SMOTENSampler(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 Oversampler to the data.

fit_transform

Fit and transform the data using the data sampler. Used during training of the pipeline

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

No transformation needs to be done here.

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 Oversampler to the data.

Parameters
  • X (pd.DataFrame) – Training features

  • y (pd.Series) – Target features

Returns

self

fit_transform(self, X, y)

Fit and transform the data using the data sampler. Used during training of the pipeline

Parameters
  • X (pd.DataFrame) – Training features

  • y – Target features

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)

No transformation needs to be done here.

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

  • y (pd.Series) – Target features. Ignored.

Returns

X and y data that was passed in.

Return type

pd.DataFrame, pd.Series

class evalml.pipelines.components.transformers.samplers.oversamplers.SMOTESampler(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 Oversampler to the data.

fit_transform

Fit and transform the data using the data sampler. Used during training of the pipeline

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

No transformation needs to be done here.

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 Oversampler to the data.

Parameters
  • X (pd.DataFrame) – Training features

  • y (pd.Series) – Target features

Returns

self

fit_transform(self, X, y)

Fit and transform the data using the data sampler. Used during training of the pipeline

Parameters
  • X (pd.DataFrame) – Training features

  • y – Target features

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)

No transformation needs to be done here.

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

  • y (pd.Series) – Target features. Ignored.

Returns

X and y data that was passed in.

Return type

pd.DataFrame, pd.Series