# How to compute the F1 score?

Here is my code:

score = metrics.f1_score(y_test[0:], y_pred, pos_label=list(set(y_test)))


And here are my dimensions/shapes, which I print before executing the score line (the line producing the error), and they get printed:

Original df shape:  (6944, 13)
x_train (Training Features) Shape: (4860, 12)
y_train (Training Labels) Shape: (4860,)
x_test (Testing Features) Shape: (2084, 12)
y_test (Testing Labels) Shape: (2084,)
features length: 38
Accuracy: 0.731765834933
y_pred shape:  (2084,)
y_pred:
[1 1 1 ..., 1 0 0]
y_test shape:  (2084,)
y_test:
1330    1
2543    1
....
many other 0,1 values here! Deleted for the post clarity
....
3025    0
5776    1


I am getting following error:

ValueError                                Traceback (most recent call last)
<ipython-input-440-9059291258bf> in <module>()
44 from sklearn import metrics
45
---> 46 score = metrics.f1_score(y_test[0:], y_pred, pos_label=list(set(y_test)))
47
48 #print(y_pred)
........
........
ValueError: all the input arrays must have same number of dimensions


So I am giving wrong dimensions to metrics.f1_score function. How could I pass the y_test and y_pred in the right form?

I think you misinterpreted the meaning of pos_label. It is used for choosing the positive label; its default value is set to $$1$$, which means the method calculate precision, recall and therefore f1 score by assuming class 1 as positive class, and class 0 as negative class. You seem to interpret it as possible labels, because you input unique class labels in the test set. Just remove pos_label argument from your call.