### Install developer version from GitHub Source: https://imbalancedlearningregression.readthedocs.io/en/latest/intro.html Install the latest developer version directly from the GitHub repository. ```bash $ pip install git+https://github.com/paobranco/ImbalancedLearningRegression.git ``` -------------------------------- ### Install pypi release Source: https://imbalancedlearningregression.readthedocs.io/en/latest/intro.html Install the package from PyPI using pip. ```bash $ pip install ImbalancedLearningRegression ``` -------------------------------- ### Python example: Using cnn() to under-sample a dataset Source: https://imbalancedlearningregression.readthedocs.io/en/latest/cnn.html Shows how to import the cnn function, load a dataset from a URL, and apply under-sampling with default parameters. The example uses the housing dataset and specifies the target column 'SalePrice'. ```python >>> from ImbalancedLearningRegression import cnn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_cnn = cnn(data = housing, y = "SalePrice") ``` -------------------------------- ### Example: Using ro() to over-sample the housing dataset Source: https://imbalancedlearningregression.readthedocs.io/en/latest/ro.html Shows how to import the ro function, load a dataset from a URL, and apply random over-sampling to the target column 'SalePrice'. ```python >>> from ImbalancedLearningRegression import ro >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_ro = ro(data = housing, y = "SalePrice") ``` -------------------------------- ### Perform ADASYN over-sampling Source: https://imbalancedlearningregression.readthedocs.io/en/latest/adasyn.html Example showing how to import the adasyn function and apply it to a housing dataset to re-sample based on the 'SalePrice' target variable. ```python >>> from ImbalancedLearningRegression import adasyn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_adasyn = adasyn(data = housing, y = "SalePrice") ``` -------------------------------- ### tomeklinks() usage example Source: https://imbalancedlearningregression.readthedocs.io/en/latest/tomeklinks.html Example showing how to import and use the tomeklinks() function from ImbalancedLearningRegression. It loads the housing dataset from a URL and applies TomekLinks under-sampling with default parameters. ```python >>> from ImbalancedLearningRegression import tomeklinks >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_tomeklinks = tomeklinks(data = housing, y = "SalePrice") ``` -------------------------------- ### random_under() usage example Source: https://imbalancedlearningregression.readthedocs.io/en/latest/ru.html Imports the random_under function, loads the housing dataset from a URL, and applies random under-sampling with default parameters. ```python >>> from ImbalancedLearningRegression import random_under >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_ru = random_under(data = housing, y = "SalePrice") ``` -------------------------------- ### Usage example with Random Over-sampling and Gaussian Noise Source: https://imbalancedlearningregression.readthedocs.io/en/latest/intro.html Demonstrates loading the housing dataset and applying random over-sampling (ro) and Gaussian noise (gn) techniques using the ImbalancedLearningRegression package. ```python >>> ## load libraries >>> import pandas >>> import ImbalancedLearningRegression as iblr >>> ## load data >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> ## conduct Random Over-sampling >>> housing_ro = iblr.ro(data = housing, y = "SalePrice") >>> ## conduct Introduction of Gaussian Noise >>> housing_gn = iblr.gn(data = housing, y = "SalePrice") ``` -------------------------------- ### enn() usage example with housing dataset Source: https://imbalancedlearningregression.readthedocs.io/en/latest/enn.html Imports the enn function, loads the housing dataset from a URL, and applies ENN under-sampling to the 'SalePrice' target column. The result is stored in housing_enn. ```python >>> from ImbalancedLearningRegression import enn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_enn = enn(data = housing, y = "SalePrice") ``` -------------------------------- ### Import and apply gn() to a housing dataset Source: https://imbalancedlearningregression.readthedocs.io/en/latest/gn.html Shows how to import the gn function from ImbalancedLearningRegression, load a housing dataset from a URL, and apply gn() with default parameters to re-sample the data. The result is stored in housing_gn. ```python >>> from ImbalancedLearningRegression import gn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_gn = gn(data = housing, y = "SalePrice") ``` -------------------------------- ### random_under(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, replacement=False, manual_perc=False, perc_u=-1, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) Source: https://imbalancedlearningregression.readthedocs.io/en/latest/ru.html Randomly selects a subset of majority samples to under-sample the dataset. Returns a re-sampled Pandas dataframe. ```APIDOC ## random_under(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, replacement=False, manual_perc=False, perc_u=-1, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Description Randomly selects a subset of majority samples to under-sample the dataset. Returns a re-sampled Pandas dataframe. ### Method Function call ### Endpoint random_under(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, replacement=False, manual_perc=False, perc_u=-1, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Parameters - **data** (Pandas dataframe) - Required - The dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either `balance` or `extreme`. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **replacement** (bool) - Optional - Randomly select sample to duplicate: with or without replacement. - **manual_perc** (bool) - Optional - Keep the same percentage of re-sampling for all bins. If `True`, `perc_u` is required to be a real number between 0 and 1 (0, 1). - **perc_u** (float) - Optional - User-specified fixed percentage of under-sampling for all bins. Must be a real number between 0 and 1 (0, 1) if `manual_perc = True`. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considerd as normal, and vise versa. - **rel_coef** (float) - Optional - Coefficient for box plot. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. ### Returns Re-sampled dataset (Pandas dataframe). ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or under_sampled data contains missing values. ### Example python >>> from ImbalancedLearningRegression import random_under >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_ru = random_under(data = housing, y = "SalePrice") ``` -------------------------------- ### Apply smote() to housing dataset Source: https://imbalancedlearningregression.readthedocs.io/en/latest/smote.html Basic usage of the smote() function from the ImbalancedLearningRegression package. Loads the housing dataset from a URL and applies SMOTE with default parameters (k=5, samp_method='balance'). The result is stored in housing_smote. ```python >>> from ImbalancedLearningRegression import smote >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_smote = smote(data = housing, y = "SalePrice") ``` -------------------------------- ### cnn() Source: https://imbalancedlearningregression.readthedocs.io/en/latest/cnn.html Condensed Nearest Neighbor under-sampling method. It condenses the majority set by selecting a subset of majority samples from the original majority set. ```APIDOC ## cnn() ### Description Condensed Nearest Neighbor is an under-sampling method that condenses the majority set by selecting a subset of majority samples from the original majority set. ### Method Function call ### Signature cnn(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, n_seed=1, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None, k=1, n_jobs=1, k_neighbors_classifier=None) ### Parameters - **data** (Pandas dataframe) - Required - Pandas dataframe, the dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either `balance` or `extreme`. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **n_seed** (int) - Optional - Number of majority samples put into STORE at the beginning of under-sampling each normal bin. Must be a positive integer. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considerd as normal, and vise versa. - **rel_coef** (float) - Optional - Coefficient for box plot. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. - **k** (int) - Optional - The number of neighbors considered. Must be a positive integer. - **n_jobs** (int) - Optional - The number of parallel jobs to run for neighbors search. Must be an integer. See sklearn.neighbors.KNeighborsClassifier for more details. - **k_neighbors_classifier** (KNeighborsClassifier) - Optional - If users want to define more parameters of KNeighborsClassifier, such as `weights`, `algorithm`, `leaf_size`, and `metric`, they can create an instance of KNeighborsClassifier and pass it to this method. In that case, setting `k` and `n_jobs` will have no effect. ### Returns Re-sampled dataset. Type: Pandas dataframe. ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or once the index of a sample exists in both STORE and GRABBAG. ### Example ```python >>> from ImbalancedLearningRegression import cnn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_cnn = cnn(data = housing, y = "SalePrice") ``` ``` -------------------------------- ### smote(data, y, k=5, samp_method='balance', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) Source: https://imbalancedlearningregression.readthedocs.io/en/latest/smote.html The smote() function applies the Synthetic Minority Oversampling Technique to a dataset for regression. It takes a pandas dataframe and the target column name, and returns a re-sampled dataframe. ```APIDOC ## smote(data, y, k=5, samp_method='balance', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Description Synthetic Minority Oversampling Technique. SMOTE is an over-sampling method that synthesizes new samples by using one of the neighbors of a seed sample. ### Parameters - **data** (Pandas dataframe) - Required - The dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **k** (int) - Optional - The number of neighbors considered. Must be a positive integer. Default: 5. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either `balance` or `extreme`. Default: 'balance'. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. Default: True. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. Default: True. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. Default: 0.5. - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. Default: 'auto'. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considered as normal, and vice versa. Default: 'both'. - **rel_coef** (float) - Optional - Coefficient for box plot. Default: 1.5. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. Default: None. ### Returns - **Pandas dataframe** - Re-sampled dataset. ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or synthetic data contains missing values. ### Example ```python >>> from ImbalancedLearningRegression import smote >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_smote = smote(data = housing, y = "SalePrice") ``` ``` -------------------------------- ### tomeklinks() Source: https://imbalancedlearningregression.readthedocs.io/en/latest/tomeklinks.html Documentation for the tomeklinks function, an under-sampling method that removes TomekLinks from the dataset. ```APIDOC ## tomeklinks(data, y, option='majority', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Description TomekLinks is an under-sampling method that under-samples the majority/minority/both class(es) by removing TomekLinks. This function returns a re-sampled dataset. ### Method Function call ### Endpoint `tomeklinks(data, y, option='majority', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None)` ### Parameters #### Path Parameters - **data** (Pandas dataframe) - Required - Pandas dataframe, the dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **option** (str) - Optional - Sampling information to sample the data set. If `majority`, resample only the majority class; if `minority`, resample only the minority class; if `both`, resample both majority and minority class. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considerd as normal, and vise versa. - **rel_coef** (float) - Optional - Coefficient for box plot. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. ### Request Example ```python >>> from ImbalancedLearningRegression import tomeklinks >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_tomeklinks = tomeklinks(data = housing, y = "SalePrice") ``` ### Response #### Success Response - **Returns** (Pandas dataframe) - Re-sampled dataset. #### Response Example ```python housing_tomeklinks ``` ### Error Handling - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or synthetic data contains missing values. ``` -------------------------------- ### gn() Source: https://imbalancedlearningregression.readthedocs.io/en/latest/gn.html Over-sampling method that synthesizes new samples by introducing Gaussian noise on the numeric attributes and target variables of the seed samples. It can optionally perform random under-sampling. ```APIDOC ## gn(data, y, pert=0.02, samp_method='balance', under_samp=True, drop_na_col=True, drop_na_row=True, replace=False, manual_perc=False, perc_u=-1, perc_o=-1, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Description Over-sampling method that synthesizes new samples by introducing small perturbations on the numeric attributes and target variables of the seed samples. This method has an optional choice of random under-sampling. ### Parameters - **data** (Pandas dataframe) - Required - Pandas dataframe, the dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **pert** (float) - Optional - Perturbation amplitude. Must be a real number between 0 and 1 (0, 1]. Default: 0.02. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either 'balance' or 'extreme'. Default: 'balance'. - **under_samp** (bool) - Optional - If True, random under-sampling will be conducted on the normal bins. Default: True. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. Default: True. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. Default: True. - **replace** (bool) - Optional - For decimal part of the over-sampling percentage, a subset of original dataset will be chosen as base samples to introduce noise, the selection can be with or without replacement. Default: False. - **manual_perc** (bool) - Optional - Keep the same percentage of re-sampling for all bins. If True, perc_u is required to be a real number between 0 and 1 (0, 1), and perc_o is required to be a positive real number. Default: False. - **perc_u** (float) - Optional - User-specified fixed percentage of under-sampling for all bins. Must be a real number between 0 and 1 (0, 1) if manual_perc = True. Default: -1. - **perc_o** (float) - Optional - User-specified fixed percentage of over-sampling for all bins. Must be a positive real number if manual_perc = True. Default: -1. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. Default: 0.5. - **rel_method** (str) - Optional - Method to define the relevance function, either 'auto' or 'manual'. If 'manual', must specify rel_ctrl_pts_rg. Default: 'auto'. - **rel_xtrm_type** (str) - Optional - Distribution focus, 'high', 'low', or 'both'. If 'high', rare cases having small y values will be considered as normal, and vice versa. Default: 'both'. - **rel_coef** (float) - Optional - Coefficient for box plot. Default: 1.5. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. Default: None. ### Returns - **Pandas dataframe** - Re-sampled dataset. ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or synthetic data contains missing values. ### Example ```python >>> from ImbalancedLearningRegression import gn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_gn = gn(data = housing, y = "SalePrice"") ``` -------------------------------- ### ro() Source: https://imbalancedlearningregression.readthedocs.io/en/latest/ro.html Random Over-sampling method that synthesizes new samples by randomly copying minority samples. It takes a pandas dataframe and target column name, and returns a re-sampled dataframe. ```APIDOC ## ro(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, replace=True, manual_perc=False, perc_o=-1, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Description Random Over-sampling is an over-sampling method that synthesizes new samples by randomly copying minority samples. This function re-samples the dataset to balance the target variable distribution. ### Parameters - **data** (Pandas dataframe) - Required - The dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either `balance` or `extreme`. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **replace** (bool) - Optional - Randomly select sample to duplicate: with or without replacement. - **manual_perc** (bool) - Optional - Keep the same percentage of re-sampling for all bins. If `True`, `perc_o` is required to be a positive real number. - **perc_o** (float) - Optional - User-specified fixed percentage of over-sampling for all bins. Must be a positive real number if `manual_perc = True`. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1].".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".".". - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considerd as normal, and vise versa. - **rel_coef** (float) - Optional - Coefficient for box plot. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. ### Returns - **Pandas dataframe** - Re-sampled dataset. ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or synthetic data contains missing values. ### Example ```python >>> from ImbalancedLearningRegression import ro >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_ro = ro(data = housing, y = "SalePrice") ``` ``` -------------------------------- ### enn(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None, k=3, n_jobs=1, k_neighbors_classifier=None) Source: https://imbalancedlearningregression.readthedocs.io/en/latest/enn.html Performs Edited Nearest Neighbor under-sampling on a dataset. It removes majority samples that are misclassified by their k nearest neighbors, returning a re-sampled Pandas dataframe. ```APIDOC ## enn(data, y, samp_method='balance', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None, k=3, n_jobs=1, k_neighbors_classifier=None) ### Description Edited Nearest Neighbor is an under-sampling method that edits the majority set by removing some of the majority samples from the original majority set. ### Method Function call ### Endpoint enn() ### Parameters - **data** (Pandas dataframe) - Required - Pandas dataframe, the dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either `balance` or `extreme`. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considerd as normal, and vise versa. - **rel_coef** (float) - Optional - Coefficient for box plot. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. - **k** (int) - Optional - The number of neighbors considered. Must be a positive integer. - **n_jobs** (int) - Optional - The number of parallel jobs to run for neighbors search. Must be an integer. See sklearn.neighbors.KNeighborsClassifier for more details. - **k_neighbors_classifier** (KNeighborsClassifier) - Optional - If users want to define more parameters of KNeighborsClassifier, such as `weights`, `algorithm`, `leaf_size`, and `metric`, they can create an instance of KNeighborsClassifier and pass it to this method. In that case, setting `k` and `n_jobs` will have no effect. ### Returns Re-sampled dataset. ### Return Type Pandas dataframe ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one. ### Example ```python >>> from ImbalancedLearningRegression import enn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_enn = enn(data = housing, y = "SalePrice") ``` ``` -------------------------------- ### adasyn(data, y, k=5, samp_method='balance', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) Source: https://imbalancedlearningregression.readthedocs.io/en/latest/adasyn.html The adasyn() function is an over-sampling method that generates synthetic samples for imbalanced regression datasets. It takes a Pandas dataframe and the target column name, and returns a re-sampled dataframe. ```APIDOC ## adasyn(data, y, k=5, samp_method='balance', drop_na_col=True, drop_na_row=True, rel_thres=0.5, rel_method='auto', rel_xtrm_type='both', rel_coef=1.5, rel_ctrl_pts_rg=None) ### Description ADASYN is an over-sampling method that is similar to SMOTE, but more samples are generated for seed samples that are difficult to be learned. ### Parameters - **data** (Pandas dataframe) - Required - Pandas dataframe, the dataset to re-sample. - **y** (str) - Required - Column name of the target variable in the Pandas dataframe. - **k** (int) - Optional - The number of neighbors considered. Must be a positive integer. Default: 5. - **samp_method** (str) - Optional - Method to determine re-sampling percentage. Either `balance` or `extreme`. Default: 'balance'. - **drop_na_col** (bool) - Optional - Determine whether or not automatically drop columns containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. Default: True. - **drop_na_row** (bool) - Optional - Determine whether or not automatically drop rows containing NaN values. The data frame should not contain any missing values, so it is suggested to keep it as default. Default: True. - **rel_thres** (float) - Optional - Relevance threshold, above which a sample is considered rare. Must be a real number between 0 and 1 (0, 1]. Default: 0.5. - **rel_method** (str) - Optional - Method to define the relevance function, either `auto` or `manual`. If `manual`, must specify `rel_ctrl_pts_rg`. Default: 'auto'. - **rel_xtrm_type** (str) - Optional - Distribution focus, `high`, `low`, or `both`. If `high`, rare cases having small y values will be considerd as normal, and vise versa. Default: 'both'. - **rel_coef** (float) - Optional - Coefficient for box plot. Default: 1.5. - **rel_ctrl_pts_rg** (2D array) - Optional - Manually specify the regions of interest. See SMOGN advanced example for more details. Default: None. ### Returns - **Pandas dataframe** - Re-sampled dataset. ### Raises - **ValueError** - If an input attribute has wrong data type or invalid value, or relevance values are all zero or all one, or synthetic data contains missing values. - **AssertionError** - If normalized ratio ri does not sum up to one. ### Example ```python >>> from ImbalancedLearningRegression import adasyn >>> housing = pandas.read_csv("https://raw.githubusercontent.com/paobranco/ImbalancedLearningRegression/master/data/housing.csv") >>> housing_adasyn = adasyn(data = housing, y = "SalePrice") ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.