EpistasisLab / EpistasisLab/tpot

Customer Transformers Not Working

Open
#1,360 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
10.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

TPOT does not work with custom transformers. When I ran to optimization below, I got the warning that "Warning: Normalization2 is not available and will not be used by TPOT."

class Normalization2(BaseEstimator, TransformerMixin):
def __init__(self, method='minmax', feature_range=(0, 1)):
self.method = method
self.feature_range = feature_range
self.min_ = None
self.max_ = None

def fit(self, spectrum):
if self.method == 'minmax':
self.min_ = np.min(spectrum)
self.max_ = np.max(spectrum)
elif self.method == 'zscore':
self.mean = np.mean(spectrum)
self.std = np.std(spectrum)
else:
raise ValueError("Unsupported normalization method. Choose 'minmax' or 'zscore'.")
return self

def transform(self, spectrum):
if self.method == 'minmax':
if self.min_ is None or self.max_ is None:
raise ValueError("Normalization instance is not fitted yet.")
range_min, range_max = self.feature_range
return ((spectrum - self.min_) / (self.max_ - self.min_)) * (range_max - range_min) + range_min
elif self.method == 'zscore':
if self.mean is None or self.std is None:
raise ValueError("Normalization instance is not fitted yet.")
return (spectrum - self.mean) / self.std

config = {
'Normalization2': { # Wrapper for Normalization
'method': ['minmax'],
'feature_range': [(0, 1)],
},
'sklearn.linear_model.Ridge': { # Replace PLSRegression with Ridge
'alpha': [0.1, 1.0, 10.0], # Regularization strength
'solver': ['auto', 'svd', 'cholesky', 'lsqr', 'sag', 'saga'], # Solvers to optimize
},
}

spot = TPOTRegressor(
generations=100,
population_size=100,
cv=3
config_dict=config,
verbosity=2,
n_jobs=-1,
max_eval_time_mins=10
)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.