Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions transplant/features/dynamic_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pandas as pd
import json
import os
import pandas as pd
import seaborn as sns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ajouter au fichier requirements.txt pour être bien sûr qu'on ait toutes les libs au setup!

import numpy as np
import matplotlib.pyplot as plt


class ts_extraction:
"""
Compute features on TS for the dynamic dataset

Input :
- df, dynamic Dataset
Output :
- df, with new features (prefix _tresh)

"""
def __init__(self, df):
self.df = df

def f_treshold(self, treshold_json):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Où se trouve le fichier threshold_json ? Je l'ajouterais au fichier config.py cf ici


for i in treshold_json.keys():

tjson = treshold_json[i]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cela suppose qu'on ait des valeurs de threshold pour toutes les colonnes du DataFrame df non? Est ce que le script plante s'il n'y a pas de valeurs correspondante trouvée?

name_new_feature = i
serie = self.df[i]
cond1 = (serie >= tjson["etendue"][0] ) & (serie < tjson["normalite"][0])
cond2 = (serie <= tjson["etendue"][1] ) & (serie > tjson["normalite"][1])

self.df[i + "_abnormal_tresh"] = np.where(cond1 | cond2, 1, 0)
self.df[i + "_clean_tresh"] = np.where((serie >= tjson["etendue"][0]) & (serie <= tjson["etendue"][1] ), 1, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: > 80 char

self.df[i + "_normal_tresh"] = np.where((serie >= tjson["normalite"][0]) & (serie <= tjson["normalite"][1] ), 1, 0)
self.df[i + "_dirty_tresh"] = np.where((serie <= tjson["etendue"][0]) & ( serie >= tjson["etendue"][1] ), 1, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne trouve pas les prefix dirty vs clean très clair. Pourquoi ne pas simplement détecter si les valeurs sont normal ou abnormal (Sachant que ce sera plutôt cela qu'on regardera) ?

Aussi en terme d'output, là tu renvoies quatre colonnes par variable ce qui me parait beaucoup. Pourquoi ne pas renvoyer une nouvelle colonne avec un booléen, e.g:

  • etco2_threshold: avec 1 ou 0 où 1 désigne une anormalité et 0 normalité


def plot_tresh(self, treshold_json ,id_patient = 100, var = "Pmean", title = '') :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est ce qu'on ne mettrait pas ça plutôt dans la classe visualization ? https://github.com/dataforgoodfr/batch_5_transplant/blob/master/transplant/visualization/graph.py

On pourrait imaginer un paramètre lorsque tu plot une timeseries avec une variable qui renverrait les limites. Tu pourrais aussi créer une autre fonction pour plotter les aires au-dessus / en-dessous des variables anormales? Qu'en penses tu ?



serie = self.df[self.df.id_patient == id_patient ][var]

y = serie.values
x = serie.reset_index().index

fig, ax, = plt.subplots(1, 1, sharex=True)
ax.plot(x, y , color='black')

cond1 = (y <= treshold_json[var]["normalite"][0])
cond2 = (y >= treshold_json[var]["normalite"][1])

ax.fill_between(x, y, treshold_json[var]["normalite"][0], where = cond1, facecolor='red', interpolate=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: > 80 char

ax.fill_between(x, y, treshold_json[var]["normalite"][1], where = cond2, facecolor='red', interpolate=True)
ax.set_title(title)
plt.show()