forked from Shoombuatong/PAAP
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRF-LOOCV.txt
More file actions
57 lines (50 loc) · 2.04 KB
/
Copy pathRF-LOOCV.txt
File metadata and controls
57 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#######set directory
setwd('D:\\Data for R\\Peptide prediction\\Antihypertensive peptides\\CLassification\\Backup')
#######Load package
library(caret)
library(randomForest)
library(protr)
library(seqinr)
library(Interpol)
##### Set parameter for PseAAC
para1 = 2
para2 = 0.1
##### Read data
x <- read.fasta('AHTP2132.fasta', seqtype="AA", as.string = TRUE)
D = read.csv("Label all.csv", header = TRUE)
###### Feature extraction
m = length(x)
aac <- t(sapply(x, extractAAC))
dpc <- t(sapply(x, extractDC))
paac <- matrix(nrow = m, ncol = 20 + para1)
for(i in 1:m){
paac[i, ]= extractPAAC(x[[i]][1],lambda = para1 , w = para2 , props = c("Hydrophobicity", "Hydrophilicity", "SideChainMass"))
}
######## Select feature for constructing predictor
internal = data.frame(aac,dpc,Class = D[,ncol(D)])
######### Optimized parameter
control <- trainControl(method="repeatedcv", number=10, repeats=3)
tunegrid <- expand.grid(.mtry=c(1:10), .ntree=c(100,200,300,400,500))
custom <- train(Class~., data=internal , method=customRF, metric=c("Accuracy"), tuneGrid=tunegrid, trControl=control)
######Loop for LOOCV
k <- nrow(internal);
Resultcv <- 0;
folds <- cvsegments(nrow(internal), k);
for (fold in 1:k){
currentFold <- folds[fold][[1]];
RF = randomForest(Class ~ ., internal[-currentFold,], ntree= as.numeric(custom$ bestTune[2]),mtry = as.numeric(custom$ bestTune[1]),
orm.votes=TRUE,keep.forest=TRUE, importance=TRUE) ## Building RF model
pred = predict(RF, internal[currentFold,])
Resultcv <- Resultcv + table(true=internal[currentFold,]$Class, pred=pred);
################### Performance report
data = Resultcv
ACCtr = (data[1]+data[4])/(data[1]+data[2]+data[3]+data[4])*100
SENStr = (data[1]/(data[1]+data[2]))*100
SPECtr = (data[4])/(data[3]+data[4])*100
MCC1 = (data[1]*data[4]) - (data[2]*data[3])
MCC2 = (data[4]+data[2])*(data[4]+data[3])
MCC3 = (data[1]+data[2])*(data[1]+data[3])
MCC4 = sqrt(MCC2)*sqrt(MCC3)
MCCtr = MCC1/MCC4
}
result = data.frame (ACCtr,SENStr,SPECtr,MCCtr)