我无法从函数向函数分配数据集。它要求第一个函数调用第二个函数,反之亦然,以便给我正确的结果。
我已经查看了Stack Overflow上的其他R-Idioms,但我相信我有一个独特的问题。我需要将数据集输入到IBKClassifier函数中,该数据集来自下面的评估器函数。计算过程中,评估器又调用IBKClassifier函数。
#Classifiers
IBKClassifier <- function(TraindataLSVT1){
outputs <- evaluator(itn_num,TraindataLSVT_norm, TestdataLSVT_norm)
classifier <- IBk(class ~ ., data = outputs[10])
return(classifier)
}
#Column Dropping Function and Evaluation Metrics Function
evaluator <- function(itn_num,TraindataLSVT_norm,TestdataLSVT_norm){
for (K in itn_num){
D[n]<- ncol(TestdataLSVT_norm) - K # now specify the number of features to be dropped; K=310-D
s<- ranked_list[1:D[n]]
cols.dont.want <- c(names(s)) # identify names of low ranked features
TraindataLSVT1<- TraindataLSVT_norm[, !names(TraindataLSVT_norm) %in% cols.dont.want, drop = T] # now drop low ranked features from the training dataset
TestdataLSVT1<- TestdataLSVT_norm[, !names(TraindataLSVT_norm) %in% cols.dont.want, drop = T] # drop low ranked features from the test dataset
classifier <- IBKClassifier(TraindataLSVT1)
pred<-predict(classifier,TestdataLSVT1[1:K], na.action=NULL,seed=1) # deploy the new version of the dataset on the test dataset to make predictions
P11<-0
P12<-0
P21<-0
P22<-0
for ( i in seq(1,nrow(TestdataLSVT1))){
if(actual[i]==1){
if(pred[i]==1){
P11<-P11+1
}
else
{
P12<-P12+1
}
}
else if (actual[i]==2){
if(pred[i]==2){
P22<-P22+1
}
else
{
P21<-P21+1
}
}
}
accuracy[n] <- (P11+P22)/(P11+P12+P21+P22)
Prec_1[n]<-(P11/(P11+P21))
Prec_2[n]<-(P22/(P22+P12))
Recall_1[n]<-(P11/(P11+P12))
Recall_2[n]<-(P22/(P22+P21))
F1_1[n]<-(2*Prec_1[n]*Recall_1[n])/(Prec_1[n]+Recall_1[n])
F1_2[n]<-(2*Prec_2[n]*Recall_2[n])/(Prec_2[n]+Recall_2[n])
F_Weighted <- (F1_1*table(actual)[1] + F1_2*table(actual)[2])/(table(actual)[1]+table(actual)[2])
paste("This is the F1_1 score for class 1",F1_1[n])
paste("This is the F1_2 score for class 2",F1_2[n])
#t[n]<-system.time(IBk(class ~ ., data = TraindataLSVT1))
t[n]<-system.time(classifier)
confused_matrix<-matrix(c(P11,P12,P21,P22), nrow = 2, ncol = 2, byrow = F,
dimnames = list(c("class1","class2"),c("class1","class2")))
conf_matrix_list[n]<-list(confused_matrix)
cfm <- confusionMatrix(pred, reference = actual,positive = '1')
conf_matML[n] <- list(cfm$table)
if(n<length(itn_num)){
n <- n+1
}
outputs <- list(accuracy[n],Prec_1[n],Prec_2[n],Recall_1[n],Recall_2[n],F1_1[n],F1_2[n],F_Weighted,t[n],TraindataLSVT1,TestdataLSVT1)
}
return(outputs)
}
Error: node stack overflow
Error during wrapup: node stack overflow