English 中文(简体)
以预测(a)取代外部
原标题:Using outer() with predict()
  • 时间:2010-01-13 06:01:26
  •  标签:
  • r

我正试图在R的某些分类法中使用outer功能。 简而言之,我们将在这一岗位上假设,我们有两个病媒,即:alpha>/strong>和。 每一条含有0和1。 我正在寻求一种简单而有效的途径,以通过alpha>/strong>和beta>的所有组合。

我已建造了以下代码,以便把Lda功能从MASS图书馆转播,而不是“lda”,我使用的是“帽子”。 必须指出,的预测方法取决于(alpha/strong>,beta)。

当然,我可以nes忙这样做,但我试图避免这种做法。

在这里,我想理想的做法是:

alpha <- seq(0, 1)
beta <- seq(0, 1)
classifier.out <- classifier(training.data, labels)
outer(X=alpha, Y=beta, FUN="predict", classifier.out, validation.data)

这是一个问题,因为alpha/strong>和beta不是的头两个参数。

因此,为了解决这一问题,我把最后一行改为最后一行。

outer(X=alpha, Y=beta, FUN="predict", object=classifier.out, data=validation.data)

请注意,我的验证数据有40个观察点,还有4个可能的空白点:。 我错了说的话。

dims [product 4] do not match the length of object [40]

我曾尝试过其他一些事情,其中一些工作但远非简单。 任何建议?

最佳回答

问题在于,外部希望其功能能够成为病媒(即,它将用它所希望执行的所有论点的矢量预测欧安会)。 因此,当一度要求其结果(结果为4年)时,外部申诉就等于预期40。

解决这一问题的一个途径是使用<代码>检测。 未经测试的法典:

outer(X=alpha, Y=beta, FUN=Vectorize(predict, vectorize.args=c("alpha", "beta")), object=classifier.out, data=validation.data)
问题回答

我认为这是这样做的一个体面的方法。 这里是:

pairs <- expand.grid(alpha, beta)
names(pairs) <- c("alpha", "beta")
mapply(predict, pairs$alpha, pairs$beta, 
    MoreArgs=list(object=classifier.out, data=validation.data))

任何人都比较简单、更有效率? 我非常想知道,因为我在这个问题上花了太长时间。





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...