Skip to content
Snippets Groups Projects
ex2_3_5.py 706 B
Newer Older
  • Learn to ignore specific revisions
  • # Exercise 2.3.5
    # (requires data from exercise 2.3.1)
    
    bjje's avatar
    bjje committed
    import matplotlib.pyplot as plt
    
    bjje's avatar
    bjje committed
    
    
    bjje's avatar
    bjje committed
    plt.figure(figsize=(12, 10))
    
    bjje's avatar
    bjje committed
    for m1 in range(M):
        for m2 in range(M):
    
    bjje's avatar
    bjje committed
            plt.subplot(M, M, m1 * M + m2 + 1)
    
    bjje's avatar
    bjje committed
            for c in range(C):
    
    Stas Syrota's avatar
    Stas Syrota committed
                class_mask = y == c
    
    bjje's avatar
    bjje committed
                plt.plot(np.array(X[class_mask, m2]), np.array(X[class_mask, m1]), ".")
    
    Stas Syrota's avatar
    Stas Syrota committed
                if m1 == M - 1:
    
    bjje's avatar
    bjje committed
                    plt.xlabel(attributeNames[m2])
    
    bjje's avatar
    bjje committed
                else:
    
    bjje's avatar
    bjje committed
                    plt.xticks([])
    
    Stas Syrota's avatar
    Stas Syrota committed
                if m2 == 0:
    
    bjje's avatar
    bjje committed
                    plt.ylabel(attributeNames[m1])
    
    bjje's avatar
    bjje committed
                else:
    
    bjje's avatar
    bjje committed
                    plt.yticks([])
    
    bjje's avatar
    bjje committed
    plt.legend(classNames)
    
    bjje's avatar
    bjje committed
    
    
    bjje's avatar
    bjje committed
    plt.show()
    
    bjje's avatar
    bjje committed