-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
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
)
Metadata
Metadata
Assignees
Labels
No labels