I have two lists that I create outside my function. Inside this function, which is called multiple times, these two lists are extended. The problem is that after I finished my computations, the two lists are empty. Here's the code I'm using:
true_classes = []
predicted_classes = []
def report_cv(y_true, y_pred):
true_classes.extend(y_true)
predicted_classes.extend(y_pred)
return accuracy_score(y_true, y_pred)
cv = StratifiedKFold(n_splits=5, shuffle=True)
rfr = RandomForestClassifier(n_estimators=1000, class_weight='balanced',
n_jobs=-1)
scores = cross_val_score(rfr,
X=data_ml_clean.iloc[:, 2:],
y=data_ml_clean.vDili,
cv=cv, n_jobs=-1,
scoring=make_scorer(report_cv))
print(classification_report(true_classes, predicted_classes))
I do not understand why they are not treated like global variables. Adding global true_classes
inside the function does not help.