Skip to content

fixes max_eval_time_mins and max_eval_time_mins to allow None and inf - also allows steady state estimator to use template search spaces #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def calculate_version():

''',
zip_safe=True,
install_requires=['numpy==1.26.4',
install_requires=['numpy>=1.26.4',
'scipy>=1.3.1',
'scikit-learn>=1.4.2,<1.6',
'scikit-learn>=1.6',
'update_checker>=0.16',
'tqdm>=4.36.1',
'stopit>=1.1.1',
'pandas>=2.2.0',
'joblib>=1.1.1',
'xgboost>=1.7.0',
'xgboost>=3.0.0',
'matplotlib>=3.6.2',
'traitlets>=5.8.0',
'lightgbm>=3.3.3',
Expand Down
34 changes: 17 additions & 17 deletions tpot/builtin_modules/arithmetictransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"""
import random
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.base import TransformerMixin, BaseEstimator


#operations are done along axis
#TODO potentially we could do operations on every combo (mul would be all possible pairs multiplied with each other)
class ArithmeticTransformer(BaseEstimator,TransformerMixin):
class ArithmeticTransformer(TransformerMixin, BaseEstimator):

#functions = ["add", "mul_neg_1", "mul", "safe_reciprocal", "eq","ne","ge","gt","le","lt", "min","max","0","1"]
def __init__(self, function,):
Expand Down Expand Up @@ -140,7 +140,7 @@ def issorted(x, rev=False):



class AddTransformer(BaseEstimator,TransformerMixin):
class AddTransformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that adds all elements along axis 1.
Expand All @@ -163,7 +163,7 @@ def transform_helper(self, X):
X = np.expand_dims(X,0)
return np.expand_dims(np.sum(X,1),1)

class mul_neg_1_Transformer(BaseEstimator,TransformerMixin):
class mul_neg_1_Transformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that multiplies all elements by -1.
Expand All @@ -186,7 +186,7 @@ def transform_helper(self, X):
X = np.expand_dims(X,0)
return X*-1

class MulTransformer(BaseEstimator,TransformerMixin):
class MulTransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -210,7 +210,7 @@ def transform_helper(self, X):
X = np.expand_dims(X,0)
return np.expand_dims(np.prod(X,1),1)

class SafeReciprocalTransformer(BaseEstimator,TransformerMixin):
class SafeReciprocalTransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -234,7 +234,7 @@ def transform_helper(self, X):
X = np.expand_dims(X,0)
return np.divide(1.0, X.astype(float), out=np.zeros_like(X).astype(float), where=X!=0) #TODO remove astypefloat?

class EQTransformer(BaseEstimator,TransformerMixin):
class EQTransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -258,7 +258,7 @@ def transform_helper(self, X):
X = np.expand_dims(X,0)
return np.expand_dims(np.all(X == X[0,:], axis = 1),1).astype(float)

class NETransformer(BaseEstimator,TransformerMixin):
class NETransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -284,7 +284,7 @@ def transform_helper(self, X):



class GETransformer(BaseEstimator,TransformerMixin):
class GETransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -310,7 +310,7 @@ def transform_helper(self, X):
return result.astype(float)


class GTTransformer(BaseEstimator,TransformerMixin):
class GTTransformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that takes checks if all elements in a row are greater than 0.
Expand All @@ -335,7 +335,7 @@ def transform_helper(self, X):
return result.astype(float)


class LETransformer(BaseEstimator,TransformerMixin):
class LETransformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that takes checks if all elements in a row are less than or equal to 0.
Expand All @@ -360,7 +360,7 @@ def transform_helper(self, X):
return result.astype(float)


class LTTransformer(BaseEstimator,TransformerMixin):
class LTTransformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that takes checks if all elements in a row are less than 0.
Expand All @@ -385,7 +385,7 @@ def transform_helper(self, X):
return result.astype(float)


class MinTransformer(BaseEstimator,TransformerMixin):
class MinTransformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that takes the minimum of all elements in a row.
Expand All @@ -410,7 +410,7 @@ def transform_helper(self, X):



class MaxTransformer(BaseEstimator,TransformerMixin):
class MaxTransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -435,7 +435,7 @@ def transform_helper(self, X):
return np.expand_dims(np.amax(X,1),1)


class ZeroTransformer(BaseEstimator,TransformerMixin):
class ZeroTransformer(TransformerMixin, BaseEstimator):

def __init__(self):
"""
Expand All @@ -460,7 +460,7 @@ def transform_helper(self, X):
return np.zeros((X.shape[0],1))


class OneTransformer(BaseEstimator,TransformerMixin):
class OneTransformer(TransformerMixin, BaseEstimator):
def __init__(self):
"""
A transformer that returns an array of ones.
Expand All @@ -484,7 +484,7 @@ def transform_helper(self, X):
return np.ones((X.shape[0],1))


class NTransformer(BaseEstimator,TransformerMixin):
class NTransformer(TransformerMixin, BaseEstimator):

def __init__(self, n):
"""
Expand Down
6 changes: 3 additions & 3 deletions tpot/builtin_modules/column_one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import numpy as np
from scipy import sparse

from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.utils import check_array
from sklearn.preprocessing import OneHotEncoder, OrdinalEncoder
import sklearn
Expand Down Expand Up @@ -69,7 +69,7 @@ def _X_selected(X, selected):



class ColumnOneHotEncoder(BaseEstimator, TransformerMixin):
class ColumnOneHotEncoder(TransformerMixin, BaseEstimator ):


def __init__(self, columns='auto', drop=None, handle_unknown='infrequent_if_exist', sparse_output=False, min_frequency=None,max_categories=None):
Expand Down Expand Up @@ -205,7 +205,7 @@ def transform(self, X):
else:
return np.hstack((X_not_sel, X_sel))

class ColumnOrdinalEncoder(BaseEstimator, TransformerMixin):
class ColumnOrdinalEncoder(TransformerMixin, BaseEstimator ):


def __init__(self, columns='auto', handle_unknown='error', unknown_value = -1, encoded_missing_value = np.nan, min_frequency=None,max_categories=None):
Expand Down
4 changes: 2 additions & 2 deletions tpot/builtin_modules/estimatortransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@

"""
from numpy import ndarray
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.model_selection import cross_val_predict
from sklearn.utils.validation import check_is_fitted
from sklearn.utils.metaestimators import available_if
import numpy as np
from sklearn.utils.validation import check_is_fitted

class EstimatorTransformer(BaseEstimator, TransformerMixin):
class EstimatorTransformer(TransformerMixin, BaseEstimator ):
def __init__(self, estimator, method='auto', passthrough=False, cross_val_predict_cv=None):
"""
A class for using a sklearn estimator as a transformer. When calling fit_transform, this class returns the out put of cross_val_predict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sklearn.base import BaseEstimator
from sklearn.feature_selection._base import SelectorMixin

class FeatureEncodingFrequencySelector(BaseEstimator, SelectorMixin):
class FeatureEncodingFrequencySelector(SelectorMixin, BaseEstimator):
"""Feature selector based on Encoding Frequency. Encoding frequency is the frequency of each unique element(0/1/2/3) present in a feature set.
Features are selected on the basis of a threshold assigned for encoding frequency. If frequency of any unique element is less than or equal to threshold, the feature is removed. """

Expand Down
8 changes: 5 additions & 3 deletions tpot/builtin_modules/feature_set_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


#TODO clean this up and make sure it works
class FeatureSetSelector(BaseEstimator, SelectorMixin):
class FeatureSetSelector(SelectorMixin, BaseEstimator):
"""
Select predefined feature subsets.

Expand Down Expand Up @@ -109,8 +109,10 @@ def fit(self, X, y=None):

# def transform(self, X):

def _get_tags(self):
tags = {"allow_nan": True, "requires_y": False}
def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.input_tags.allow_nan = True
tags.target_tags.required = False # formally requires_y
return tags

def _get_support_mask(self):
Expand Down
6 changes: 3 additions & 3 deletions tpot/builtin_modules/feature_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@


import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.utils import check_array
from sklearn.decomposition import PCA

from .one_hot_encoder import OneHotEncoder, auto_select_categorical_features, _X_selected


class CategoricalSelector(BaseEstimator, TransformerMixin):
class CategoricalSelector(TransformerMixin, BaseEstimator ):
"""Meta-transformer for selecting categorical features and transform them using OneHotEncoder.

Parameters
Expand Down Expand Up @@ -101,7 +101,7 @@ def transform(self, X):
return ohe.fit_transform(X_sel)


class ContinuousSelector(BaseEstimator, TransformerMixin):
class ContinuousSelector(TransformerMixin, BaseEstimator ):
"""Meta-transformer for selecting continuous features and transform them using PCA.

Parameters
Expand Down
12 changes: 6 additions & 6 deletions tpot/builtin_modules/genetic_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.utils import check_array


class DominantEncoder(BaseEstimator, TransformerMixin):
class DominantEncoder(TransformerMixin, BaseEstimator ):
"""This class contains the function definition for encoding the input features as a Dominant genetic model.
The encoding used is AA(0)->1, Aa(1)->1, aa(2)->0. """

Expand Down Expand Up @@ -47,7 +47,7 @@ def transform(self, X, y=None):

return X_transformed

class RecessiveEncoder(BaseEstimator, TransformerMixin):
class RecessiveEncoder(TransformerMixin, BaseEstimator ):
"""This class contains the function definition for encoding the input features as a Recessive genetic model.
The encoding used is AA(0)->0, Aa(1)->1, aa(2)->1. """

Expand Down Expand Up @@ -85,7 +85,7 @@ def transform(self, X, y=None):

return X_transformed

class HeterosisEncoder(BaseEstimator, TransformerMixin):
class HeterosisEncoder(TransformerMixin, BaseEstimator ):
"""This class contains the function definition for encoding the input features as a Heterozygote Advantage genetic model.
The encoding used is AA(0)->0, Aa(1)->1, aa(2)->0. """

Expand Down Expand Up @@ -123,7 +123,7 @@ def transform(self, X, y=None):

return X_transformed

class UnderDominanceEncoder(BaseEstimator, TransformerMixin):
class UnderDominanceEncoder(TransformerMixin, BaseEstimator ):
"""This class contains the function definition for encoding the input features as a Under Dominance genetic model.
The encoding used is AA(0)->2, Aa(1)->0, aa(2)->1. """

Expand Down Expand Up @@ -162,7 +162,7 @@ def transform(self, X, y=None):
return X_transformed


class OverDominanceEncoder(BaseEstimator, TransformerMixin):
class OverDominanceEncoder(TransformerMixin, BaseEstimator ):
"""This class contains the function definition for encoding the input features as a Over Dominance genetic model.
The encoding used is AA(0)->1, Aa(1)->2, aa(2)->0. """

Expand Down
4 changes: 2 additions & 2 deletions tpot/builtin_modules/imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import numpy as np
from scipy import sparse

from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.utils import check_array
from sklearn.preprocessing import OneHotEncoder
import sklearn
Expand All @@ -50,7 +50,7 @@
import sklearn.compose


class ColumnSimpleImputer(BaseEstimator, TransformerMixin):
class ColumnSimpleImputer(TransformerMixin, BaseEstimator ):
def __init__(self, columns="all",
missing_values=np.nan,
strategy="mean",
Expand Down
20 changes: 12 additions & 8 deletions tpot/builtin_modules/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def set_params(self, **parameters):
return self


class PytorchClassifier(PytorchEstimator, ClassifierMixin):
class PytorchClassifier(ClassifierMixin, PytorchEstimator):
@abstractmethod
def _init_model(self, X, y): # pragma: no cover
pass
Expand All @@ -131,7 +131,6 @@ def fit(self, X, y):
self
Fitted estimator.
"""
# pylint: disable=no-member

self._init_model(X, y)

Expand Down Expand Up @@ -193,7 +192,6 @@ def validate_inputs(self, X, y):
return (X, y)

def predict(self, X):
# pylint: disable=no-member

X = check_array(X, accept_sparse=True)
check_is_fitted(self, 'is_fitted_')
Expand Down Expand Up @@ -295,8 +293,11 @@ def _init_model(self, X, y):
self.train_dset_len = len(train_dset)
self.device = device

def _more_tags(self):
return {'non_deterministic': True, 'binary_only': True}
def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.non_deterministic = True
tags.target_tags.single_output = True
return tags

class PytorchMLPClassifier(PytorchClassifier):
"""Multilayer Perceptron, implemented in PyTorch, for use with TPOT.
Expand Down Expand Up @@ -347,6 +348,9 @@ def _init_model(self, X, y):
)
self.train_dset_len = len(train_dset)
self.device = device

def _more_tags(self):
return {'non_deterministic': True, 'binary_only': True}

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.non_deterministic = True
tags.target_tags.single_output = True
return tags
Loading