News

New paper! in the American Naturalist

Friday, December 15, 2017

Deep Learning first trial



import pandas as pd
from keras.layers import Dense
from keras.models import Sequential
import sys

#
# Make a model based on deep learning.
# predictors_data: predictor data file as a matrix of shape (x,y); row x is a dataset, column y is a parameter/input node
# The number of output node = 1 (this becomes more if the model is for classification)
#

dataset = sys.argv[1]
df = pd.read_table(dataset,delim_whitespace=True).sample(frac=1)
predictors = df.drop(['average','max'], axis=1).as_matrix()
target = df.average
n_cols = predictors.shape[1] # the number of input nodes

model = Sequential()
# hidden layers
model.add(Dense(500, activation='relu',input_shape=(n_cols,))) # n_cols nodes exist in the input layaer
model.add(Dense(500, activation='relu'))
model.add(Dense(500, activation='relu'))
model.add(Dense(500, activation='relu'))
# Output layer
model.add(Dense(1))
# Compiling the model
model.compile(optimizer='adam',loss='mean_squared_error')
# Fitting the model
model.fit(predictors,target,shuffle=True,verbose=1,validation_split=0.3)
model.summary()

model.save('model_file.h5')