Why is subplot making another matrix next to my matrix?

21 views Asked by At

I have a function that produces me confusion matrixes to some data. If i run this function without subplot in it it works fine but my matrixes are one under another, i wanted to add subplot but it makes weird thing next to my matrix.

Here is the code:

def crossValidation(cla):
    i = 1
    skf=StratifiedKFold(n_splits=5, shuffle=True, random_state=2)
    acc=[] 
    net_mat=np.zeros((4, 4))
    for train_index, test_index in skf.split(X,Y):
        X_train=X[train_index]
        X_test=X[test_index]
        Y_train=Y[train_index]
        Y_test=Y[test_index]

        cla.fit(X_train, Y_train)  
        Y_testPred = cla.predict(X_test) 

        testAccuracy = metrics.accuracy_score(Y_test, Y_testPred)
        print("Test Accuracy", testAccuracy*100)
        acc.append(testAccuracy)   

        matrix1 = confusion_matrix(Y_test, Y_testPred)
        #sum of the total confusion matirx
        net_mat=net_mat+matrix1
        plt.subplot(6, 2, i)

        plot_confusion_matrix(matrix1,class_names=['A', 'B','C','D'],show_normed=True, colorbar=True, show_absolute=True,figsize=(4,4))   
        i = i + 1
        plt.show()
    return net_mat,acc
0

There are 0 answers