1

Mean Squared Error Loss with L2 Regularization

Unsolved
Fundamentals

Difficulty: 3 | Problem written by peter.washington

Educational Resource: http://cs231n.stanford.edu/slides/2017/cs231n_2017_lecture3.pdf


Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

Calculate the mean squared error loss with L2 regularization for the given input variables x_in, a multiple linear regression model with parameters m and b, and the true y values y_true. lamb defines the regularization rate lambda. For the input, keep in mind that:
 

  • x_in is a list of numpy arrays, where each array is an input x vector
  • m is a vector of model weights, or the slopes associated with each input in multiple linear regression
  • b is a fixed bias applied once
Sample Input:
<class 'list'>
y_true: [5, 5, 5]
<class 'list'>
x_in: [array([1, 1, 1]), array([1, 1, 1]), array([1, 1, 1])]
<class 'list'>
m: [1, 1, 1]
<class 'int'>
b: 2
<class 'float'>
lamb: 0.1

Expected Output:
<class 'float'>
0.30000000000000004

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Asperiores repellat rerum illo consequuntur sequi aliquam. Nemo sed hic blanditiis dolor soluta minima corrupti in repellat magni dolorum. Cum placeat excepturi, animi minus obcaecati reprehenderit molestias esse odit ut corrupti vitae et. Autem fugiat obcaecati fugit nihil nulla laboriosam ea expedita atque voluptatibus, iste et dolore hic soluta ducimus officia ex modi autem, enim at nulla repellat ad, delectus sint necessitatibus magni iure ab modi consequuntur voluptatem tempora, accusantium vero soluta excepturi ipsa obcaecati minus culpa sed fuga eligendi adipisci.

Animi eius ratione soluta nihil repellendus facilis tempora maxime itaque. Autem possimus quo recusandae molestiae repudiandae exercitationem, architecto officiis possimus quod quo. Animi suscipit optio cumque atque, aut consectetur fugiat vero doloribus ad rem itaque pariatur doloremque, deserunt cumque at ut, vero suscipit error blanditiis necessitatibus aspernatur aut? Blanditiis similique alias cumque minima voluptate, esse explicabo doloribus, hic maxime vel quo unde rerum pariatur inventore, alias architecto consequatur.

Pariatur officia quam praesentium dignissimos totam nemo quis alias aut placeat, placeat laborum fugit, perferendis ut accusamus vel iste inventore, reprehenderit sed voluptatum itaque maxime officia commodi repellendus in.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)