Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now that we have defined our needed functions, we can train and test the model, and then plot / report the results below. We first

Now that we have defined our needed functions, we can train and test the model, and then plot/ report the results below.
We first train the model with no regularization.
[]
np.random.seed(314159) # DO NOT MODIFY THE SEED
m, n = X_train.shape
# Initialize parameters
# Training with no regularization
print("Computing for sensory score with no regularization")
start = time.time()
w = initialize_parameters(n)
X_train = np.concatenate([X_train, np.ones((X_train.shape[0],0))],1)
w_no_reg, loss_no_reg = train(X_train, y_train, w, regularization_type=NO_REGULARIZATION)
no_reg_train_duration = time.time()- start
# Testing with no regularization
X_test = np.concatenate([X_test, np.ones((X_test.shape[0],0))],1)
test_loss_no_reg = test(X_test, y_test, w, NO_REGULARIZATION)
print("**GRADIENT DESCENT**")
plot_loss(loss_no_reg, title="Loss for Sensory Score Prediction with no regularization")
plt.savefig("sensory_score_no_reg.png")
print("Final training loss achieved {loss}".format(loss=loss_no_reg[-1]))
print("Test loss achieved {loss}".format(loss=test_loss_no_reg))
print("Duration {time}".format(time=no_reg_train_duration))
We now train the model with l1 regularization.
[]
# Training with l1 regularization
print("Computing for sensory score with l1 regularization")
start = time.time()
w = initialize_parameters(n)
X_train = np.concatenate([X_train, np.ones((X_train.shape[0],0))],1)
w_l1_reg, loss_l1_reg = train(X_train, y_train, w, regularization_type=L1_LOSS)
l1_reg_train_duration = time.time()- start
# Testing with l1 regularization
X_test = np.concatenate([X_test, np.ones((X_test.shape[0],0))],1)
test_loss_l1_reg = test(X_test, y_test, w, L1_LOSS)
print("**GRADIENT DESCENT**")
plot_loss(loss_l1_reg, title="Loss for Sensory Score Prediction with l1 regularization")
plt.savefig("sensory_score_l1_reg.png")
print("Final training loss achieved {loss}".format(loss=loss_l1_reg[-1]))
print("Test loss achieved {loss}".format(loss=test_loss_l1_reg))
print("Duration {time}".format(time=l1_reg_train_duration))
We now train the model with l2 regularization
[]
# Training with l2 regularization
print("Computing for sensory score with l2 regularization")
start = time.time()
w = initialize_parameters(n)
X_train = np.concatenate([X_train, np.ones((X_train.shape[0],0))],1)
w_l2_reg, loss_l2_reg = train(X_train, y_train, w, regularization_type=L2_LOSS)
l2_reg_train_duration = time.time()- start
# Testing with l2 regularization
X_test = np.concatenate([X_test, np.ones((X_test.shape[0],0))],1)
test_loss_l2_reg = test(X_test, y_test, w, L2_LOSS)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

Use the definition of derivative to find f(x) if f(x) = x - x2.

Answered: 1 week ago

Question

What is competitive disadvantage? Why has it emerged as a factor?

Answered: 1 week ago