def scorer_auc(y_true, y_pred, n_jobs=1): from sklearn.preprocessing import LabelBinarizer shape = y_pred.shape if len(shape) == 1: y_pred = y_pred[:, np.newaxis] le = LabelBinarizer() y_true = le.fit_transform(y_true) assert_array_equal(np.unique(y_true), [0, 1]) _, _, auc = fast_mannwhitneyu(y_pred[np.where(y_true == 0)[0], ...], y_pred[np.where(y_true == 1)[0], ...], n_jobs=n_jobs) return auc
def _default_analysis(X, y): # from sklearn.metrics import roc_auc_score from jr.stats import fast_mannwhitneyu # Binary contrast unique_y = np.unique(y) # if two condition, can only return contrast if len(y) == 2: y = np.where(y == unique_y[0], 1, -1) return np.mean(X * y[:, np.newaxis], axis=0) elif len(unique_y) == 2: # if two conditions but multiple trials, can return AUC # auc = np.zeros_like(X[0]) _, _, auc = fast_mannwhitneyu(X[y == unique_y[0], ...], X[y == unique_y[1], ...], n_jobs=1) # for ii, x in enumerate(X.T): # auc[ii] = roc_auc_score(y, np.copy(x)) return auc # Linear regression: elif len(unique_y) > 2: return repeated_spearman(X, y) else: raise RuntimeError('Please specify a function for this kind of data')
def _default_analysis(X, y): """Aux. function to nested_analysis""" # Binary contrast unique_y = np.unique(y) # if two condition, can only return contrast if len(y) == 2: y = np.where(y == unique_y[0], 1, -1) # Tile Y to across X dimension without allocating memory Y = tile_memory_free(y, X.shape[1:]) # FIXME tile memory free is now automatic in numpy # noqa return np.mean(X * Y, axis=0) elif len(unique_y) == 2: # if two conditions but multiple trials, can return AUC # auc = np.zeros_like(X[0]) _, _, auc = fast_mannwhitneyu(X[y == unique_y[0], ...], X[y == unique_y[1], ...], n_jobs=1) # for ii, x in enumerate(X.T): # auc[ii] = roc_auc_score(y, np.copy(x)) return auc # Linear regression: elif len(unique_y) > 2: return repeated_spearman(X, y) else: raise RuntimeError('Please specify a function for this kind of data')