i = 1 # init. subplot counter # iterate over datasets (in reverse order, to match original layout) for ds in datasets [:: - 1 ]: # preprocess dataset, split into training and test part X , _y = ds X = StandardScaler () . fit_transform ( X ) X_train , X_test , y_train , y_test = train_test_split ( X , _y , test_size = 0.4 ) x_min , x_max = X [:, 0 ] . min () - . 5 , X [:, 0 ] . max () + . 5 y_min , y_max = X [:, 1 ] . min () - . 5 , X [:, 1 ] . max () + . 5 x = np . arange ( x_min , x_max , h ) y = np . arange ( y_min , y_max , h ) xx , yy = np . meshgrid ( x , y ) # Make color list (1 item for each per scatter pt) cm_train = [ cm_bright [ yy_train ] for yy_train in y_train ] cm_test = [ cm_bright [ yy_test ] for yy_test in y_test ] # Append 'data' with Scatter objects figure [ 'data' ] += [ make_Scatter ( i , X_train [:, 0 ], X_train [:, 1 ], 'Training' , cm_train , 1 )] figure [ 'data' ] += [ make_Scatter ( i , X_test [:, 0 ], X_test [:, 1 ], 'Test' , cm_test , 0.6 )] # Format subplot i's axes figure [ 'layout' ] . update ({ 'xaxis {} ' . format ( i ): make_XAxis ( x )}) figure [ 'layout' ] . update ({ 'yaxis {} ' . format ( i ): make_XAxis ( y )}) i += 1 # increment subplot counter # iterate over classifiers for name , clf in zip ( names , classifiers ): clf . fit ( X_train , y_train ) score = clf . score ( X_test , y_test ) # Plot the decision boundary. For that, we will assign a color to each # point in the mesh [x_min, m_max]x[y_min, y_max]. if hasattr ( clf , "decision_function" ): Z = clf . decision_function ( np . c_ [ xx . ravel (), yy . ravel ()]) else : Z = clf . predict_proba ( np . c_ [ xx . ravel (), yy . ravel ()])[:, 1 ] # Put the result into a color plot, append 'data' with Contour object Z = Z . reshape ( xx . shape ) figure [ 'data' ] += [ make_Contour ( i , x , y , Z )] # Plot also the training points and testing points, append 'data' figure [ 'data' ] += [ make_Scatter ( i , X_train [:, 0 ], X_train [:, 1 ], 'Training' , cm_train , 1 )] figure [ 'data' ] += [ make_Scatter ( i , X_test [:, 0 ], X_test [:, 1 ], 'Test' , cm_test , 0.6 )] # Format subplot i's axes figure [ 'layout' ] . update ({ 'xaxis {} ' . format ( i ): make_XAxis ( x )}) figure [ 'layout' ] . update ({ 'yaxis {} ' . format ( i ): make_YAxis ( y )}) # Add score annotation to 'layout' figure [ 'layout' ][ 'annotations' ] += [ make_score_anno ( i , x , y , score )] # Add subplot title to 'layout' if on the top-most row if i >= 22 : figure [ 'layout' ][ 'annotations' ] += [ make_sbplt_anno ( i , x , y , name )] i += 1 # increment subplot counter