mask = data[i].mask img_shape = mask.shape X = X[:, mask != 0] # Binarizing y to perform classification y = y.astype(np.bool) # Computing connectivity matrix A = grid_to_graph(n_x=img_shape[0], n_y=img_shape[1], n_z=img_shape[2], mask=mask) estimator = SVC(kernel='linear', C=1.) sc = SupervisedClusteringClassifier(estimator=estimator, n_jobs=1, n_iterations=150, cv=6, connectivity=A, verbose=0) cv = StratifiedKFold(y, 10) print "Computing score for the patient %d on 6" % i cv_scores = cross_val_score(sc, X, y, cv=cv, n_jobs=8, verbose=0) sc.fit(X, y) print ". Classification score for patient %d : %f" % (i, np.mean(cv_scores)) print ". Number of parcels : %d" % len(np.unique(sc.labels_)) scores.append(np.mean(cv_scores)) print "====================================" print "Average score for the whole dataset : %f", np.mean(scores)
# We compute the score for each patient for i in range(6): # Using the data corresponding to the patient X = data[i].data y = data[i].target mask = data[i].mask img_shape = mask.shape X = X[:, mask!=0] # Binarizing y to perform classification y = y.astype(np.bool) # Computing connectivity matrix A = grid_to_graph(n_x=img_shape[0], n_y=img_shape[1], n_z=img_shape[2], mask=mask) estimator = SVC(kernel='linear', C=1.) sc = SupervisedClusteringClassifier(estimator=estimator, n_jobs=1, n_iterations=150, cv=6, connectivity=A, verbose=0) cv = StratifiedKFold(y, 10) print "Computing score for the patient %d on 6" % i cv_scores = cross_val_score(sc, X, y, cv=cv, n_jobs=8, verbose=0) sc.fit(X, y) print ". Classification score for patient %d : %f" % (i, np.mean(cv_scores)) print ". Number of parcels : %d" % len(np.unique(sc.labels_)) scores.append(np.mean(cv_scores)) print "====================================" print "Average score for the whole dataset : %f", np.mean(scores)
data = data[0] X = data.data y = data.target mask = data.mask img_shape = mask.shape X = X[:, mask!=0] # Binarizing y y = y.astype(np.bool) # Connectivity matrix print "computing connectivity matrix" A = grid_to_graph(n_x=img_shape[0], n_y=img_shape[1], n_z=img_shape[2], mask=mask) estimator = SVC(kernel='linear', C=1.) sc = SupervisedClusteringClassifier(estimator=estimator, n_jobs=1, n_iterations=30, verbose=1, cv=5, connectivity=A) cv = StratifiedKFold(y, 5) print "computing score" cv_scores = cross_val_score(sc, X, y, cv=cv, n_jobs=8, verbose=1) sc.fit(X, y) print "classification score : ", np.mean(cv_scores) print "number of parcels : %d" % len(np.unique(sc.labels_)) coefs = np.zeros(img_shape) coefs[mask!=0] = sc.inverse_transform() pl.figure() vminmax = np.max(np.abs(coefs)) vmin = -vminmax vmax = +vminmax for i in range(8): pl.subplot(2, 4, i+1)