Skip to content

Instantly share code, notes, and snippets.

@risenW
Created July 10, 2019 20:59
Show Gist options
  • Save risenW/d39732c645a70fddeb3f80c02993c6f8 to your computer and use it in GitHub Desktop.
Save risenW/d39732c645a70fddeb3f80c02993c6f8 to your computer and use it in GitHub Desktop.
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import KFold, cross_val_score
# def get_mae(pred, target):
# return mean_absolute_error(true, pred)
def cross_validate(model, nfolds, feats, targets):
score = -1 * (cross_val_score(model, feats, targets, cv=nfolds, scoring='neg_mean_absolute_error'))
return np.mean(score)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment