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(digits.data, digits.target,
                                                    train_size=0.75, test_size=0.25, random_state=42)

tpot = TPOTClassifier(generations=5, population_size=50, verbosity=2, random_state=42)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
tpot.export('tpot_digits_pipeline.py')
Generation 1 - Current best internal CV score: 0.9866363761531047
Generation 2 - Current best internal CV score: 0.9866363761531047
Generation 3 - Current best internal CV score: 0.9866363761531047
Generation 4 - Current best internal CV score: 0.9866363761531047
Generation 5 - Current best internal CV score: 0.9866363761531047

Best pipeline: KNeighborsClassifier(input_matrix, n_neighbors=2, p=2, weights=distance)
0.9822222222222222
Download notebook

(0 downloads)

Post categories:

tpot

python