'''
Evaluating model accuracy on validation dataset

Now it's your turn to monitor model accuracy with a validation data set. A model definition has been provided as model. Your job is to add the code to compile it and then fit it. You'll check the validation score in each epoch.
'''

import pandas as pd
import numpy as np

from keras.layers import Dense
from keras.models import Sequential
from keras.utils.np_utils import to_categorical

df = pd.read_csv('../datasets/titanic_all_numeric.csv')

predictors = df.drop('survived', axis=1).values

n_cols = predictors.shape[1]
input_shape = (n_cols,)

target = to_categorical(df.survived)

'''
INSTRUCTIONS

*   Compile your model using 'adam' as the optimizer and 'categorical_crossentropy' for the loss. To see what fraction of predictions are correct (the accuracy) in each epoch, specify the additional keyword argument metrics=['accuracy'] in model.compile().
*   Fit the model using the predictors and target. Create a validation split of 30% (or 0.3). This will be reported in each epoch.
'''

# Save the number of columns in predictors: n_cols
n_cols = predictors.shape[1]
input_shape = (n_cols,)

# Specify the model
model = Sequential()

model.add(Dense(100, activation='relu', input_shape=input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))

# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Fit the model
hist = model.fit(predictors, target, validation_split=0.3, epochs=10)

d0b58bc4fb7f67182b8ae9316149d25349ff8a5e
<mask token>

<mask token>
model.add(Dense(100, activation='relu', input_shape=input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=[
    'accuracy'])
<mask token>

<mask token>
df = pd.read_csv('../datasets/titanic_all_numeric.csv')
predictors = df.drop('survived', axis=1).values
n_cols = predictors.shape[1]
input_shape = n_cols,
target = to_categorical(df.survived)
<mask token>
n_cols = predictors.shape[1]
input_shape = n_cols,
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=[
    'accuracy'])
hist = model.fit(predictors, target, validation_split=0.3, epochs=10)

<mask token>
import pandas as pd
import numpy as np
from keras.layers import Dense
from keras.models import Sequential
from keras.utils.np_utils import to_categorical
df = pd.read_csv('../datasets/titanic_all_numeric.csv')
predictors = df.drop('survived', axis=1).values
n_cols = predictors.shape[1]
input_shape = n_cols,
target = to_categorical(df.survived)
<mask token>
n_cols = predictors.shape[1]
input_shape = n_cols,
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=[
    'accuracy'])
hist = model.fit(predictors, target, validation_split=0.3, epochs=10)

'''
Evaluating model accuracy on validation dataset

Now it's your turn to monitor model accuracy with a validation data set. A model definition has been provided as model. Your job is to add the code to compile it and then fit it. You'll check the validation score in each epoch.
'''

import pandas as pd
import numpy as np

from keras.layers import Dense
from keras.models import Sequential
from keras.utils.np_utils import to_categorical

df = pd.read_csv('../datasets/titanic_all_numeric.csv')

predictors = df.drop('survived', axis=1).values

n_cols = predictors.shape[1]
input_shape = (n_cols,)

target = to_categorical(df.survived)

'''
INSTRUCTIONS

*   Compile your model using 'adam' as the optimizer and 'categorical_crossentropy' for the loss. To see what fraction of predictions are correct (the accuracy) in each epoch, specify the additional keyword argument metrics=['accuracy'] in model.compile().
*   Fit the model using the predictors and target. Create a validation split of 30% (or 0.3). This will be reported in each epoch.
'''

# Save the number of columns in predictors: n_cols
n_cols = predictors.shape[1]
input_shape = (n_cols,)

# Specify the model
model = Sequential()

model.add(Dense(100, activation='relu', input_shape=input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))

# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Fit the model
hist = model.fit(predictors, target, validation_split=0.3, epochs=10)
