For the evaluation of the participating systems in this problem, we will be using the `micro-F1` measure, which is a label-based measure.

Here is a background on the `micro-F1` metric: In a multi-label classification problem, each instance can belong to zero or more classes simultaneously. The `micro-F1 score` is a global measure of performance that aggregates the contributions of all labels to compute an overall F1 score.

### Definition of `micro-F1`

The `micro-F1` score is defined as:
![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1896018%2Feb3bce37a1c6f955c8d2eab3eebd2e68%2Fmf1-a.png?generation=1762914341724216&alt=media)

where

![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1896018%2Fac84f1bee84c6d3c69c6482d11195537%2Fp_micro.png?generation=1762914358512316&alt=media)

![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1896018%2Fe85c4b090a5ae3ca6b4532c20dfd066f%2Fr_micro.png?generation=1762914371139202&alt=media)

* TP_i: True positives for label  i 
* FP_i: False positives for label  i 
* FN_i: False negatives for label  i 


### Intuition

* Micro-F1 treats every prediction equally, regardless of label type.
* It sums all true positives, false positives, and false negatives across all labels before computing precision and recall.
* Therefore, it favors performance on common classes and can be dominated by frequent labels.


### A simplified formula for `micro-F1` score

Because micro-precision and micro-recall are the same when computed globally, we can simplify:

![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1896018%2F1369ad79f59a70fd76c201267da14178%2Fmf1-b.png?generation=1762914422921232&alt=media)


### Example

Suppose across all labels:

* Total TP = 80 
* Total FP = 10 
* Total  FN = 30 

Then:

![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1896018%2F78aff97af89651345d7a86f22d97c3bb%2Fmf1-c.png?generation=1762914452538556&alt=media)


### Comparison note

| Metric       | How it’s computed              | Sensitive to                      |
| ------------ | ------------------------------ | --------------------------------- |
| **Micro-F1** | Aggregates all labels globally | Common classes                    |
| **Macro-F1** | Averages F1 per label          | Rare classes (equal label weight) |


### A code example

```python
from sklearn.metrics import f1_score

# Suppose we have 3 samples and 4 possible labels (multi-label setup)
# Each row corresponds to one sample, and each column to a label

# Ground truth labels
y_true = [
    [1, 0, 1, 0],  # sample 1
    [0, 1, 0, 1],  # sample 2
    [1, 1, 0, 0]   # sample 3
]

# Predicted labels
y_pred = [
    [1, 0, 0, 0],  # sample 1
    [0, 1, 1, 1],  # sample 2
    [1, 0, 0, 0]   # sample 3
]

# Compute micro-F1
micro_f1 = f1_score(y_true, y_pred, average='micro')

print(f"Micro-F1 Score: {micro_f1:.4f}")
#It should print: Micro-F1 Score: 0.6667

```

> Here, `average='micro'` option makes `f1_score()` aggregate all true positives, false positives, and false negatives across all labels before computing the F1.

## Submission File
Predict the MeSH labels for each of the article present in the `judge dataset` and save it as a CSV file, and submit that file. The format of the file should be:

```csv
"pmid","meshMajor"
16854706,"['Risk Assessment', 'Sensitivity and Specificity']"
12943287,"['Anti-Bacterial Agents']"
9808709,"['Prospective Studies', 'Male', 'Risk Assessment', 'Predictive Value of Tests', 'Aged']"
3856646,"['Anti-Bacterial Agents', 'Risk Factors', 'Time Factors', 'Adult']"
22033210,"['Risk']"
3594827,"['Prospective Studies', 'Fever of Unknown Origin']"
23332437,"['Neutropenia', 'Humans', 'Anti-Bacterial Agents']"
...
...
etc.
```

