This file contains hidden or 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
import random | |
import pandas | |
import numpy as np | |
from sklearn import metrics, cross_validation | |
import tensorflow as tf | |
from tensorflow.contrib import layers | |
from tensorflow.contrib import learn | |
random.seed(42) |
This file contains hidden or 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
def dnn_tanh(features, target): | |
target = tf.one_hot(target, 2, 1.0, 0.0) | |
logits = layers.stack(features, layers.fully_connected, [10, 20, 10], | |
activation_fn=tf.tanh) | |
prediction, loss = learn.models.logistic_regression(logits, target) | |
train_op = layers.optimize_loss(loss, | |
tf.contrib.framework.get_global_step(), optimizer='SGD', learning_rate=0.05) | |
return tf.argmax(prediction, dimension=1), loss, train_op | |
random.seed(42) |
This file contains hidden or 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
>>> classifier = learn.DNNClassifier(hidden_units=[10, 20, 10], | |
... n_classes=2, | |
... feature_columns=learn.infer_real_valued_columns_from_input(X_train), | |
... optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.05)) | |
>>> classifier.fit(X_train, y_train, batch_size=128, steps=500) | |
>>> score = accuracy_score(classifier.predict(X_test), y_test) | |
>>> print("Accuracy: %f" % score) | |
Accuracy: 0.67597765363 |
This file contains hidden or 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
import random | |
from sklearn import datasets, cross_validation, metrics | |
import tensorflow as tf | |
from tensorflow.contrib import layers | |
from tensorflow.contrib import learn | |
random.seed(42) | |
# Load dataset and split it into train / test subsets. |
NewerOlder