How to print value in list in R

r
list

#1
for(i in seq(from=0.05, to=0.2, by=0.01)){
    print(i)
  
    prediction <- as.numeric(test_pred >= i)
    print(prediction)

    TP<-sum(ifelse(prediction==test_label & test_label ==1,1,0))
    TN <-sum(ifelse(prediction==test_label & test_label ==0,0,1))
    FP <-sum(ifelse(prediction!=test_label & test_label ==1,1,0))
    FN <- sum(ifelse(prediction!=test_label & test_label ==0,0,1)) 
    precision <- (TP / TP + FP)
    recall <- (TP / TP + FN)
    F1 <- (2 * precision * recall) / (precision + recall)
    print(precision)
    print(recall)
    print(F1)
}

I need my value print in list , not one by one print. so I can check best value for Precision , Recall, F1.


#2

One way to go about this is to create empty vectors for precision, recall and F1 prior to entering the loop, and then append the values to the appropriate vector during each iteration. Print the vectors after exiting the loop.


#3

If possible ,please share little bit code sample.


#4
## Define vectors to store values
precision_vals <- numeric()
recall_vals <- numeric()
F1_vals <- numeric()

## Your for loop goes here
## ...
## Instead of printing values, append the values to above lists:
## e.g. precision_vals <- c(precision_vals, precision)

You can later print these vectors out to compare them in context.


#5

Thanks a lot.