
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
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']](https://content.bartleby.com/qna-images/question/4902cbb3-0fbf-4391-90d0-15ad68ae7505/861e7b06-e437-4ef8-9567-c3d6c88f0531/4vmfqb_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images

Knowledge Booster
Similar questions
- Question : Imagine that you track your commute times for (10 days) and recorded your observations in minutes as {17, 16, 20, 24, 22, 15, 21, 15, 17, 22}. Enter your observations into a series (vector) in Python and label it 'data'. Next answer the following questions: ● How many times were your commute 20 minutes or more? Hint: Write a condition! What percent of your commutes are less than 17 minutes?arrow_forwardvector, or a matrix in the same way as described for rand function. EXERCISE I8 Generate a random integer between I and 10. Ask user to guess the number. If user's guess is incorrect, ask' to guess again until user gets it right. At this point, tell user that he guessed it correctly and print out the number of attempts it took for the correct guess. Output Samples >> exercisel8 Please guess an integer between 1 and 10: 5 Your guess is incorrect. Please try again: 2 You guessed it correctly in 2 attemptS >> >> exercise16 Please guess an integer between 1 and 10: 2 Your guess is incorrect. Please try again: 3 Your guess is incorrect. Please try again: 6 Your guess is incorrect. Please try again: 5 Your guess is incorrect. Please try again: 8 Your guess is incorrect. Please try again: 9 Your guess is incorrect. Please try again: 10 Your guess is incorrect. Please try again: 1 Your guess is incorrect. Please try again: 4 Your guess is incorrect. Please try again: 7 You guessed it correctly…arrow_forwardUse Matlabarrow_forward
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY