def compare(k): N_INDCS = -1 map_test, map_train = map_overlay.basic_setup([100, 400], 50, label_name = "Jared") clf = ObjectClassifier() damage_labels = np.loadtxt('damagelabels50/Jared-3-3.csv', delimiter = ',').astype('int') building_labels = np.loadtxt('damagelabels50/all_rooftops-3-3.csv', delimiter =',').astype('int') segs = map_train.segmentations[50].ravel() n_segs = int(np.max(segs))+1 all_labels = np.zeros(n_segs) #Nothing = Green all_labels[damage_labels] = 1 #Damage = Red all_labels[building_labels] = 2 #Building = Blue all_data, y = clf._get_X_y(map_train, 'Jared') clf.fit(map_train, label_name = 'Jared') #<-this one changesthe training for the importance order names = clf.feat_names print names importances = clf.model.feature_importances_ indices = np.argsort(importances)[::-1] print names[indices][:N_INDCS] plt.figure() std = np.std([tree.feature_importances_ for tree in clf.model.estimators_], axis=0) plt.title("Feature importances") plt.bar(range(names.shape[0]), importances[indices], color="r", yerr=std[indices], align="center") plt.xticks(range(names.shape[0]), names[indices]) plt.xlim([-1, names.shape[0]]) all_histos(all_data[damage_labels], all_data[building_labels], all_data[np.where(all_labels == 0)[0]], names, indices[:N_INDCS]) #plt.show() return names, indices '''
def look_at_features(names, indices): N_INDCS = -1 map_test, map_train = map_overlay.basic_setup([100, 400], 50, label_name = "Jared") clf = ObjectClassifier() damage_labels = np.loadtxt('damagelabels50/Jared-3-3.csv', delimiter = ',').astype('int') building_labels = np.loadtxt('damagelabels50/all_rooftops-3-3.csv', delimiter =',').astype('int') segs = map_train.segmentations[50] n_segs = int(np.max(segs.ravel()))+1 all_labels = np.zeros(n_segs) #Nothing = Green all_labels[damage_labels] = 1 #Damage = Red all_labels[building_labels] = 2 #Building = Blue all_data, y = clf._get_X_y(map_train, 'Jared') ''' clf.fit(map_train, label_name = 'Jared') #<-this one changesthe training for the importance order names = clf.feat_names print names importances = clf.model.feature_importances_ indices = np.argsort(importances)[::-1]''' pbar = custom_progress() j = names.shape[0] for i in pbar(indices[::-1]): j-=1 fig = plt.figure(names[i]) plt.imshow(all_data[:,i][segs.astype('int')], cmap = 'gray') fig.savefig('/Users/jsfrank/Desktop/features/{}-{}'.format(j, names[i]), format='png') plt.close(fig)
def transition(): N_INDCS = -1 map_test, map_train = map_overlay.basic_setup([100], 50, label_name = "Jared") clf = ObjectClassifier() damage_labels = np.loadtxt('damagelabels50/Jared-3-3.csv', delimiter = ',').astype('int') building_labels = np.loadtxt('damagelabels50/all_buildings-3-3.csv', delimiter =',').astype('int') segs = map_train.segmentations[50].ravel() n_segs = int(np.max(segs))+1 all_labels = np.zeros(n_segs) #Nothing = Green all_labels[damage_labels] = 1 #Damage = Red all_labels[building_labels] = 2 #Building = Blue all_data, y = clf._get_X_y(map_train, 'Jared') clf.fit(map_train, label_name = 'Jared') names = clf.feat_names for i in range(50): new_damage = np.concatenate((all_data[damage_labels], all_data[building_labels[:i*10]]), axis = 0) print new_damage.shape all_histos(new_damage, all_data[building_labels], all_data[np.where(all_labels == 0)[0]], names, [17], prefix = "{} ".format(i*10)) plt.show()