<s> COLOUR_FIGURE = False <EOL> from matplotlib import pyplot as plt <EOL> from matplotlib . colors import ListedColormap <EOL> from load import load_dataset <EOL> import numpy as np <EOL> from knn import fit_model , predict <EOL> feature_names = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def plot_decision ( features , labels ) : <EOL> '''<STR_LIT>''' <EOL> y0 , y1 = features [ : , <NUM_LIT:2> ] . min ( ) * <NUM_LIT> , features [ : , <NUM_LIT:2> ] . max ( ) * <NUM_LIT> <EOL> x0 , x1 = features [ : , <NUM_LIT:0> ] . min ( ) * <NUM_LIT> , features [ : , <NUM_LIT:0> ] . max ( ) * <NUM_LIT> <EOL> X = np . linspace ( x0 , x1 , <NUM_LIT:100> ) <EOL> Y = np . linspace ( y0 , y1 , <NUM_LIT:100> ) <EOL> X , Y = np . meshgrid ( X , Y ) <EOL> model = fit_model ( <NUM_LIT:1> , features [ : , ( <NUM_LIT:0> , <NUM_LIT:2> ) ] , np . array ( labels ) ) <EOL> C = predict ( <EOL> model , np . vstack ( [ X . ravel ( ) , Y . ravel ( ) ] ) . T ) . reshape ( X . shape ) <EOL> if COLOUR_FIGURE : <EOL> cmap = ListedColormap ( [ ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ) ] ) <EOL> else : <EOL> cmap = ListedColormap ( [ ( <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> ) , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ] ) <EOL> fig , ax = plt . subplots ( ) <EOL> ax . set_xlim ( x0 , x1 ) <EOL> ax . set_ylim ( y0 , y1 ) <EOL> ax . set_xlabel ( feature_names [ <NUM_LIT:0> ] ) <EOL> ax . set_ylabel ( feature_names [ <NUM_LIT:2> ] ) <EOL> ax . pcolormesh ( X , Y , C , cmap = cmap ) <EOL> if COLOUR_FIGURE : <EOL> cmap = ListedColormap ( [ ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ) ] ) <EOL> ax . scatter ( features [ : , <NUM_LIT:0> ] , features [ : , <NUM_LIT:2> ] , c = labels , cmap = cmap ) <EOL> else : <EOL> for lab , ma in zip ( range ( <NUM_LIT:3> ) , "<STR_LIT>" ) : <EOL> ax . plot ( features [ labels == lab , <NUM_LIT:0> ] , features [ <EOL> labels == lab , <NUM_LIT:2> ] , ma , c = ( <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> ) ) <EOL> return fig , ax <EOL> features , labels = load_dataset ( '<STR_LIT>' ) <EOL> names = sorted ( set ( labels ) ) <EOL> labels = np . array ( [ names . index ( ell ) for ell in labels ] ) <EOL> fig , ax = plot_decision ( features , labels ) <EOL> fig . savefig ( '<STR_LIT>' ) <EOL> features -= features . mean ( <NUM_LIT:0> ) <EOL> features /= features . std ( <NUM_LIT:0> ) <EOL> fig , ax = plot_decision ( features , labels ) <EOL> fig . savefig ( '<STR_LIT>' ) </s>
