Nothing happens with my code: is it full online or does it rely on some local process that may not work on my computer ?
from sklearn.model_selection import validation_curve
max_depth = [1, 2, 5, 10, 20, 50, 100, 200, 5005]
train_scores, test_scores = validation_curve(
model, data, target, param_name="n_neighbors", param_range=max_depth,
cv=5, scoring="balanced_accuracy", n_jobs=2)
train_errors, test_errors = -train_scores, -test_scores
import matplotlib.pyplot as plt
plt.plot(max_depth, train_errors.mean(axis=1), label="Training error")
plt.plot(max_depth, test_errors.mean(axis=1), label="Testing error")
plt.legend()
plt.xlabel("Number of N_neighbors")
plt.ylabel("Balanced accuracy")
_ = plt.title("Effect on Train & Test score")
from sklearn.model_selection import cross_validate
cv_results = cross_validate(model, data, target, scoring="balanced_accuracy", cv=5)
cv_results = pd.DataFrame(cv_results)
cv_results
scores = cv_result["test_score"]
print("The balanced cross-validation accuracy is: "
f"{scores.mean():.3f} +/- {scores.std():.3f}")