Mercurial > repos > deepakjadmin > r_caret_test
comparison caret_future/tool3/test/tmp1/Preold_advance.R @ 0:68300206e90d draft default tip
Uploaded
author | deepakjadmin |
---|---|
date | Thu, 05 Nov 2015 02:41:30 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:68300206e90d |
---|---|
1 ########## | |
2 args <- commandArgs(T) | |
3 arg1 <- args[1] | |
4 arg2 <- args[2] | |
5 arg3 <- args[3] | |
6 #source("~/galaxy-dist/tools/mpdstoolsV2/tool3/Preold.R") | |
7 #pre(arg1,arg2,arg3) | |
8 | |
9 pre <- function(args1,args2,args3){ | |
10 #args <- commandArgs(TRUE) | |
11 nTrain <- read.csv(args1,row.names= 1, header = T) # example nTrain.csv file of unknown activity | |
12 #save(nTrain,file = "nTrain.RData") | |
13 #load("nTrain.RData") | |
14 load(args2) # model generated from previous programn | |
15 newdata <- nTrain | |
16 modelFit <- Fit | |
17 ########### | |
18 # input csv file must contaion the exact same column as used in model building # | |
19 # Also do pre-proccessing by means of centering and scaling | |
20 ## problem in s4 object so first check that the given model has s4 object in | |
21 ## >isS4(Fit$finalmodel) if it is s4 than add in with elseif loop | |
22 ## eg . isS4(plsFit$finalModel) == TRUE | |
23 | |
24 library(caret) | |
25 | |
26 #if(as.character(!isS4(Fit$finalModel == "TRUE"))) | |
27 if(Fit$method != "svmRadial") | |
28 { | |
29 reqcol <- Fit$finalModel$xNames | |
30 newdata <- newdata[,reqcol] | |
31 newdata1 <- preProcess(newdata, method = c("center", "scale")) | |
32 newdata11 <- predict(newdata1,newdata) | |
33 ########### | |
34 library(stats) | |
35 testpredict <- predict(modelFit,newdata11) | |
36 Label <- levels(testpredict) | |
37 a1 <- Label[1] | |
38 a2 <- Label[2] | |
39 probpredict <- predict(modelFit,newdata11,type="prob") | |
40 names <- as.data.frame(rownames(nTrain)) | |
41 colnames(names) <- "COMPOUND" | |
42 activity <- as.data.frame(testpredict) | |
43 colnames(activity) <- "PREDICTED ACTIVITY" | |
44 colnames(probpredict) <- c(eval(a1),eval(a2)) | |
45 Prob <- as.data.frame(probpredict) | |
46 dw <- format(cbind(names,Prob,activity),justify="centre") | |
47 write.table(dw,file=args3,row.names=FALSE,sep="\t") | |
48 } | |
49 else if(Fit$method == "svmRadial") | |
50 { | |
51 library(stats) | |
52 newdata1 <- preProcess(newdata, method = c("center", "scale")) | |
53 newdata11 <- predict(newdata1,newdata) | |
54 #library(stats) | |
55 #testpredict <- predict(modelFit,newdata11) | |
56 #names <- as.data.frame(rownames(nTrain)) | |
57 #colnames(names) <- "COMPOUND" | |
58 #activity <- as.data.frame(testpredict) | |
59 #colnames(activity) <- "ACTIVITY" | |
60 #dw <- cbind(names,activity) | |
61 #write.csv(dw,file=args3,row.names=FALSE) | |
62 library(stats) | |
63 testpredict <- predict(modelFit,newdata11) | |
64 Label <- levels(testpredict) | |
65 a1 <- Label[1] | |
66 a2 <- Label[2] | |
67 probpredict <- predict(modelFit,newdata11,type="prob") | |
68 names <- as.data.frame(rownames(nTrain)) | |
69 colnames(names) <- "COMPOUND" | |
70 activity <- as.data.frame(testpredict) | |
71 colnames(activity) <- "PREDICTED ACTIVITY" | |
72 colnames(probpredict) <- c(eval(a1),eval(a2)) | |
73 Prob <- as.data.frame(probpredict) | |
74 dw <- format(cbind(names,Prob,activity),justify="centre") | |
75 write.table(dw,file=args3,row.names=FALSE,sep="\t") | |
76 } | |
77 else { | |
78 dw <- "There is something wrong in data or model" | |
79 write.csv(dw,file=args3,row.names=FALSE) | |
80 | |
81 } | |
82 | |
83 } | |
84 pre(arg1,arg2,arg3) |