EpistasisLab / EpistasisLab/tpot

Training custom sklearn classifier with TPOTClassifier?

Open
#1,165 2 comments 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

I created a custom sklearn classifier and need to run it along with tpot. But while running tpot I get this warning.

> Warning: MeanClassifier is not available and will not be used by TPOT.

My full toy code.

```
from tpot import TPOTClassifier
import numpy as np
from sklearn.base import BaseEstimator, ClassifierMixin

class MeanClassifier(BaseEstimator, ClassifierMixin):
def __init__(self):
pass

def fit(self, X, y=None):
self.treshold_ = (sum(X)/len(X))
return self

def _meaning(self, x):
return( True if x >= self.treshold_ else False )

def predict(self, X, y=None):
try:
getattr(self, "treshold_")
except AttributeError:
raise RuntimeError("You must train classifer before predicting data!")

return([self._meaning(x) for x in X])

def score(self, X, y=None):
# counts number of values bigger than mean
return(sum(self.predict(X)))

tpot_config = {
'MeanClassifier': {
},
}

X_train = [i for i in range(0, 100, 5)]
X_test = [i + 3 for i in range(-5, 95, 5)]
y_train = None
y_test= None

tpot = TPOTClassifier(generations=2, population_size=20, verbosity=2, random_state=42,config_dict=tpot_config)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
```

How can we run a custom sklearn estimator with TPOT? In the web there is not much info available for running custom models with tpot.

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.