作者gsuper (Logit(odds))
看板Statistics
标题[程式] predict() in R
时间Sat Nov 30 22:12:59 2013
研究 S3 与 predict() 的关联
-----------------------------
我以前的观念
认为 predict() 的使用 , 是凑齐两种条件
1. model <- lm(y~x) : 给予 linear model
2. Xpoint <- as.data.fram(x) : 给予 x 向量
在这样的情况下
model 提供了回归模型的趋势线参数 y=ax+b
Xpoint 提供了 x 值 , 套入趋势线的 y=ax+b
得到 predicted y , 异於 real data y
-----------------------------
但我现在在研究一个 R package
作者的程序如下
source(../script/sourcetracker.R)
这个 sourcetracker.R 里面包有一个 main function , sourcetracker()
还有大约 10 来个小 functions
-----------------------------
作者先用 sourcetracker() , 产生一个 model 变数
model 变数的内容很单纯 , 都是 matrix 与 factor 而已
(我有把它拆开来跑过了 , 确定是单纯变数)
model <- list(NULL)
model[[2]] <- 原始矩阵 (training set) [90样本 & 100features]
model[[3]] <- group factors [30 vs 30 vs 30 (total 90 样本)]
model[[1]] <- 根据 model[[3]] 的 factor , 将原始矩阵分成三分取 colSums
然後再 rbind() , 变成 [3混合样本 & 100 features]
最後作者加了一行
class(model) <- "sourcetracker"
-----------------------------------------------------------
接下来作者进行 predict()
predict( model , testSET , alpha1=0.001 , alpha2=0.001 )
其中 model[[2]] 是 training set , 用来建造 model
[资料矩阵维度 : 90 x 100]
而 testSET 是 testing set , 是需要被预测的资料
[资料矩阵维度 :10 x 100]
***
如果把 source(../script/sourcetracker.R)
收进来的小 fuinction 砍掉 , predict() 会跳出错误
-----------------------------------------------------------
关键在这行
class(model) <- "sourcetracker"
当宣告了特定 class 後
再套用 predict() , predict() 就能进行计算 (不加就不能算)
但 model 这个变数根本不是 线型模型
所以 predict() 吃入 model 变数後
还需要做一大堆事情才能得到结果
(Gibb`s sampling,cross-validation,贝式 etc.)
但我不明白的是 , predict() 是怎麽知道接下来要做哪些事情?
因为我看其他的 internal function , 并没有特别宣称自己是属於 "sourcetracker"
那 predict() 要怎麽辨认这些 function , 并按照正确的顺序使用??
诚心求教
--
我用名为真心的卡牌说服你
这是我最後一张牌
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.32.215.136
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:13)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:13)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:14)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:15)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:16)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:16)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:17)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:17)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:19)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:20)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:21)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:30)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:32)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:35)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:35)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:37)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:37)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:38)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:38)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:39)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:43)
※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:43)
※ gsuper:转录至看板 R_Language 11/30 22:45
1F:→ obarisk:predict."class name" 12/01 22:07
2F:→ obarisk:如果是s3的话,就上面了! 12/01 22:09
OK 我学会了 , 感谢
※ 编辑: gsuper 来自: 114.32.215.136 (12/02 08:44)