R_Language 板


LINE

研究 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)



※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: gsuper (114.32.215.136), 时间: 11/30/2013 22:45:16 ※ 编辑: gsuper 来自: 114.32.215.136 (11/30 22:45)
1F:→ clickhere:predict.sourcetracker() 11/30 23:00
2F:→ clickhere:S3并无需特别宣称(理论上需要),class(model)就已将其 11/30 23:02
3F:→ clickhere:改定为该类别. predict 是个S3函数. 故自行定义 predict 11/30 23:03
4F:→ clickhere:该类别即可. 11/30 23:04
5F:→ clickhere:methods("predict")可以知道哪些S3类别可用 11/30 23:07
原来如此 source(../script/sourcetracker.R) 里面有 predict.sourcetracker() plot.sourcetracker.fit() plot.sourcetracker.pie() plot.sourcetracker.bar() plot.sourcetracker.dist() 也就是说 , predict() 或 plot() 的 input 若先天上带有 class 就会去找这些 function 来用 谢谢C大 ! ※ 编辑: gsuper 来自: 114.32.215.136 (12/01 14:24) 更正一下 sourcetracker() 跑出来的结果是变数 "model" class(model) 等於 "sourcetracker" model 套用 predict() 後 , 自动转向 predict.sourcetracker() 也就是说原本的 predict 被暂时覆盖掉 predict.sourcetracker() 输出的结果是变数 results , class(results) 等於 "sourcetracker.fit" results 套用 plot() 後 , 自动转向 plot.sourcetracker.fit() 逻辑到这边就很清楚了 ※ 编辑: gsuper 来自: 114.32.215.136 (12/01 19:19)







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:iOS站内搜寻

TOP