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 :A numpy array of the shape (d+1,1) where d is the data dimension Bo ... L 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'h element is defined as e) = y) – (Bo + Bix + B2x + …· + Baxg)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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']
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY