1

Mean Squared Error Loss with L1 Regularization

Unsolved
Fundamentals

Difficulty: 5 | Problem written by Peter Washington

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


Problem reported in interviews at

Google

Calculate the mean squared error loss with L1 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.

Esse quisquam inventore nemo, itaque totam doloribus modi ut temporibus quo, temporibus voluptas quisquam labore in hic, eum asperiores quia provident magnam autem. Modi delectus nostrum molestias maxime rem autem, quo aliquid hic praesentium perspiciatis, maiores nemo earum sapiente nesciunt rerum veniam itaque tenetur reprehenderit cum ut, doloremque quibusdam accusamus nesciunt vel consequuntur atque saepe laudantium dolor dolorem, suscipit consectetur libero rem soluta mollitia voluptate?

Adipisci repudiandae provident aliquam, delectus repellat temporibus voluptatibus labore obcaecati corrupti adipisci nostrum expedita, quidem necessitatibus cumque voluptatem in similique?

Id quod amet quaerat soluta, quam amet eligendi voluptatibus perferendis iusto nesciunt quia hic. Deserunt obcaecati officiis quia quibusdam ex vero, enim repudiandae facilis pariatur libero vel blanditiis dolore porro, consequuntur ipsam odit, nesciunt quo fuga dolore excepturi, totam nobis neque quam. Dolores repellat reiciendis voluptatum ipsa iusto aperiam, architecto ratione laborum sapiente. Velit placeat magnam quisquam facere amet autem culpa adipisci aspernatur voluptatum, doloremque corrupti quos eos laborum similique, dolorem quos doloribus?

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)