Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing outer() with predict()
    primarykey
    data
    text
    <p>I am trying to use the <strong>outer</strong> function with <strong>predict</strong> in some classification code in R. For ease, we will assume in this post that we have two vectors named <strong>alpha</strong> and <strong>beta</strong> each containing ONLY 0 and 1. I am looking for a simple yet efficient way to pass all combinations of <strong>alpha</strong> and <strong>beta</strong> to <strong>predict</strong>.</p> <p>I have constructed the code below to mimic the lda function from the MASS library, so rather than "lda", I am using "classifier". It is important to note that the prediction method within <strong>predict</strong> depends on an (<strong>alpha</strong>, <strong>beta</strong>) pair.</p> <p>Of course, I could use a nested for loop to do this, but I am trying to avoid this method.</p> <p>Here is what I would like to do ideally:</p> <pre><code>alpha &lt;- seq(0, 1) beta &lt;- seq(0, 1) classifier.out &lt;- classifier(training.data, labels) outer(X=alpha, Y=beta, FUN="predict", classifier.out, validation.data) </code></pre> <p>This is a problem because <strong>alpha</strong> and <strong>beta</strong> are not the first two parameters in <strong>predict</strong>.</p> <p>So, in order to get around this, I changed the last line to</p> <pre><code>outer(X=alpha, Y=beta, FUN="predict", object=classifier.out, data=validation.data) </code></pre> <p>Note that my validation data has 40 observations, and also that there are 4 possible pairs of <strong>alpha</strong> and <strong>beta</strong>. I get an error though saying</p> <pre><code>dims [product 4] do not match the length of object [40] </code></pre> <p>I have tried a few other things, some of which work but are far from simple. Any suggestions?</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.
 

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