Skip to content

Instantly share code, notes, and snippets.

@triestpa
Created June 7, 2016 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triestpa/e326db921a5400428aeb33130fb3152b to your computer and use it in GitHub Desktop.
Save triestpa/e326db921a5400428aeb33130fb3152b to your computer and use it in GitHub Desktop.
Cross Validation Shuffle
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"shuffle_validator = cross_validation.ShuffleSplit(len(X), n_iter=20, test_size=0.2, random_state=0)\n",
"def test_classifier(clf):\n",
" scores = cross_validation.cross_val_score(clf, X, y, cv=shuffle_validator)\n",
" print(\"Accuracy: %0.4f (+/- %0.2f)\" % (scores.mean(), scores.std()))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.7742 (+/- 0.02)\n"
]
}
],
"source": [
"test_classifier(clf_dt)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment