Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 209020

How to write a command fuction for the step function learner

$
0
0

Data have just y and x as output and input variables.

We are interested in constructing a step function learner as follows:

First draw a random number U uniformly on the interval spanned by the minimum and maximum values of the inputs (x1, ... , xn) and then use it to construct the following function whose purpose is to give the prediction of Y given X = x: f(x)= alpha1 I(U <= x) + Alpha2 I(U >x), where alpha1 and alpha2 are just unknown constants to be learned.

It goes without saying that I(some statement) is the indicator function that equals 1 when the statement is true and 0 otherwise.

a. Use two different methods to compute the estimate f(x)= alpha1 I(U<= x)+ alpha2 I(U > x). Is f^ a strong learner?

b. Use one of the previous two methods to write an R function that takes as input x and the data (x1, ..., xn, y1; ..., yn) and gives as output f^(x). Make sure the function is capable of dealing with the case where x conatains more than one number.

c. Using three different runs of the previous function, create three different plots where, on each, f^ is shown together with the scatter plot of the data.


Viewing all articles
Browse latest Browse all 209020

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>