Skip to content

Instantly share code, notes, and snippets.



Created Apr 24, 2019
What would you like to do?
from tpot import TPOTClassifier
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
digits = load_digits()
X_train, X_test, y_train, y_test = train_test_split(,,
train_size=0.75, test_size=0.25)
tpot = TPOTClassifier(generations=5, population_size=50, verbosity=2), y_train)
print(tpot.score(X_test, y_test))
# Running this code should discover a pipeline (expored as
# that achieves about 98% test accuracy:
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
# NOTE: Make sure that the class is labeled 'class' in the data file
tpot_data = np.recfromcsv('PATH/TO/DATA/FILE', delimiter='COLUMN_SEPARATOR', dtype=np.float64)
features = np.delete(tpot_data.view(np.float64).reshape(tpot_data.size, -1),
tpot_data.dtype.names.index('class'), axis=1)
training_features, testing_features, training_target, testing_target = \
train_test_split(features, tpot_data['class'], random_state=None)
exported_pipeline = KNeighborsClassifier(n_neighbors=6, weights="distance"), training_target)
results = exported_pipeline.predict(testing_features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment