[{'role': 'system', 'content': "You are an expert in machine learning and your task is to classify code snippets into one of the following categories: ['helper_functions', 'load_data', 'data_exploration', 'data_preprocessing', 'evaluation', 'modelling', 'prediction', 'result_visualization', 'save_results', 'comment_only']."}, {'role': 'user', 'content': 'Identify the single most appropriate category to which the provided code belongs. Provide your response as a single category label without any additional information, commentary, or personal opinions.\\nPython Code:def no_norm(matrix):\nreturn matrix\ndef max_norm(matrix):\nnormed_matrix = matrix / np.max(matrix)\nreturn normed_matrix\ndef binar_norm(matrix):\nbin_matrix = matrix.copy()\nbin_matrix[bin_matrix > 0] = 1\nreturn bin_matrix\ndef mean_norm(matrix):\nnormed_matrix = matrix / np.mean(matrix)\nreturn normed_matrix\ndef double_norm(function, matrix1, matrix2):\nreturn function(matrix1), function(matrix2)\ndef bag_of_edges(X, SPL=None, symmetric = True, return_df = False, offset = 1):\nsize = X.shape[1]\nif symmetric:\nindices = np.triu_indices(size, k = offset)\nelse:\ngrid = np.indices(X.shape[1:])\nindices = (grid[0].reshape(-1), grid[1].reshape(-1))\nif len(X.shape) == 3:\nfeaturized_X = X[:, indices[0], indices[1]]\nelif len(X.shape) == 2:\nfeaturized_X = X[indices[0], indices[1]]\nelse:\nraise ValueError(\'Provide array of valid shape: (number_of_matrices, size, size).\')\nif return_df:\ncol_names = [\'edge_\' + str(i) + \'_\' + str(j) for i,j in zip(indices[0], indices[1])]\nfeaturized_X = pd.DataFrame(featurized_X, columns=col_names)\nreturn featurized_X\ndef degrees(X, return_df = False):\nif len(X.shape) == 3:\nfeaturized_X = np.sum(X, axis=1)\nshape = (X.shape[0], X.shape[1])\nelif len(X.shape) == 2:\nfeaturized_X = np.sum(X, axis=1)\nshape = (1, X.shape[1])\nelse:\nraise ValueError(\'Provide array of valid shape: (number_of_matrices, size, size). \')\nif return_df:\ncol_names = [\'degree_\' + str(i) for i in range(X.shape[1])]\nfeaturized_X = pd.DataFrame(featurized_X.reshape(shape), columns=col_names)\nreturn featurized_X\ndef closeness_centrality(X):\nn_nodes = X.shape[0]\nA_inv = 1./X\nSPL = scipy.sparse.csgraph.dijkstra(A_inv, directed=False,\nunweighted=False)\nsum_distances_vector = np.sum(SPL, 1)\ncl_c = float(n_nodes - 1)/sum_distances_vector\nfeaturized_X = cl_c\nreturn featurized_X\ndef betweenness_centrality(X):\nn_nodes = X.shape[0]\nA_inv = 1./X\nG_inv = ig.Graph.Weighted_Adjacency(list(A_inv), mode="UNDIRECTED", attr="weight", loops=False)\nbtw = np.array(G_inv.betweenness(weights=\'weight\', directed=False))*2./((n_nodes-1)*(n_nodes-2))\nreturn btw\ndef eigenvector_centrality(X):\nG = ig.Graph.Weighted_Adjacency(list(X), mode="UNDIRECTED",\nattr="weight", loops=False)\neigc = G.eigenvector_centrality(weights=\'weight\', directed=False)\nreturn np.array(eigc)\ndef pagerank(X):\nG = ig.Graph.Weighted_Adjacency(list(X), mode="DIRECTED", attr="weight", loops=False)\nreturn np.array(G.pagerank(weights="weight"))\ndef efficiency(X):\nA_inv = 1./X\nSPL = scipy.sparse.csgraph.dijkstra(A_inv, directed=False, unweighted=False)\ninv_SPL_with_inf = 1./SPL\ninv_SPL_with_nan = inv_SPL_with_inf.copy()\ninv_SPL_with_nan[np.isinf(inv_SPL_with_inf)]=np.nan\nefs = np.nanmean(inv_SPL_with_nan, 1)\nreturn efs\ndef clustering_coefficient(X):\nGnx = nx.from_numpy_matrix(X)\nclst_geommean = list(nx.clustering(Gnx, weight=\'weight\').values())\nclst_geommean\nreturn np.array(clst_geommean)\ndef triangles(X):\nclust = clustering_coefficient(X)\nG = ig.Graph.Weighted_Adjacency(list(X), mode="UNDIRECTED",\nattr="weight", loops=False)\nnon_weighted_degrees = np.array(G.degree())\nnon_weighted_deg_by_deg_minus_one = np.multiply(non_weighted_degrees,\n(non_weighted_degrees - 1))\ntr = np.multiply(np.array(clust),\nnp.array(non_weighted_deg_by_deg_minus_one, dtype = float))/2.\nreturn tr\npairs_data = pd.read_csv(\'data/parkinson_pairs_data.csv\', index_col = None)\ndef generate_even_sample(data, n = 1000, seed = 0):\nsample_of_1 = data[data.are_same == 1].sample(n=n, random_state=seed)\nsample_of_0 = data[data.are_same == 0].sample(n=n, random_state=seed)\nreturn pd.concat([sample_of_1, sample_of_0], axis=0)\nclass DataTransformer(BaseEstimator, TransformerMixin):\ndef __init__(self, target, copy=True):\nself.target = target\ndef fit(self, pairs_data, y=None):\nreturn self\ndef transform(self, pairs_data, data_dir=\'data/parkinson/\'):\nmatrices = {}\nif self.target != \'All\':\npairs_data = pairs_data[(pairs_data.subject1_target == self.target) & (pairs_data.subject2_target == self.target)]\nfile_ids = np.unique(pairs_data[[\'subject1_id\', \'subject2_id\']])\nfor file_id in file_ids:\nfor file in os.listdir(data_dir+file_id):\nif \'FULL\' in file:\nprint(data_dir + file_id + \'/\' + file)\nmatrix = np.loadtxt(data_dir + file_id + \'/\' + file)\nmatrix = np.delete(matrix, [3,38], axis = 1)\nmatrix = np.delete(matrix, [3,38], axis = 0)\nnp.fill_diagonal(matrix, 0)\nmatrices[file_id] = matrix\npairs_data = generate_even_sample(pairs_data, n = int(pairs_data.are_same.sum()))\nreturn {\'pairs_data\': pairs_data,\n\'matrices\': matrices}\nclass MatrixNormalizer(BaseEstimator, TransformerMixin):\ndef __init__(self, norm, copy=True):\nself.norm    = norm\nself.copy    = copy\ndef fit(self, X, y=None):\nreturn self\ndef transform(self, X):\nX_transformed = {}\nfor key in X[\'matrices\'].keys():\nX_transformed[key] = self.norm(X[\'matrices\'][key])\nreturn {\'pairs_data\': X[\'pairs_data\'],\n\'matrices\': X_transformed}\nclass MatrixFeaturizer(BaseEstimator, TransformerMixin):\ndef __init__(self, features, copy=True):\nself.features = features\nself.copy = copy\ndef fit(self, X, y=None):\nreturn self\ndef transform(self, X):\ncur_features = {}\nfor key in X[\'matrices\'].keys():\ncur_features[key] = self.features[0](X[\'matrices\'][key])\nfor feature_func in self.features[1:]:\ncur_features[key] = np.append(cur_features[key], feature_func(X[\'matrices\'][key]))\nreturn {\'pairs_data\': X[\'pairs_data\'],\n\'features\': cur_features}\ndef gen_dist(p): return lambda x,y: minkowski(x.reshape(-1),y.reshape(-1),p)\nfunc_list = [chebyshev] + [gen_dist(i) for i in [1, 2]]\nclass VectorFeaturizer(BaseEstimator, TransformerMixin):\ndef __init__(self, func_list):\nself.func_list = func_list\ndef fit(self, X, y=None):\nreturn self\ndef transform(self, X):\nvectors1 = X[\'pairs_data\'].subject1_id.apply(lambda x: X[\'features\'][x])\nvectors2 = X[\'pairs_data\'].subject2_id.apply(lambda x: X[\'features\'][x])\nfeatures = []\nfor index in vectors1.index:\nfeats = []\nfor function in self.func_list:\nfeats.append(function(vectors1[index], vectors2[index]))\nfeatures.append(feats)\nreturn np.array(features)\nsys.path.append(os.path.abspath(\'../../Reskit/\'))\nfrom reskit.core import *\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.linear_model import SGDClassifier\nfrom sklearn.svm import SVC\nfrom sklearn.preprocessing import MinMaxScaler\nfrom sklearn.preprocessing import RobustScaler\nfrom sklearn.preprocessing import StandardScaler\nfrom xgboost import XGBClassifier\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.model_selection import GridSearchCV\ngrid_cv = StratifiedKFold(n_splits=10, shuffle=True,  random_state=0)\neval_cv = StratifiedShuffleSplit(\nn_splits = 100,\ntest_size = 0.2,\nrandom_state = 0 )\nsteps = [\n(\'norm\', [\n(\'-\', [\n(\'object\', MatrixNormalizer),\n(\'params\', [\n(\'param\', {\'norm\': no_norm}) ]) ]),\n(\'max\', [\n(\'object\', MatrixNormalizer),\n(\'params\', [\n(\'param\', {\'norm\': max_norm}) ]) ]),\n(\'binar\', [\n(\'object\', MatrixNormalizer),\n(\'params\', [\n(\'param\', {\'norm\': binar_norm}) ]) ]),\n(\'mean\', [\n(\'object\', MatrixNormalizer),\n(\'params\', [\n(\'param\', {\'norm\': mean_norm}) ]) ]) ]),\n(\'base_features\', [\n(\'bag_of_edges\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [bag_of_edges]}) ]) ]),\n(\'degrees\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [degrees]}) ]) ]),\n(\'closeness_centrality\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [closeness_centrality]}) ]) ]),\n(\'betweenness_centrality\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [betweenness_centrality]}) ]) ]),\n(\'eigenvector_centrality\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [eigenvector_centrality]}) ]) ]),\n(\'pagerank\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [pagerank]}) ]) ]),\n(\'efficiency\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [efficiency]}) ]) ]),\n(\'clustering_coefficient\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [clustering_coefficient]}) ]) ]),\n(\'triangles\', [\n(\'object\', MatrixFeaturizer),\n(\'params\', [\n(\'param\', {\'features\': [triangles]}) ]) ]) ]),\n(\'pairwise_features\', [\n(\'l1_l2_linf\', [\n(\'object\', VectorFeaturizer),\n(\'params\', [\n(\'param\', {\'func_list\': func_list}) ]) ]) ]),\n(\'scaler\', [\n(\'standard\', [\n(\'object\', StandardScaler),\n(\'params\', [\n(\'None\', {}) ]) ]) ]),\n(\'classifier\', [\n(\'grid\', [\n(\'object\', GridSearchCV),\n(\'params\', [\n(\'LR\', {\n\'estimator\': LogisticRegression(),\n\'cv\': grid_cv,\n\'n_jobs\': -1,\n\'param_grid\': {\n\'penalty\': [\'l1\', \'l2\'],\n\'C\':[0.05*i for i in range(1,20)],\n\'fit_intercept\': [True],\n\'max_iter\': [50, 100],\n\'random_state\': [0],\n\'solver\': [\'liblinear\'],\n\'n_jobs\': [1] } }),\n(\'RF\', {\n\'estimator\': RandomForestClassifier(),\n\'cv\': grid_cv,\n\'n_jobs\': -1,\n\'param_grid\': {\n\'n_estimators\': [100],\n\'criterion\': [\'gini\', \'entropy\'],\n\'max_depth\': [2, 3, 3, 5, 7],\n\'min_samples_split\': [2],\n\'min_samples_leaf\': [1],\n\'min_weight_fraction_leaf\': [0.0],\n\'max_features\': [0.5, 1],\n\'max_leaf_nodes\': [None],\n\'bootstrap\': [True],\n\'oob_score\': [False],\n\'n_jobs\':[1],\n\'random_state\': [0],\n\'verbose\': [0],\n\'warm_start\': [False],\n\'class_weight\': [None] } }),\n(\'GBT\', {\n\'estimator\': XGBClassifier(),\n\'cv\': grid_cv,\n\'n_jobs\': -1,\n\'param_grid\': {\n\'max_depth\': [2,3,4,5],\n\'learning_rate\': [0.01, 0.05, 0.1, 0.2, 0.5],\n\'n_estimators\': [100],\n\'silent\': [True],\n\'objective\': [\'binary:logistic\'],\n\'nthread\': [1],\n\'gamma\': [0],\n\'subsample\': [1.0, 0.9, 0.8, 0.7, 0.6],\n\'colsample_bytree\': [1.0],\n\'base_score\': [0.5],\n\'seed\': [0] } }),\n(\'SGD\', {\n\'estimator\': SGDClassifier(),\n\'cv\': grid_cv,\n\'n_jobs\': -1,\n\'param_grid\': {\n\'loss\':[\'hinge\', \'log\', \'modified_huber\'],\n\'penalty\': [\'elasticnet\'],\n\'alpha\': [0.001, 0.01, 0.1, 0.5, 1.0],\n\'l1_ratio\': [0, 0.2, 0.4, 0.6, 0.8, 1.0],\n\'fit_intercept\': [True],\n\'n_iter\': [50, 100, 200],\n\'shuffle\': [True],\n\'verbose\':[0],\n\'epsilon\': [0.1],\n\'n_jobs\': [-1],\n\'random_state\':[0],\n\'learning_rate\': [\'optimal\'],\n\'eta0\': [0.0],\n\'power_t\': [0.5],\n\'class_weight\': [None] } }),\n(\'SVC\', {\n\'estimator\': SVC(),\n\'cv\': grid_cv,\n\'n_jobs\': -1,\n\'param_grid\': {\n\'C\': [0.05*i for i in range(1,11)],\n\'kernel\': [\'linear\', \'poly\', \'rbf\', \'sigmoid\'],\n\'degree\': list(range(2,5)),\n\'gamma\': [0.01, 0.001, 0.05, 0.1, 0.2],\n\'max_iter\': [50, 100],\n\'random_state\': [0],\n\'shrinking\': [True] } }) ]) ]) ]) ]\nscoring = [\'accuracy\', \'roc_auc\']\ntargets = [\'All\', \'PD\', \'Control\']\nsteps = Steps(steps)\ncfg = Config(   steps = steps,\neval_cv = eval_cv,\nscoring = scoring   )\noutput_folder = \'PPMI_pairwise_results/\''}, {'role': 'assistant', 'content': 'data_preprocessing'}]