Skip to content

Instantly share code, notes, and snippets.

@wibowotangara
Created January 24, 2024 06:12
Show Gist options
  • Save wibowotangara/db7f17c6d400157a416b70c34bfb05ce to your computer and use it in GitHub Desktop.
Save wibowotangara/db7f17c6d400157a416b70c34bfb05ce to your computer and use it in GitHub Desktop.
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
model = RandomForestClassifier()
k_fold = KFold(n_splits=5, shuffle=True, random_state=42)
scores = cross_val_score(model, X_train, Y_train, cv=k_fold, scoring='accuracy')
for i, score in enumerate(scores, 1):
print(f'Fold {i}: Accuracy = {score:.4f}')
print(f'Mean Accuracy: {np.mean(scores):.4f}')
print(f'Standard Deviation: {np.std(scores):.4f}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment