# Confusion matrix using data from two matrices

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 =
{{ s1, s2, s3, s4. ..., s5788},
{d1, 1, 0, 0, 1, 0, ...},
{d2, 0, 0, 0, 0, 1, ,..},
...
{d3330, 0, 1, 1, 0, 0. ...}}
(* Dimension {3331, 5789} *)

Mtx2 =
{{s1, s2, s3, s4,..., s2092},
{d1, 1, 0, 0, 1, 0, ...},
{d2, 0, 0, 0, 0, 1, ...}
,..
{d4841, 0, 1, 1, 0, 0....}}
(* Dimension= {4832, 2092} *)


I would like to create the confusion matrix between diseases in Mtx1 and Mtx2 then the confusion matrix between diseases in two lists.

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: *)
(* 183 *)
(* 1 *)
(* 0.00546448 *)


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?

• 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. – Henrik Schumacher Apr 9 at 6:21
• sorry it is a mistake of typing [PSMtx1, PSMtx2]==[PSR, PSC] – Ben Aawf Apr 9 at 10:29
• 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. – Henrik Schumacher Apr 9 at 10:41