This is the introduction to deep learning
Let us start with a simple examples
# Numerical Computations
import numpy as np
# For Deep Learning
import keras
# Visualisation
import matplotlib.pyplot as plt
%matplotlib inline
$$ Z = 2X^2 - 3Y^2 + 5 + \epsilon $$
x = np.arange(start = -1, stop = 1, step = 0.01)
y = np.arange(start = -1, stop = 1, step = 0.01)
len(x), len(y)
X,Y = np.meshgrid(x,y)
c = np.ones((200, 200))
e = np.random.rand(200,200)*0.1
Z = 2*X*X - 3*Y*Y + 5*c + e
#!wget http://bit.do/dl-vis
#!mv dl-vis vis.py
#!pip install altair
import vis
vis.plot3d(X,Y,Z)
Step 1: Get the input and output data
input_xy = np.c_[X.reshape(-1), Y.reshape(-1)]
output_z = Z.reshape(-1)
input_xy.shape, output_z.shape
Step 2: Create the Transformation & Regression Model
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(10, input_dim =2, activation="relu"))
model.add(Dense(10, activation="relu"))
model.add(Dense(1))
model.summary()
Step 3: Comile the Model - Loss, Optimizer & Fit on the Data
model.compile(loss="mean_squared_error", optimizer="sgd")
%time
output = model.fit(input_xy, output_z, batch_size= 32,
epochs=10, validation_split=0.2, verbose=0)
Step 4: Evaluate Model Perfomance
vis.metrics(output.history)
Step 5: Make Prediction from the model
Z_pred = model.predict(input_xy).reshape(200,200)
vis.plot3d(X,Y,Z_pred)