Commit f9b5b621 authored by Antoine Rollet's avatar Antoine Rollet

Upload New File

parent 5d6c4435
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.callbacks import EarlyStopping
##Create a new model
predictors=np.array(X_train)
target=np.array(y_train)
n=len(predictors[0])
model = Sequential()
#adding layers
model.add(Dense(180,activation='relu',input_shape=(n,)))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
model.add(Dense(180,activation='relu'))
#output layer
model.add(Dense(3,activation="softmax"))
#compiling
model.compile(optimizer="adam",loss="categorical_crossentropy",metrics=['accuracy'])
#fiting
early_stopping_monitor = EarlyStopping(patience=3)
model.fit(predictors,target,epochs=100,validation_split=0.3,callbacks=[early_stopping_monitor])
## Score
import sklearn.metrics
y_predicted=model.predict(X_test)
y_predicted_maxs=np.max(y_predicted,axis=1)
y_predicted_bool=np.zeros(y_test.shape)
y_predicted_bool[:,0]=(y_predicted_maxs==y_predicted[:,0])
y_predicted_bool[:,1]=(y_predicted_maxs==y_predicted[:,1])
y_predicted_bool[:,2]=(y_predicted_maxs==y_predicted[:,2])
print(accuracy_score(y_test,y_predicted_bool))
## Saving the model
model.save("c:/Users/Antoine Rollet/Documents/Midas_indecis-2.1.h5")
##Loading a model
from keras.models import load_model
my_model=load_model("c:/Users/Antoine Rollet/Documents/Midas-1.1.h5")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment