Created
April 24, 2019 06:14
-
-
Save vivek081166/ac9484d518dfa246a587119cc58415eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
tpot = TPOTClassifier(generations=5, population_size=50, verbosity=2) | |
tpot.fit(X_train, y_train) | |
print(tpot.score(X_test, y_test)) | |
tpot.export('tpot_mnist_pipeline.py') | |
# Running this code should discover a pipeline (expored as tpot_mnist_pipeline.py) | |
# 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") | |
exported_pipeline.fit(training_features, 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