Skip to content

Instantly share code, notes, and snippets.

@WittmannF
Created July 24, 2018 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WittmannF/c0afad18f2fe95009df776521966405a to your computer and use it in GitHub Desktop.
Save WittmannF/c0afad18f2fe95009df776521966405a to your computer and use it in GitHub Desktop.
Hello TFLearn!
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from tflearn.data_utils import to_categorical
import tflearn
## Load the dataset
X, y = load_breast_cancer(True)
## Train/Test Split and convert class vector to a binary class matrix
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
y_train, y_test = to_categorical(y_train, nb_classes=2), to_categorical(y_test, nb_classes=2)
# Defining NN Model
NUMBER_OF_FEATURES = len(X[0])
NUMBER_OF_CLASSES = len(set(y))
net = tflearn.input_data(shape=[None, NUMBER_OF_FEATURES])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, NUMBER_OF_CLASSES, activation='softmax')
net = tflearn.regression(net)
model = tflearn.DNN(net)
# Train the classifier
model.fit(X_train, y_train)
# Report the training and test scores
train_score = model.evaluate(X_train, y_train)
test_score = model.evaluate(X_test, y_test)
print("Training score: {:.2f}".format(train_score[0]))
print("Test score: {:.2f}".format(test_score[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment