SchubertLab / mvTCR

MIT License
45 stars 4 forks source link

Tutorial "02_training_analysis.ipynb" Error: <path>/python3.10/site-packages/mvtcr/evaluation/Mtrics.py line 106 #16

Closed WhatMelonGua closed 3 months ago

WhatMelonGua commented 3 months ago

I'm not sure if I didn't install the env sucessfully, I just do as the readme said. When I use "Haniffa" data to test the tutorials "[01_preprocessing.ipynb](https://github.com/SchubertLab/mvTCR/blob/master/tutorials/01_preprocessing.ipynb)" & "02_training_analysis.ipynb"

The preprocessing works very well. But when it comes to train the model, the error happend...

It's time i have fix it, so i can give a blur description that it happened because of Metrics.py,numpy Error

at:(I have modified the scripts below, it can solve the error happened on this issue)


def get_knn_f1_within_set(latent, column_name):
    con = latent.obsp['connectivities'].todense().astype(bool)         # source [latent.obsp['connectivities'].A] > error: no attr .A
    nearest_neighbor_label = [latent.obs[column_name].values[np.array(row)[0]].tolist()[0] for row in con]    # below
    #source [nearest_neighbor_label = latent.obs[column_name].values[row].tolist()[0] ] ....
    # because row is type np.matrix, so can‘t use row[0] to get as 1-d index 
    # I transfer it to np.array then [0] to fix this issue
    labels_true = latent.obs[column_name].values
    if torch.is_tensor(nearest_neighbor_label[0]):
        nearest_neighbor_label = [str(el.item()) for el in nearest_neighbor_label]
        labels_true = [str(el.item()) for el in labels_true]
    result = classification_report(labels_true, nearest_neighbor_label, output_dict=True)
    result = result['weighted avg']['f1-score']
    return result

I have write down after ’#‘ to describe the scripts I modified

Then it can train sucessfully, with 'pseudo_metric' as params_optimization name。

Has anyone encountered such a problem? Or what could be causing this, package version or other factors? Thank you very much.

leuschjanphilipp commented 3 months ago

Hi, thanks for trying out mvTCR and having such a deep dive into the code! #17 and #14 face the same issue which is presumably caused by scipy version 1.14. As mentioned in #14 downgrading scipy to v1.13 solves this issue for now.

(However, without testing, it looks like one can also just use .toarray() instead of todense() so one doesnt need the conversion later as it already returns a np.array)