Deep Learning Fundamentals with Keras EDX Week-5 Final Exam Answers

This is answer-key to the IBM course named IBM DL0101EN Deep Learning Fundamentals with Keras Final Exam of week 5 (20 Questions)

Download the Concrete Dataset by click here.

This is how the finished data-set looks like.

Deep Learning Fundamentals with Keras EDX Week-5 Final Exam Answers

So we are directly starting with the code

CODE –

Importing Required Packages

import pandas as pd
import numpy as np

Importing Convulation

concrete_data = pd.read_csv('https://cocl.us/concrete_data')
concrete_data.head()
concrete_data.shape
concrete_data.describe()
concrete_data.isnull().sum()

Cleaning and Normalizing given Data

concrete_data_columns = concrete_data.columns
predictors = concrete_data[concrete_data_columns[concrete_data_columns != 'Strength']] # all columns except Strength
target = concrete_data['Strength'] # Strength column
predictors.head()
target.head()
n_cols = predictors.shape[1] # number of predictors
n_cols

Importing Keras

import keras

Import Useful Packages

from keras.models import Sequential
from keras.layers import Dense
# define regression model
def regression_model():
    # create model
    model = Sequential()
    model.add(Dense(10, activation='relu', input_shape=(n_cols,)))
    model.add(Dense(1))
    
    # compile model
    model.compile(optimizer='adam', loss='mean_squared_error')
    return model
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(predictors, target, test_size=0.3, random_state=42)

Training and Testing the Network

# build the model
model = regression_model()
# fit the model
epochs = 50
model.fit(X_train, y_train, epochs=epochs, verbose=1)
loss_val = model.evaluate(X_test, y_test)
y_pred = model.predict(X_test)
loss_val
from sklearn.metrics import mean_squared_error
mean_square_error = mean_squared_error(y_test, y_pred)
mean = np.mean(mean_square_error)
standard_deviation = np.std(mean_square_error)
print(mean, standard_deviation)
total_mean_squared_errors = 50
epochs = 50
mean_squared_errors = []
for i in range(0, total_mean_squared_errors):
    X_train, X_test, y_train, y_test = train_test_split(predictors, target, test_size=0.3, random_state=i)
    model.fit(X_train, y_train, epochs=epochs, verbose=0)
    MSE = model.evaluate(X_test, y_test, verbose=0)
    print("MSE "+str(i+1)+": "+str(MSE))
    y_pred = model.predict(X_test)
    mean_square_error = mean_squared_error(y_test, y_pred)
    mean_squared_errors.append(mean_square_error)

mean_squared_errors = np.array(mean_squared_errors)
mean = np.mean(mean_squared_errors)
standard_deviation = np.std(mean_squared_errors)

print('\n')
print("Below is the mean and standard deviation of " +str(total_mean_squared_errors) + " mean squared errors without normalized data. Total number of epochs for each training is: " +str(epochs) + "\n")
print("Mean: "+str(mean))
print("Standard Deviation: "+str(standard_deviation))

check out our other amazing futuristic blogs

2 thoughts on “Deep Learning Fundamentals with Keras EDX Week-5 Final Exam Answers”

  1. Pingback: Deep Learning Fundamentals With Keras EDX WEEK-4 MCQ ANSWERS By IBM | Techohealth.com

  2. Pingback: Deep Learning Fundamentals With Keras Edx Week-1 MCQ Answers | Techohealth.com

Leave a Comment

Your email address will not be published. Required fields are marked *