Creating confusion matrix from multiple .csv files

前端 未结 2 1611
醉话见心
醉话见心 2021-01-28 07:20

I have a lot of .csv files with the following format.

338,800
338,550
339,670
340,600 
327,500
301,430
299,350
284,339
284,338
283,335
283,330
283,310
282,310
         


        
2条回答
  •  [愿得一人]
    2021-01-28 07:48

    Using Scikit-Learn is the best option to go for in your case as it provides a confusion_matrix function. Here is an approach you can easily extend.

    from sklearn.metrics import confusion_matrix
    
    # Read your csv files
    with open('A1.csv', 'r') as readFile:
        true_values = [int(ff) for ff in readFile]
    with open('B1.csv', 'r') as readFile:
        predictions = [int(ff) for ff in readFile]
    
    # Produce the confusion matrix
    confusionMatrix = confusion_matrix(true_values, predictions)
    
    print(confusionMatrix)
    

    This is the output you would expect.

    [[0 2]
     [0 2]]
    

    For more hint - check out the following link:

    How to write a confusion matrix in Python?

提交回复
热议问题