Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
963 additions
and
57 deletions.
There are no files selected for viewing
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
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
739 changes: 739 additions & 0 deletions
739
docs/sources/user_guide/tf_classifier/TfMultiLayerPerceptron.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+7.55 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_13_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.55 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_14_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.28 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_15_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_16_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.28 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_16_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_17_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.67 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_23_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_23_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.67 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_24_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_24_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.67 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_27_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.67 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_28_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.54 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_29_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.54 KB
...uide/tf_classifier/TfMultiLayerPerceptron_files/TfMultiLayerPerceptron_30_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+115 KB
...ources/user_guide/tf_classifier/TfMultiLayerPerceptron_files/mlp_overview_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.7 KB
...ources/user_guide/tf_classifier/TfMultiLayerPerceptron_files/mlp_overview_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 13 additions & 13 deletions
26
docs/sources/user_guide/tf_classifier/TfSoftmaxRegression.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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
130 changes: 130 additions & 0 deletions
130
mlxtend/tf_classifier/tests/tests_tf_multilayerperceptron.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Sebastian Raschka 2014-2016 | ||
# mlxtend Machine Learning Library Extensions | ||
# Author: Sebastian Raschka <sebastianraschka.com> | ||
# | ||
# License: BSD 3 clause | ||
|
||
from mlxtend.tf_classifier import TfMultiLayerPerceptron as MLP | ||
from mlxtend.data import iris_data | ||
import numpy as np | ||
from nose.tools import raises | ||
|
||
|
||
X, y = iris_data() | ||
X = X[:, [0, 3]] # sepal length and petal width | ||
X_bin = X[0:100] # class 0 and class 1 | ||
y_bin = y[0:100] # class 0 and class 1 | ||
|
||
# standardize | ||
X_bin[:, 0] = (X_bin[:, 0] - X_bin[:, 0].mean()) / X_bin[:, 0].std() | ||
X_bin[:, 1] = (X_bin[:, 1] - X_bin[:, 1].mean()) / X_bin[:, 1].std() | ||
X[:, 0] = (X[:, 0] - X[:, 0].mean()) / X[:, 0].std() | ||
X[:, 1] = (X[:, 1] - X[:, 1].mean()) / X[:, 1].std() | ||
|
||
|
||
@raises(AttributeError) | ||
def test_optimizer_init(): | ||
MLP(optimizer='no-optimizer') | ||
|
||
|
||
@raises(AttributeError) | ||
def test_activations_init_typo(): | ||
MLP(hidden_layers=[1, 2], activations=['logistic', 'invalid']) | ||
|
||
|
||
@raises(AttributeError) | ||
def test_activations_invalid_ele_1(): | ||
MLP(hidden_layers=[1], activations=['logistic', 'logistic']) | ||
|
||
|
||
@raises(AttributeError) | ||
def test_activations_invalid_ele_2(): | ||
MLP(hidden_layers=[10, 10], activations=['logistic']) | ||
|
||
|
||
def test_mapping(): | ||
mlp = MLP() | ||
w, b = mlp._layermapping(n_features=10, | ||
n_classes=11, | ||
hidden_layers=[8, 7, 6]) | ||
|
||
expect_b = {1: [[8], 'n_hidden_1'], | ||
2: [[7], 'n_hidden_2'], | ||
3: [[6], 'n_hidden_3'], | ||
'out': [[11], 'n_classes']} | ||
|
||
expect_w = {1: [[10, 8], 'n_features, n_hidden_1'], | ||
2: [[8, 7], 'n_hidden_1, n_hidden_2'], | ||
3: [[7, 6], 'n_hidden_2, n_hidden_3'], | ||
'out': [[6, 11], 'n_hidden_3, n_classes']} | ||
|
||
assert expect_b == b, b | ||
assert expect_w == w, w | ||
|
||
|
||
def test_binary_gd(): | ||
mlp = MLP(epochs=100, | ||
eta=0.5, | ||
hidden_layers=[5], | ||
optimizer='gradientdescent', | ||
activations=['logistic'], | ||
minibatches=1, | ||
random_seed=1) | ||
|
||
mlp.fit(X_bin, y_bin) | ||
assert((y_bin == mlp.predict(X_bin)).all()) | ||
|
||
|
||
def test_binary_sgd(): | ||
mlp = MLP(epochs=10, | ||
eta=0.5, | ||
hidden_layers=[5], | ||
optimizer='gradientdescent', | ||
activations=['logistic'], | ||
minibatches=len(y_bin), | ||
random_seed=1) | ||
|
||
mlp.fit(X_bin, y_bin) | ||
assert((y_bin == mlp.predict(X_bin)).all()) | ||
|
||
|
||
def test_multiclass_probas(): | ||
mlp = MLP(epochs=100, | ||
eta=0.5, | ||
hidden_layers=[5], | ||
optimizer='gradientdescent', | ||
activations=['logistic'], | ||
minibatches=1, | ||
random_seed=1) | ||
mlp.fit(X, y) | ||
idx = [0, 50, 149] # sample labels: 0, 1, 2 | ||
y_pred = mlp.predict_proba(X[idx]) | ||
exp = np.array([[0.9, 0.1, 0.0], | ||
[0.0, 0.6, 0.4], | ||
[0.0, 0.1, 0.9]]) | ||
np.testing.assert_almost_equal(y_pred, exp, 1) | ||
|
||
|
||
def test_multiclass_gd_acc(): | ||
mlp = MLP(epochs=100, | ||
eta=0.5, | ||
hidden_layers=[5], | ||
optimizer='gradientdescent', | ||
activations=['logistic'], | ||
minibatches=1, | ||
random_seed=1) | ||
mlp.fit(X, y) | ||
assert((y == mlp.predict(X)).all()) | ||
|
||
|
||
@raises(AttributeError) | ||
def test_fail_minibatches(): | ||
mlp = MLP(epochs=100, | ||
eta=0.5, | ||
hidden_layers=[5], | ||
optimizer='gradientdescent', | ||
activations=['logistic'], | ||
minibatches=13, | ||
random_seed=1) | ||
mlp.fit(X, y) | ||
assert((y == mlp.predict(X)).all()) |
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
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
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