Skip to content

Instantly share code, notes, and snippets.

@CamDavidsonPilon
Last active July 9, 2017 11:03
Show Gist options
  • Save CamDavidsonPilon/d54ec4b8079728758c2131169afd6a1e to your computer and use it in GitHub Desktop.
Save CamDavidsonPilon/d54ec4b8079728758c2131169afd6a1e to your computer and use it in GitHub Desktop.
This NN model performs worse than sklearn's `LogisticRegression` model (with default params too). Really I can only get about 57% on the test set, and LR gives me about 58%. What am I doing wrong - I've tried dozen of permutations of the network topology, optimisers, etc.? Note the size of the data is (400k, 144), so I have lots of data.
# FFN to model game outcome
import pandas as pd
from keras.layers import Dense
from keras.models import Sequential
import numpy as np
if __name__ == "__main__":
import sqlite3
with sqlite3.connect("data/heroes.db") as conn:
with open("data/sql/feature_matrix.sql", "r") as sql:
df = pd.read_sql(sql.read(), conn)
df = df.drop("ReplayID", axis=1)
df = df.dropna(axis=0, how='any')
TRAINING_DATA = 400000
# shape = (TRAINING_DATA, 144)
X_train = df.iloc[:TRAINING_DATA].drop('outcome', axis=1)
Y_train = df.iloc[:TRAINING_DATA]['outcome']
X_test = df.iloc[TRAINING_DATA:].drop('outcome', axis=1)
Y_test = df.iloc[TRAINING_DATA:]['outcome']
model = Sequential()
model.add(Dense(100, activation='relu', kernel_initializer='he_normal', input_dim=X_train.shape[1]))
model.add(Dense(10, activation='relu', kernel_initializer='he_normal'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['binary_accuracy'])
model.fit(X_train.values, Y_train.values, epochs=50, batch_size=512)
print model.evaluate(X_test.values, Y_test.values, batch_size=128)
@vyraun
Copy link

vyraun commented Jul 8, 2017

could you share the data too?

@dartdog
Copy link

dartdog commented Jul 9, 2017

Try shuffling the data

@julioasotodv
Copy link

You probably have to standardize your features. Given that sklearn's LogisticRegression trains through coordinate descent by deafult (which is not that sensitive to feature scale), LogisticRegression is working better. Try to use sklearn's StandardScaler before training your network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment