Skip to content

Instantly share code, notes, and snippets.

@mmmayo13
Last active December 31, 2018 22:44
Show Gist options
  • Save mmmayo13/8c4744100607a003f6696c74173179a8 to your computer and use it in GitHub Desktop.
Save mmmayo13/8c4744100607a003f6696c74173179a8 to your computer and use it in GitHub Desktop.
from tpot import TPOTClassifier
from sklearn.cross_validation import train_test_split
from sklearn.datasets import load_iris
import time
# Load and split the data
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42)
# Construct and fit TPOT classifier
start_time = time.time()
tpot = TPOTClassifier(generations=10, verbosity=2)
tpot.fit(X_train, y_train)
end_time = time.time()
# Results
print('TPOT classifier finished in %s seconds' % (end_time - start_time))
print('Best pipeline test accuracy: %.3f' % tpot.score(X_test, y_test))
# Save best pipeline as Python script file
tpot.export('tpot_iris_pipeline.py')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment