Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will try to explain the cost function in simple words. Let's take <code>cv.glm(data, glmfit, cost, K)</code> arguments step by step:</p> <ol> <li><p><code>data</code> The data consists of many observations. Think of it like series of numbers or even.</p></li> <li><p><code>glmfit</code> It is generalized linear model, which runs on the above series. But there is a catch it splits data into several parts equal to K. And runs <code>glmfit</code> on each of them separately (test set), taking the rest of them as training set. The output of <code>glmfit</code> is a series consisting of same number of elements as the split input passed.</p></li> <li><p><code>cost</code> Cost Function. It takes two arguments first the split input series(test set), and second the output of <code>glmfit</code> on the test input. The default is mean square error function. <img src="https://i.stack.imgur.com/VOQqy.png" alt="The MSE function">. It sums the square of difference between observed data point and predicted data point. Inside the function a loop runs over the test set (output and input should have same number of elements) calculates difference, squares it and adds to output variable.</p></li> <li><p><code>K</code> The number to which the input should be split. Default gives leave one out cross validation.</p></li> </ol> <p>Judging from your cost function description. Your input(x) would be a set of numbers between 0 and 1 (0-0.5 = no and 0.5-1 = yes) and output(y) is 'yes' or 'no'. So error(e) between observation(x) and prediction(y) would be :</p> <pre><code>cost&lt;- function(x, y){ e=0 for (i in 1:length(x)){ if(x[i]&gt;0.5) { if( y[i]=='yes') {e=0} else {e=x[i]-0.5} }else { if( y[i]=='no') {e=0} else {e=0.5-x[i]} } e=e*e #square error } e=e/i #mean square error return (e) } </code></pre> <p>Sources : <a href="http://www.cs.cmu.edu/~schneide/tut5/node42.html" rel="nofollow noreferrer">http://www.cs.cmu.edu/~schneide/tut5/node42.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload