Question 3 The objective of this question is to give practice with using attributes and connecting their use and behavior with lists. In statistics and machine learning, it is often useful/necessary to rescale (or normalize) the range of data values to a standard interval. The simplest method of rescaling is min-max scaling (or min-max normalization), which rescales the range of the data values to the interval [0, 1]. Formally, if x = (21, 22, ..., Zn) is a sample of data values, then the min-max scaling to [0, 1] is Xi – min(x) for i=1,2,...,n. max(x) – min(x)' The scaled values z= (21, 22, ..., Zn) would have a range of (0, 1). More generally, the min-max scaling to an interval [a,b], with a <b, is given by [xi – min(x)](b − a) 2i = a + for i = 1,2,...,n. max(x) – min (2) 2i = Write a function called my_scale() that inputs a numeric vector x and outputs a vector such that: • The output vector contains the min-max scaled values of the input vector. • The output object contains additional attributes called a and b that contain, respectively, the original minimum and maximum of the input vector. • If the input vector does not contain both attributes a and b, the output vector should be scaled to the range from 0 to 1. If the input vector contains both attributes a and b, the output vector should be scaled to the range from a to b.
For any numeric vector x, the command my_scale(my_scale(x)) should represent the same vector of values as x. In other words, the my_scale() function is its own inverse function. Note 1: Attributes of an object that are not inherent to its class (e.g., the dim and dimnames attributes for matrix objects) will automatically be shown when printing the object. Note 2: This is not the same type of scaling as the built-in scale() function, which uses 2-score normalization (also called standardization). You should not use the scale() function for comparison.
Question 3 The objective of this question is to give practice with using attributes and connecting their use and behavio
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am