Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Do following project in racket language #lang racket (provide (all-defined-out)) ;; for us to test (require racket/trace) ii in case you want to use tracing
Do following project in racket language
#lang racket (provide (all-defined-out)) ;; for us to test (require racket/trace) ii in case you want to use tracing (require "PTS.rkt") ; to access the database of points You are only allowed to use functions, if-then-else, cond, list operations, operations on numbers. No imperative-style constructs, such as begin-end or explicitly variable assignments, such as get/set are allowed. If you do not follow the guidelines, your submission will not be graded. If you are in doubt that you are using some construct that may violate rules, please contact instructor/TA (post on Piazza). Questions Given two variables, 2 (explanatory variable) and y (dependent variable), linear regression analysis aims to model the dependency of yon x (using a line, hence the name linear). For the purpose of discussion of this problem-specification, consider the coordinates in a 2-D plan, where the 2-coordinates of the points indicate the valuations of c-variable and the y-coordinates of the points indicates the corresponding valuations of y variable. For instance, the data contains n points in the plane, represented as (21,41), (22, y2), ..., (2n, yn). For linear regression of y on 2, our objective is to obtain a line y = mx + c, in particular the values of m (slope) and c(intercept), such that the points on this line "closely reflect the data. That is, i = mci tc is a reflection of yi when is equal to 2. To realize the objective, we need to minimize the overall error E in predicting the value of y for a given value of , i.e. == (yi - :)= - (yi - (mx; + c)2 (1) 1. The result is the least squares method for computing the values of m and c, which minimizes E. The method computes m and c as follows: i=1 m = ( 2/3 1) (ti ) and c=t m In the above, 7 and y denote the mean of the 2;s and yis respectively. For example, if the points are (0,0),(1,1), (2, 2), then m = 1 and c= 0. If the points are (1,0), (2,1), (3, 2), then m= 1 and c= -1. You are given a set of points in a Racket file PTS.rkt: (define ptsi '((O 1) (2 3) (1 0) (3 3) (50))) (define pts2' ((0 0) (1 1) (2 2) (33))) (define pts3 '((1 0) (2 1) (3 2) (4 3))) Write a function compute.mc that takes as arguments the list of points and returns a list contain- ing two elements: the first element is the valuation of m and the second that of c. compute_mc implements the least squares method. For example, > (compute_mc ptsl) (-0.02702702702702699 1.4594594594594592) > (compute_mc pts2) (1.0 0.0) > (compute_mc pts) (1.0 -1.0) #lang racket (provide (all-defined-out)) ;; for us to test (require racket/trace) ii in case you want to use tracing (require "PTS.rkt") ; to access the database of points You are only allowed to use functions, if-then-else, cond, list operations, operations on numbers. No imperative-style constructs, such as begin-end or explicitly variable assignments, such as get/set are allowed. If you do not follow the guidelines, your submission will not be graded. If you are in doubt that you are using some construct that may violate rules, please contact instructor/TA (post on Piazza). Questions Given two variables, 2 (explanatory variable) and y (dependent variable), linear regression analysis aims to model the dependency of yon x (using a line, hence the name linear). For the purpose of discussion of this problem-specification, consider the coordinates in a 2-D plan, where the 2-coordinates of the points indicate the valuations of c-variable and the y-coordinates of the points indicates the corresponding valuations of y variable. For instance, the data contains n points in the plane, represented as (21,41), (22, y2), ..., (2n, yn). For linear regression of y on 2, our objective is to obtain a line y = mx + c, in particular the values of m (slope) and c(intercept), such that the points on this line "closely reflect the data. That is, i = mci tc is a reflection of yi when is equal to 2. To realize the objective, we need to minimize the overall error E in predicting the value of y for a given value of , i.e. == (yi - :)= - (yi - (mx; + c)2 (1) 1. The result is the least squares method for computing the values of m and c, which minimizes E. The method computes m and c as follows: i=1 m = ( 2/3 1) (ti ) and c=t m In the above, 7 and y denote the mean of the 2;s and yis respectively. For example, if the points are (0,0),(1,1), (2, 2), then m = 1 and c= 0. If the points are (1,0), (2,1), (3, 2), then m= 1 and c= -1. You are given a set of points in a Racket file PTS.rkt: (define ptsi '((O 1) (2 3) (1 0) (3 3) (50))) (define pts2' ((0 0) (1 1) (2 2) (33))) (define pts3 '((1 0) (2 1) (3 2) (4 3))) Write a function compute.mc that takes as arguments the list of points and returns a list contain- ing two elements: the first element is the valuation of m and the second that of c. compute_mc implements the least squares method. For example, > (compute_mc ptsl) (-0.02702702702702699 1.4594594594594592) > (compute_mc pts2) (1.0 0.0) > (compute_mc pts) (1.0 -1.0)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started