class RIFT.misc.ModifiedScikitFit.Binarizer(threshold=0.0, copy=True)

Bases: BaseEstimator, TransformerMixin

Binarize data (set feature values to 0 or 1) according to a threshold Values greater than the threshold map to 1, while values less than or equal to the threshold map to 0. With the default threshold of 0, only positive values map to 1. Binarization is a common operation on text count data where the analyst can decide to only consider the presence or absence of a feature rather than a quantified number of occurrences for instance. It can also be used as a pre-processing step for estimators that consider boolean random variables (e.g. modelled using the Bernoulli distribution in a Bayesian setting). Read more in the User Guide. Parameters ———- threshold : float, optional (0.0 by default)

Feature values below or equal to this are replaced by 0, above it by 1. Threshold may not be less than 0 for operations on sparse matrices.

copyboolean, optional, default True

set to False to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix).

Notes

If the input is a sparse matrix, only the non-zero values are subject to update by the Binarizer class. This estimator is stateless (besides constructor parameters), the fit method does nothing but is useful when used in a pipeline. See also ——– binarize: Equivalent function without the object oriented API.

fit(X, y=None)

Do nothing and return the estimator unchanged This method is just there to implement the usual API and hence work in pipelines.

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → Binarizer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

transform(X, y=None, copy=None)

Binarize each element of X Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to binarize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

class RIFT.misc.ModifiedScikitFit.KernelCenterer

Bases: BaseEstimator, TransformerMixin

Center a kernel matrix Let K(x, z) be a kernel defined by phi(x)^T phi(z), where phi is a function mapping x to a Hilbert space. KernelCenterer centers (i.e., normalize to have zero mean) the data without explicitly computing phi(x). It is equivalent to centering phi(x) with sklearn.preprocessing.StandardScaler(with_std=False). Read more in the User Guide.

fit(K, y=None)

Fit KernelCenterer Parameters ———- K : numpy array of shape [n_samples, n_samples]

Kernel matrix.

Returns

self : returns an instance of self.

set_fit_request(*, K: bool | None | str = '$UNCHANGED$') → KernelCenterer

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

Kstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for K parameter in fit.

Returns

selfobject

The updated object.

set_transform_request(*, K: bool | None | str = '$UNCHANGED$', copy: bool | None | str = '$UNCHANGED$') → KernelCenterer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

Kstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for K parameter in transform.

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

transform(K, y=None, copy=True)

Center kernel matrix. Parameters ———- K : numpy array of shape [n_samples1, n_samples2]

Kernel matrix.

copyboolean, optional, default True

Set to False to perform inplace computation.

Returns

K_new : numpy array of shape [n_samples1, n_samples2]

class RIFT.misc.ModifiedScikitFit.MaxAbsScaler(copy=True)

Bases: BaseEstimator, TransformerMixin

Scale each feature by its maximum absolute value. This estimator scales and translates each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. It does not shift/center the data, and thus does not destroy any sparsity. This scaler can also be applied to sparse CSR or CSC matrices. .. versionadded:: 0.17 Parameters ———- copy : boolean, optional, default is True

Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).

Attributes

scale_ndarray, shape (n_features,)

Per feature relative scaling of the data. .. versionadded:: 0.17

scale_ attribute.

max_abs_ndarray, shape (n_features,)

Per feature maximum absolute value.

n_samples_seen_int

The number of samples processed by the estimator. Will be reset on new calls to fit, but increments across partial_fit calls.

See also

maxabs_scale: Equivalent function without the object oriented API.

fit(X, y=None)

Compute the maximum absolute value to be used for later scaling. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the per-feature minimum and maximum used for later scaling along the features axis.

inverse_transform(X)

Scale back the data to the original representation Parameters ———- X : {array-like, sparse matrix}

The data that should be transformed back.

partial_fit(X, y=None)

Online computation of max absolute value of X for later scaling. All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y: Passthrough for Pipeline compatibility.

transform(X, y=None)

Scale the data Parameters ———- X : {array-like, sparse matrix}

The data that should be scaled.

class RIFT.misc.ModifiedScikitFit.MinMaxScaler(feature_range=(0, 1), copy=True)

Bases: BaseEstimator, TransformerMixin

Transforms features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is given by:

X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min

where min, max = feature_range. This transformation is often used as an alternative to zero mean, unit variance scaling. Read more in the User Guide. Parameters ———- feature_range : tuple (min, max), default=(0, 1)

Desired range of transformed data.

copyboolean, optional, default True

Set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array).

Attributes

min_ndarray, shape (n_features,)

Per feature adjustment for minimum.

scale_ndarray, shape (n_features,)

Per feature relative scaling of the data. .. versionadded:: 0.17

scale_ attribute.

data_min_ndarray, shape (n_features,)

Per feature minimum seen in the data .. versionadded:: 0.17

data_min_ instead of deprecated data_min.

data_max_ndarray, shape (n_features,)

Per feature maximum seen in the data .. versionadded:: 0.17

data_max_ instead of deprecated data_max.

data_range_ndarray, shape (n_features,)

Per feature range (data_max_ - data_min_) seen in the data .. versionadded:: 0.17

data_range_ instead of deprecated data_range.

See also

minmax_scale: Equivalent function without the object oriented API.

property data_min
property data_range
fit(X, y=None)

Compute the minimum and maximum to be used for later scaling. Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to compute the per-feature minimum and maximum used for later scaling along the features axis.

inverse_transform(X)

Undo the scaling of X according to feature_range. Parameters ———- X : array-like, shape [n_samples, n_features]

Input data that will be transformed. It cannot be sparse.

partial_fit(X, y=None)

Online computation of min and max on X for later scaling. All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream. Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y : Passthrough for Pipeline compatibility.

transform(X)

Scaling features of X according to feature_range. Parameters ———- X : array-like, shape [n_samples, n_features]

Input data that will be transformed.

class RIFT.misc.ModifiedScikitFit.Normalizer(norm='l2', copy=True)

Bases: BaseEstimator, TransformerMixin

Normalize samples individually to unit norm. Each sample (i.e. each row of the data matrix) with at least one non zero component is rescaled independently of other samples so that its norm (l1 or l2) equals one. This transformer is able to work both with dense numpy arrays and scipy.sparse matrix (use CSR format if you want to avoid the burden of a copy / conversion). Scaling inputs to unit norms is a common operation for text classification or clustering for instance. For instance the dot product of two l2-normalized TF-IDF vectors is the cosine similarity of the vectors and is the base similarity metric for the Vector Space Model commonly used by the Information Retrieval community. Read more in the User Guide. Parameters ———- norm : ‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default)

The norm to use to normalize each non zero sample.

copyboolean, optional, default True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix).

Notes

This estimator is stateless (besides constructor parameters), the fit method does nothing but is useful when used in a pipeline. See also ——– normalize: Equivalent function without the object oriented API.

fit(X, y=None)

Do nothing and return the estimator unchanged This method is just there to implement the usual API and hence work in pipelines.

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → Normalizer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

transform(X, y=None, copy=None)

Scale each non zero row of X to unit norm Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

class RIFT.misc.ModifiedScikitFit.OneHotEncoder(n_values='auto', categorical_features='all', dtype=<class 'numpy.float64'>, sparse=True, handle_unknown='error')

Bases: BaseEstimator, TransformerMixin

Encode categorical integer features using a one-hot aka one-of-K scheme. The input to this transformer should be a matrix of integers, denoting the values taken on by categorical (discrete) features. The output will be a sparse matrix where each column corresponds to one possible value of one feature. It is assumed that input features take on values in the range [0, n_values). This encoding is needed for feeding categorical data to many scikit-learn estimators, notably linear models and SVMs with the standard kernels. Note: a one-hot encoding of y labels should use a LabelBinarizer instead. Read more in the User Guide. Parameters ———- n_values : ‘auto’, int or array of ints

Number of values per feature. - ‘auto’ : determine value range from training data. - int : number of categorical values per feature.

Each feature value should be in range(n_values)

  • arrayn_values[i] is the number of categorical values in

    X[:, i]. Each feature value should be in range(n_values[i])

categorical_features“all” or array of indices or mask

Specify what features are treated as categorical. - ‘all’ (default): All features are treated as categorical. - array of indices: Array of categorical feature indices. - mask: Array of length n_features and with dtype=bool. Non-categorical features are always stacked to the right of the matrix.

dtypenumber type, default=np.float

Desired dtype of output.

sparseboolean, default=True

Will return sparse matrix if set True else will return an array.

handle_unknownstr, ‘error’ or ‘ignore’

Whether to raise an error or ignore if a unknown categorical feature is present during transform.

Attributes

active_features_array

Indices for active features, meaning values that actually occur in the training set. Only available when n_values is 'auto'.

feature_indices_array of shape (n_features,)

Indices to feature ranges. Feature i in the original data is mapped to features from feature_indices_[i] to feature_indices_[i+1] (and then potentially masked by active_features_ afterwards)

n_values_array of shape (n_features,)

Maximum number of values per feature.

Examples

Given a dataset with three features and two samples, we let the encoder find the maximum value per feature and transform the data to a binary one-hot encoding. >>> from sklearn.preprocessing import OneHotEncoder >>> enc = OneHotEncoder() >>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]]) # doctest: +ELLIPSIS OneHotEncoder(categorical_features=’all’, dtype=<… ‘numpy.float64’>,

handle_unknown=’error’, n_values=’auto’, sparse=True)

>>> enc.n_values_
array([2, 3, 4])
>>> enc.feature_indices_
array([0, 2, 5, 9])
>>> enc.transform([[0, 1, 1]]).toarray()
array([[ 1.,  0.,  0.,  1.,  0.,  0.,  1.,  0.,  0.]])
See also
--------
sklearn.feature_extraction.DictVectorizer : performs a one-hot encoding of
  dictionary items (also handles string-valued features).
sklearn.feature_extraction.FeatureHasher : performs an approximate one-hot
  encoding of dictionary items or strings.
sklearn.preprocessing.LabelBinarizer : binarizes labels in a one-vs-all
  fashion.
sklearn.preprocessing.MultiLabelBinarizer : transforms between iterable of
  iterables and a multilabel format, e.g. a (samples x classes) binary
  matrix indicating the presence of a class label.
sklearn.preprocessing.LabelEncoder : encodes labels with values between 0
  and n_classes-1.
fit(X, y=None)

Fit OneHotEncoder to X. Parameters ———- X : array-like, shape [n_samples, n_feature]

Input array of type int.

Returns

self

fit_transform(X, y=None)

Fit OneHotEncoder to X, then transform X. Equivalent to self.fit(X).transform(X), but more convenient and more efficient. See fit for the parameters, transform for the return value.

transform(X)

Transform X using one-hot encoding. Parameters ———- X : array-like, shape [n_samples, n_features]

Input array of type int.

Returns

X_outsparse matrix if sparse=True else a 2-d array, dtype=int

Transformed input.

class RIFT.misc.ModifiedScikitFit.RobustScaler(with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True)

Bases: BaseEstimator, TransformerMixin

Scale features using statistics that are robust to outliers. This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile). Centering and scaling happen independently on each feature (or each sample, depending on the axis argument) by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the transform method. Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results. .. versionadded:: 0.17 Read more in the User Guide. Parameters ———- with_centering : boolean, True by default

If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.

with_scalingboolean, True by default

If True, scale the data to interquartile range.

quantile_rangetuple (q_min, q_max), 0.0 < q_min < q_max < 100.0

Default: (25.0, 75.0) = (1st quantile, 3rd quantile) = IQR Quantile range used to calculate scale_. .. versionadded:: 0.18

copyboolean, optional, default is True

If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.

Attributes

center_array of floats

The median value for each feature in the training set.

scale_array of floats

The (scaled) interquartile range for each feature in the training set. .. versionadded:: 0.17

scale_ attribute.

See also

robust_scale: Equivalent function without the object oriented API. sklearn.decomposition.PCA

Further removes the linear correlation across features with ‘whiten=True’.

Notes

See examples/preprocessing/plot_robust_scaling.py for an example. https://en.wikipedia.org/wiki/Median_(statistics) https://en.wikipedia.org/wiki/Interquartile_range

fit(X, y=None)

Compute the median and quantiles to be used for scaling. Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to compute the median and quantiles used for later scaling along the features axis.

inverse_transform(X)

Scale back the data to the original representation Parameters ———- X : array-like

The data used to scale along the specified axis.

transform(X, y=None)

Center and scale the data Parameters ———- X : array-like

The data used to scale along the specified axis.

class RIFT.misc.ModifiedScikitFit.StandardScaler(copy=True, with_mean=True, with_std=True)

Bases: BaseEstimator, TransformerMixin

Standardize features by removing the mean and scaling to unit variance Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Mean and standard deviation are then stored to be used on later data using the transform method. Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual feature do not more or less look like standard normally distributed data (e.g. Gaussian with 0 mean and unit variance). For instance many elements used in the objective function of a learning algorithm (such as the RBF kernel of Support Vector Machines or the L1 and L2 regularizers of linear models) assume that all features are centered around 0 and have variance in the same order. If a feature has a variance that is orders of magnitude larger that others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected. This scaler can also be applied to sparse CSR or CSC matrices by passing with_mean=False to avoid breaking the sparsity structure of the data. Read more in the User Guide. Parameters ———- with_mean : boolean, True by default

If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.

with_stdboolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

copyboolean, optional, default True

If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.

Attributes

scale_ndarray, shape (n_features,)

Per feature relative scaling of the data. .. versionadded:: 0.17

scale_ is recommended instead of deprecated std_.

mean_array of floats with shape [n_features]

The mean value for each feature in the training set.

var_array of floats with shape [n_features]

The variance for each feature in the training set. Used to compute scale_

n_samples_seen_int

The number of samples processed by the estimator. Will be reset on new calls to fit, but increments across partial_fit calls.

See also

scale: Equivalent function without the object oriented API. sklearn.decomposition.PCA

Further removes the linear correlation across features with ‘whiten=True’.

fit(X, y=None)

Compute the mean and std to be used for later scaling. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y: Passthrough for Pipeline compatibility.

inverse_transform(X, copy=None)

Scale back the data to the original representation Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to scale along the features axis.

partial_fit(X, y=None)

Online computation of mean and std on X for later scaling. All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream. The algorithm for incremental mean and std is given in Equation 1.5a,b in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. “Algorithms for computing the sample variance: Analysis and recommendations.” The American Statistician 37.3 (1983): 242-247: Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y: Passthrough for Pipeline compatibility.

set_inverse_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → StandardScaler

Configure whether metadata should be requested to be passed to the inverse_transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in inverse_transform.

Returns

selfobject

The updated object.

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → StandardScaler

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

property std_
transform(X, y=None, copy=None)

Perform standardization by centering and scaling Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to scale along the features axis.

RIFT.misc.ModifiedScikitFit.add_dummy_feature(X, value=1.0)

Augment dataset with an additional dummy feature. This is useful for fitting an intercept term with implementations which cannot otherwise fit it directly. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

Data.

valuefloat

Value to use for the dummy feature.

Returns

X{array, sparse matrix}, shape [n_samples, n_features + 1]

Same data with dummy feature added as first column.

Examples

>>> from sklearn.preprocessing import add_dummy_feature
>>> add_dummy_feature([[0, 1], [1, 0]])
array([[ 1.,  0.,  1.],
       [ 1.,  1.,  0.]])
RIFT.misc.ModifiedScikitFit.binarize(X, threshold=0.0, copy=True)

Boolean thresholding of array-like or scipy.sparse matrix Read more in the User Guide. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to binarize, element by element. scipy.sparse matrices should be in CSR or CSC format to avoid an un-necessary copy.

thresholdfloat, optional (0.0 by default)

Feature values below or equal to this are replaced by 0, above it by 1. Threshold may not be less than 0 for operations on sparse matrices.

copyboolean, optional, default True

set to False to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR / CSC matrix and if axis is 1).

See also

Binarizer: Performs binarization using the Transformer API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.maxabs_scale(X, axis=0, copy=True)

Scale each feature to the [-1, 1] range without breaking the sparsity. This estimator scales each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. This scaler can also be applied to sparse CSR or CSC matrices. Parameters ———- axis : int (0 by default)

axis used to scale along. If 0, independently scale each feature, otherwise (if 1) scale each sample.

copyboolean, optional, default is True

Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).

See also

MaxAbsScaler: Performs scaling to the [-1, 1] range using the``Transformer`` API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.minmax_scale(X, feature_range=(0, 1), axis=0, copy=True)

Transforms features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is given by:

X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min

where min, max = feature_range. This transformation is often used as an alternative to zero mean, unit variance scaling. Read more in the User Guide. .. versionadded:: 0.17

minmax_scale function interface to sklearn.preprocessing.MinMaxScaler.

Parameters

feature_rangetuple (min, max), default=(0, 1)

Desired range of transformed data.

axisint (0 by default)

axis used to scale along. If 0, independently scale each feature, otherwise (if 1) scale each sample.

copyboolean, optional, default is True

Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).

See also

MinMaxScaler: Performs scaling to a given range using the``Transformer`` API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.normalize(X, norm='l2', axis=1, copy=True, return_norm=False)

Scale input vectors individually to unit norm (vector length). Read more in the User Guide. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to normalize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

norm‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default)

The norm to use to normalize each non zero sample (or each non-zero feature if axis is 0).

axis0 or 1, optional (1 by default)

axis used to normalize the data along. If 1, independently normalize each sample, otherwise (if 0) normalize each feature.

copyboolean, optional, default True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix and if axis is 1).

return_normboolean, default False

whether to return the computed norms

See also

Normalizer: Performs normalization using the Transformer API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.robust_scale(X, axis=0, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True)

Standardize a dataset along any axis Center to the median and component wise scale according to the interquartile range. Read more in the User Guide. Parameters ———- X : array-like

The data to center and scale.

axisint (0 by default)

axis used to compute the medians and IQR along. If 0, independently scale each feature, otherwise (if 1) scale each sample.

with_centeringboolean, True by default

If True, center the data before scaling.

with_scalingboolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

quantile_rangetuple (q_min, q_max), 0.0 < q_min < q_max < 100.0

Default: (25.0, 75.0) = (1st quantile, 3rd quantile) = IQR Quantile range used to calculate scale_. .. versionadded:: 0.18

copyboolean, optional, default is True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix and if axis is 1).

Notes

This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems. Instead the caller is expected to either set explicitly with_centering=False (in that case, only variance scaling will be performed on the features of the CSR matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory. To avoid memory copy the caller should pass a CSR matrix. See also ——– RobustScaler: Performs centering and scaling using the Transformer API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.scale(X, axis=0, with_mean=True, with_std=True, copy=True)

Standardize a dataset along any axis Center to the mean and component wise scale to unit variance. Read more in the User Guide. Parameters ———- X : {array-like, sparse matrix}

The data to center and scale.

axisint (0 by default)

axis used to compute the means and standard deviations along. If 0, independently standardize each feature, otherwise (if 1) standardize each sample.

with_meanboolean, True by default

If True, center the data before scaling.

with_stdboolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

copyboolean, optional, default True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSC matrix and if axis is 1).

Notes

This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems. Instead the caller is expected to either set explicitly with_mean=False (in that case, only variance scaling will be performed on the features of the CSC matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory. To avoid memory copy the caller should pass a CSC matrix. See also ——– StandardScaler: Performs scaling to unit variance using the``Transformer`` API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).