Created
August 16, 2018 16:48
-
-
Save chmodsss/8df771999668358f96afda6d24b6a0df to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
from keras.layers import Dense | |
from keras.models import Sequential | |
from keras.optimizers import RMSprop, Adadelta, Adam | |
from sklearn.datasets import load_digits | |
from sklearn.model_selection import train_test_split | |
dig = load_digits() | |
onehot_target = pd.get_dummies(dig.target) | |
x_train, x_val, y_train, y_val = train_test_split(dig.data, onehot_target, test_size=0.1, random_state=20) | |
model = Sequential() | |
model.add(Dense(128, input_dim=x_train.shape[1], activation='sigmoid')) | |
model.add(Dense(128, activation='sigmoid')) | |
model.add(Dense(10, activation='softmax')) | |
model.summary() | |
model.compile(optimizer=Adadelta(), loss='categorical_crossentropy', metrics=['categorical_accuracy']) | |
model.fit(x_train, y_train, epochs=50, batch_size=64) | |
scores = model.evaluate(x_val, y_val) | |
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment