Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
Using the linear_predict function that you previously wrote, write a function linear_residuals that given the learned weights in the
linear_regression function calculates the residuals vector. Your functions takes the following arguments as input:
1. X:A numpy array of the shape (N,d) where N is the number of data points, and d is the data dimension. Do not assume anything about N or d
other than being a positive integer.
2. beta : Anumpy array of the shape (d+1,1) where d is the data dimension
Bo
Ba
3. Y: A numpy array of the shape (N,) where N is the number of data points.
Your function should produce the e numpy array with the shape of (N,), whose i" element is defined as
el) = yl) – (Bo + Bix? + Bzx +
+ Bax)
In [ ]: def linear_residuals (X,beta,Y):
assert X.ndim==2
N = X.shape[0]
х.shape[1]
assert beta.shape
assert Y.shape
d =
(d+1,1)
(N,)
==
==
#3
your code here
e
e.reshape(-1)
%3D
assert e.size
return e
(np.arange ( 35).reshape ( 7,5) ** 13) % 20
2.** (-np.arange (6).reshape (-1,1))
In [ ]: some_X =
some beta =
some_Y = np.sum(some_X, axis=1)
some res
linear_residuals(some_x, some_beta, some_Y)
%3D
assert np.array_equal (some_res.round (3), np.array([16.938, 35.844, 33. 812, 59.281, 16.938, 39.719, 16.938] ))
# Checking against the pre-computed test database
test results
test_case_checker (linear_residuals, task_id=3)
assert test_results['passed'], test_results['message']
expand button
Transcribed Image Text:Using the linear_predict function that you previously wrote, write a function linear_residuals that given the learned weights in the linear_regression function calculates the residuals vector. Your functions takes the following arguments as input: 1. X:A numpy array of the shape (N,d) where N is the number of data points, and d is the data dimension. Do not assume anything about N or d other than being a positive integer. 2. beta : Anumpy array of the shape (d+1,1) where d is the data dimension Bo Ba 3. Y: A numpy array of the shape (N,) where N is the number of data points. Your function should produce the e numpy array with the shape of (N,), whose i" element is defined as el) = yl) – (Bo + Bix? + Bzx + + Bax) In [ ]: def linear_residuals (X,beta,Y): assert X.ndim==2 N = X.shape[0] х.shape[1] assert beta.shape assert Y.shape d = (d+1,1) (N,) == == #3 your code here e e.reshape(-1) %3D assert e.size return e (np.arange ( 35).reshape ( 7,5) ** 13) % 20 2.** (-np.arange (6).reshape (-1,1)) In [ ]: some_X = some beta = some_Y = np.sum(some_X, axis=1) some res linear_residuals(some_x, some_beta, some_Y) %3D assert np.array_equal (some_res.round (3), np.array([16.938, 35.844, 33. 812, 59.281, 16.938, 39.719, 16.938] )) # Checking against the pre-computed test database test results test_case_checker (linear_residuals, task_id=3) assert test_results['passed'], test_results['message']
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY