-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeneral_utility_ml.py
More file actions
35 lines (34 loc) · 1.21 KB
/
general_utility_ml.py
File metadata and controls
35 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import pandas as pd
class GeneralUtiliy:
def confusion_matrix(self,data_x,data_y):
data_x=np.array(data_x)
data_y=np.array(data_y)
unique_y=np.unique(data_y)
unique_x=np.unique(data_x)
j=0
pos_dict={}
for nb in unique_x:
pos_dict[str(nb)]=j
j+=1
"""
that function take two array and compute
confusion matrix of them
on doit avoir une matrice carree
"""
lenght=len(unique_x)
confusition_matrix=np.zeros((lenght,lenght),dtype=int)
i=0
for nb_x in data_x:
nb_y=data_y[i]
pos_x=pos_dict[str(nb_x)] #position de x
pos_y=pos_dict[str(nb_y)] #pos_y
confusition_matrix[pos_x,pos_y]+=1
i=i+1
list_with_tuple=[]
for name in pos_dict.keys():
print(confusition_matrix[pos_dict[name]])
element=(name,confusition_matrix[pos_dict[name]])
list_with_tuple.append(element)
confusion_matrix_with_name=pd.DataFrame(data=confusition_matrix,columns=unique_x)
return {"confusion":confusition_matrix,"namedconfusion":confusion_matrix_with_name}