gpt-4-0314· openai
Suzhen/CodeChat
Here is the code below for testing 4 different models oon 4 different features( obtained…
- User
Here is the code below for testing 4 different models oon 4 different features( obtained from different correlations)
measures = ['correlation', 'partial correlation', 'tangent'] predictors = [ # ('svc_l2', LinearSVC(C=1)), # ('svc_l1', LinearSVC(C=1, penalty='l1', dual=False)), ('svc', SVC()), ('ridge_classifier', RidgeClassifier()), ('xgboost', XGBClassifier()), ('gradient boosting', GradientBoostingClassifier(learning_rate = 0.01)) ] cv = 4 for measure in measures: conn_est = ConnectivityMeasure(kind=measure) conn_matrices = conn_est.fit_transform(abide.rois_cc200) X = sym_matrix_to_vec(conn_matrices) for name, predictor in predictors: print(measure, name, np.mean(cross_val_score(predictor, X, y-1, cv=cv)))modify it to use cross_validate to also calculate f1 score, auc along with accuracy
- Assistant
You can use the
cross_validatefunction fromsklearn.model_selectionand pass the additional scoring metrics as a list to thescoringparameter. In this case, we will add 'f1_macro', 'roc_auc' (AUC for binary classification) and 'accuracy'. Here's the modified code:from sklearn.model_selection import cross_validate measures = ['correlation', 'partial correlation', 'tangent'] predictors = [ # ('svc_l2', LinearSVC(C=1)), # ('svc_l1', LinearSVC(C=1, penalty='l1', dual=False)), ('svc', SVC()), ('ridge_classifier', RidgeClassifier()), ('xgboost', XGBClassifier()), ('gradient boosting', GradientBoostingClassifier(learning_rate = 0.01)) ] cv = 4 scoring_metrics = ['f1_macro', 'roc_auc', 'accuracy'] for measure in measures: conn_est = ConnectivityMeasure(kind=measure) conn_matrices = conn_est.fit_transform(abide.rois_cc200) X = sym_matrix_to_vec(conn_matrices) for name, predictor in predictors: scores = cross_validate(predictor, X, y-1, cv=cv, scoring=scoring_metrics) f1_score = np.mean(scores['test_f1_macro']) auc = np.mean(scores['test_roc_auc']) accuracy = np.mean(scores['test_accuracy']) print(measure, name, f1_score, auc, accuracy)