Utilities

fast_automl.utils.TransformerMixin

Version of scikit-learn's TransformerMixin which implements a default inert fit method.

Methods

fit(self, X, y=None) [source]

This function doesn't do anything, but is necessary to include the transformer in a Pipeline.

Returns: self :

transform(self, X) [source]

Must be implemented by the transformer.

fast_automl.utils.ColumnSelector

class fast_automl.utils.ColumnSelector(columns) [source]

Selects columns from a dataframe.

Parameters: columns : list

List of columns to select.

Examples

from fast_automl.utils import ColumnSelector

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline

X = pd.DataFrame({
    'x0': [-1, -2, 1, 2],
    'x1': [-1, -1, 1, 1]
})
y = np.array([1, 1, 2, 2])

reg = make_pipeline(
    ColumnSelector(['x1']),
    LinearRegression()
).fit(X, y)
reg.score(X, y)

Methods

transform(self, X, y=None) [source]

Parameters: X : array-like of shape (n_samples, n_features)

Training data.

y : optional, array-like of shape (n_samples, n_targets)

Target values.

Returns: X or (X, y) : Where X columns have been selected

fast_automl.utils.ColumnRemover

class fast_automl.utils.ColumnRemover(columns) [source]

Removes columns from a dataframe.

Parameters: columns : list

List of columns to remove.

Examples

from fast_automl.utils import ColumnRemover

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline

X = pd.DataFrame({
    'x0': [-1, -2, 1, 2],
    'x1': [-1, -1, 1, 1]
})
y = np.array([1, 1, 2, 2])

reg = make_pipeline(
    ColumnRemover(['x0']),
    LinearRegression()
).fit(X, y)
reg.score(X, y)

Methods

transform(self, X, y=None) [source]

Parameters: X : array-like of shape (n_samples, n_features)

Training data.

y : optional, array-like of shape (n_samples, n_targets)

Target values.

Returns: X or (X, y) : Where X columns have been removed

fast_automl.utils.BoundRegressor

class fast_automl.utils.BoundRegressor(estimator) [source]

Constrains the predicted target value to be within the range of targets in the training data.

Parameters: estimator : scikit-learn style regressor

Attributes: estimator_ : scikit-learn style regressor

Fitted regressor.

y_max_ : scalar

Maximum target value in training data.

y_min_ : scalar

Minimum target value in training data.

Examples

from fast_automl.utils import BoundRegressor

import numpy as np
from sklearn.linear_model import LinearRegression

X_train = np.array([
    [1, 2],
    [7, 8]
])
X_test = np.array([
    [3, 4],
    [5, 1000]
])
y_train = np.array([1.5, 7.5])
y_test = np.array([3.5, 5.5])

reg = LinearRegression().fit(X_train, y_train)
reg.predict(X_test)

Out:

array([3.5, 7.5])

Methods

fit(self, X, y, sample_weight=None) [source]

predict(self, X) [source]