Last active
January 26, 2017 18:22
-
-
Save ilblackdragon/1ff35124459cdf16bc01 to your computer and use it in GitHub Desktop.
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) | |
classifier = learn.Estimator(model_fn=dnn_tanh) | |
classifier.fit(X_train, y_train, batch_size=128, steps=100) | |
print("Accuracy: %f" % score) | |
# Outputs: Accuracy: 0.692737430168 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a note. If you were to try to get the cross val score by:
from sklearn.cross_validation import cross_val_score scores = cross_val_score(classifier, X, y,cv=4)
,you will get the following error:
Solution? Add the scoring method as:
scores = cross_val_score(classifier, X, y,cv=4,scoring="accuracy")
I mention this here because you will not encounter this situation with skflow.TensorFlowDNNClassifier.