-
-
Save triestpa/9db250404adde1fbf9a12232e38fa7fc to your computer and use it in GitHub Desktop.
Tensorflow 2
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def custom_model(X, y):\n", | |
" layers = skflow.ops.dnn(X, [20, 40, 20], tf.tanh)\n", | |
" return skflow.models.logistic_regression(layers, y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Step #100, epoch #25, avg. train loss: 0.61585\n", | |
"Step #200, epoch #50, avg. train loss: 0.59296\n", | |
"Step #300, epoch #75, avg. train loss: 0.56212\n", | |
"Step #400, epoch #100, avg. train loss: 0.53000\n", | |
"Step #500, epoch #125, avg. train loss: 0.51094\n", | |
"Step #600, epoch #150, avg. train loss: 0.48331\n", | |
"Step #700, epoch #175, avg. train loss: 0.47346\n", | |
"Step #800, epoch #200, avg. train loss: 0.46050\n", | |
"Step #900, epoch #225, avg. train loss: 0.45013\n", | |
"Step #1000, epoch #250, avg. train loss: 0.44446\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"0.80382775119617222" | |
] | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"tf_clf_c = skflow.TensorFlowEstimator(model_fn=custom_model, n_classes=2, batch_size=256, steps=1000, learning_rate=0.05)\n", | |
"tf_clf_c.fit(X_train, y_train)\n", | |
"metrics.accuracy_score(y_test, tf_clf_c.predict(X_test))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.4.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment