Skip to content
Snippets Groups Projects
ex2_3_4.py 747 B
Newer Older
  • Learn to ignore specific revisions
  • bjje's avatar
    bjje committed
    # Exercise 4.2.4
    # requires data from exercise 4.1.1
    
    Stas Syrota's avatar
    Stas Syrota committed
    from matplotlib.pyplot import boxplot, figure, show, subplot, title, xticks, ylim
    
    bjje's avatar
    bjje committed
    
    
    Stas Syrota's avatar
    Stas Syrota committed
    figure(figsize=(14, 7))
    
    bjje's avatar
    bjje committed
    for c in range(C):
    
    Stas Syrota's avatar
    Stas Syrota committed
        subplot(1, C, c + 1)
        class_mask = y == c  # binary mask to extract elements of class c
    
    bjje's avatar
    bjje committed
        # or: class_mask = nonzero(y==c)[0].tolist()[0] # indices of class c
    
    Stas Syrota's avatar
    Stas Syrota committed
    
        boxplot(X[class_mask, :])
        # title('Class: {0}'.format(classNames[c]))
        title("Class: " + classNames[c])
        xticks(
            range(1, len(attributeNames) + 1), [a[:7] for a in attributeNames], rotation=45
        )
        y_up = X.max() + (X.max() - X.min()) * 0.1
        y_down = X.min() - (X.max() - X.min()) * 0.1
    
    bjje's avatar
    bjje committed
        ylim(y_down, y_up)
    
    show()
    
    
    Stas Syrota's avatar
    Stas Syrota committed
    print("Ran Exercise 4.2.4")