2
$\begingroup$

I have a problem. Any help will be appreciated.

In order to calculate the accuracy, sensitivity, sensibility and F1 score between diseases and their symptoms, I have two matrices with a different Diseases associated with their symptoms with the same format but have different dimensions

Mtx1 = {{"di","s1","s2","s3","s4","s5","s6","s7","s8","s9","s10","s11"},{"d1",1,1,0,1,1,1,0,0,1,0,0},{"d2",0,1,1,1,0,0,1,0,1,1,1},{"d3",0,1,1,0,0,0,0,1,0,0,1},{"d4",0,1,0,1,1,0,0,1,0,1,0},{"d5",0,0,1,1,0,0,0,0,1,1,1},{"d6",0,0,0,0,1,0,0,0,0,0,0}};

second matrix:

Mtx2 = {{"di","s1","s7","s3","s6","s4","s8","s9","s10","s12"},{"d7",1,1,0,1,1,1,0,0,1}, {"d8",0,1,1,1,0,0,1,0,1},{"d9",0,1,1,0,0,0,0,1,0},{"d4",0,1,0,1,1,0,0,1,0},{"d1",0,0,1,1,0,0,0,0,1},{"d3",0,0,0,0,1,0,0,0,0},{"d10",0,1,0,0,1,0,0,0,0},{"d11",0,0,1,1,0,0,0,0,1}};

I would like to calculate the index of confusion diseases in Mtx1 and Mtx2 then the confusion matrix between diseases in two lists. using the below equation to calculate the index of confusion(IC), in fact, the IC assigns the similarity score of symptoms between two diseases. IC =(number of common symptoms between two diseases/Union of symptoms of these two diseases) Using Mathematica, this is my script for two diseases in a separated list:

(* 
d = disease 
s = symptoms 
1 = symptoms correspond to disease
0 = not a symptom for this disease
*)

D1 = Mtx1[[2]];
D2 = Mtx2[[2]];
PSMtx1 = Position[D1, 1] // Flatten;
PSMtx2 = Position[D1, 1] // Flatten;
AllS = (Union[PSMtx1, PSMtx2] // Dimensions)[[1]]
CommonS = (Intersection[PSMtx1, PSMtx2] // Dimensions)[[1]]
IC = CommonS/AllS // N

(* Out: *)
(* 6 *)
(* 6 *)
(* 1 *)

I did this computation, but it serves only for confusion between two diseases. what about the confusion between all diseases in two lists?

I want to adopt this code above for all diseases in both matrices to get the confusion matrices.

Does anybody have any insight?

$\endgroup$
  • 2
    $\begingroup$ Welcome to Mathematica.StackExchange. I see that you invested a lot of effort into formulating your question. That is great because that show other users that you really care! It would be easier to help you if you would also give short code for generating example datasets for Mtx1 and Mtx2. RandomReal and RandomInteger are usually very versatile for that. But that is not a problem. I tried run your code and found that you haven't defined PSR and PSC, yet. $\endgroup$ – Henrik Schumacher Apr 9 at 6:21
  • $\begingroup$ sorry it is a mistake of typing [PSMtx1, PSMtx2]==[PSR, PSC] $\endgroup$ – Ben Aawf Apr 9 at 10:29
  • $\begingroup$ Okay, I edited your post to include that. (You can and should make use of the edit functionality whenever needed.) Still, a bit more of context might be helpful. $\endgroup$ – Henrik Schumacher Apr 9 at 10:41
2
$\begingroup$

I just want to share the answer that I was looking for. in order to share the knowledge with others. First, I need to obtain a list of arrays where all sublist of my matrice transposed without the head of each sublist. (i didn't keep in mind that each sublist starts with string and need to remove them to make the computation of IC more significate).

vectosrset1 =Transpose[Delete[Transpose[Delete[Mtx1,{{1}}]], {{1}}]];

The below code calculating the IC between Diseases in matrix1

IC = Table[N[Dimensions[Intersection[Position[vectosrset1[[i]], 1],Position[vectosrset1[[j]], 1]][[1]]/Dimensions[Union[Position[vectosrset1[[i]], 1],Position[vectosrset1[[j]], 1]]][[1]]], {i, 1,Dimensions[vectosrset1][[1]]}, {j, 1,Dimensions[vectosrset1][[1]]}];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.