Allow us to learn few concepts expected to more readily compilation the aggregation process.

Keras gives many loss function in the losses module and they are as per the following −

All above loss function acknowledges two contentions −

Import the losses module prior to involving loss function as determined below −

`from keras import losses`

`keras.optimizers.SGD(learning_rate = 0.01, momentum = 0.0, nesterov = False>`

`keras.optimizers.RMSprop(learning_rate = 0.001, rho = 0.9>`

`keras.optimizers.Adagrad(learning_rate = 0.01>`

`keras.optimizers.Adadelta(learning_rate = 1.0, rho = 0.95>`

```
keras.optimizers.Adam(
learning_rate = 0.001, beta_1 = 0.9, beta_2 = 0.999, amsgrad = False
>
```

Import the metrics module prior to involving metrics as indicated below −

`from keras import metrics`

to compile the model. The contention and default value of the compile(>

strategy is as per the following

```
compile(
optimizer,
loss = None,
metrics = None,
loss_weights = None,
sample_weight_mode = None,
weighted_metrics = None,
target_tensors = None
>
```

The significant arguments are as per the following −
```
from keras import losses
from keras import optimizers
from keras import metrics
model.compile(loss = 'mean_squared_error',
optimizer = 'sgd', metrics = [metrics.categorical_accuracy]>
```

. The main reason for this fit function is utilized to assess your model on preparing. This can be likewise utilized for graphing model execution. It has the accompanying syntax −

`model.fit(X, y, epochs = , batch_size = >`

Here,```
import numpy as np
x_train = np.random.random((100,4,8>
```

>

y_train = np.random.random((100,10>

>

Presently, create random validation data,
`x_val = np.random.random((100,4,8>`

>

y_val = np.random.random((100,10>

>

`from keras.models import Sequential model = Sequential(>`

```
from keras.layers import LSTM, Dense
# add a sequence of vectors of dimension 16
model.add(LSTM(16, return_sequences = True>
```

>

model.add(Dense(10, activation = 'softmax'>

>

```
model.compile(
loss = 'categorical_crossentropy', optimizer = 'sgd', metrics = ['accuracy']
>
```

Below code can be utilized to load the dataset −

```
from keras.datasets import mnist
(x_train, y_train>
```

, (x_test, y_test>

= mnist.load_data(>

as addressed underneath and attempt to make the model utilizing Keras. The core features of the model are as per the following −

.

```
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import RMSprop
import numpy as np
```

`(x_train, y_train>`

, (x_test, y_test>

= mnist.load_data(>

`x_train = x_train.reshape(60000, 784>`

x_test = x_test.reshape(10000, 784>

x_train = x_train.astype('float32'>

x_test = x_test.astype('float32'>

x_train /= 255
x_test /= 255
y_train = keras.utils.to_categorical(y_train, 10>

y_test = keras.utils.to_categorical(y_test, 10>

`model = Sequential(>`

model.add(Dense(512, activation = 'relu', input_shape = (784,>

>

>

model.add(Dropout(0.2>

>

model.add(Dense(512, activation = 'relu'>

>

model.add(Dropout(0.2>

>

model.add(Dense(10, activation = 'softmax'>

>

```
model.compile(loss = 'categorical_crossentropy',
optimizer = RMSprop(>
```

,
metrics = ['accuracy']>

```
history = model.fit(
x_train, y_train,
batch_size = 128,
epochs = 20,
verbose = 1,
validation_data = (x_test, y_test>
```

>