I have trained two models to detect gestures using ambient light and solar panels. I am now testing the two models in different light scenarios. I have a Convolutional Neural Network model that performs slightly better than a Random Forest in terms of accuracy, but in darker intensities (<650 lux), RF outperforms CNN in terms of precision and recall.
My question is - How can my CNN model have a greater accuracy than precision, recall and F-score? Such as my living room dataset (350 lux).
And, how can my RF model after 650 lux outperform CNN in precision, recall and F-score but still receive a lower accuracy score than my CNN.
Could someone please help explain this to me, Thank you in advance
from sklearn.metrics import precision_score, recall_score, f1_score, accuracy_score
from sklearn.metrics import confusion_matrix
array_predicted = torch.tensor([])
array_labels = torch.tensor([])
loss_fn = nn.CrossEntropyLoss()
val_loss = 0
precision, recall, f1, accuracy = [], [], [], []
model.eval()
with torch.no_grad():
for i,(data, label) in enumerate(test_loader):
outputs = model(data.to(device))
val_loss += loss_fn(outputs, label.to(device))
predicted_classes = torch.max(outputs, 1)[1] # get class from network's prediction
array_predicted = torch.cat((array_predicted.cpu(),predicted_classes.cpu()),0)
array_labels = torch.cat((array_labels.cpu(), label.cpu()),0)
# calculate P/R/F1/A metrics for batch
for acc, metric in zip((precision, recall, f1),
(precision_score, recall_score, f1_score)):
acc.append(
metric(label.cpu(), predicted_classes.cpu(), average="macro")
)
accuracy.append(accuracy_score(label.cpu(), predicted_classes.cpu()))
[sum(x*100)//len(x) for x in [precision, recall, f1, accuracy]]