Created
June 25, 2018 05:21
-
-
Save a-y-khan/687730e39794faacd3f58762d04de1b6 to your computer and use it in GitHub Desktop.
sklearn_split
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(6, 2)" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import pandas as pd\n", | |
"\n", | |
"df = pd.DataFrame([[1,2],[3,4],[5,6],[7,8],[9,10],[11,12]], columns=['col1', 'col2'])\n", | |
"df.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" col1 col2\n", | |
"2 5 6\n", | |
"5 11 12\n", | |
"3 7 8\n", | |
"0 1 2\n", | |
" col1 col2\n", | |
"4 9 10\n", | |
"1 3 4\n" | |
] | |
} | |
], | |
"source": [ | |
"from sklearn.model_selection import train_test_split\n", | |
"\n", | |
"train, test = train_test_split(df, test_size=0.3)\n", | |
"train.shape, test.shape\n", | |
"print(train)\n", | |
"print(test)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" col1 col2\n", | |
"0 1 2\n", | |
"1 3 4\n", | |
"2 5 6\n", | |
"3 7 8\n", | |
" col1 col2\n", | |
"4 9 10\n", | |
"5 11 12\n" | |
] | |
} | |
], | |
"source": [ | |
"from sklearn.model_selection import train_test_split\n", | |
"\n", | |
"train, test = train_test_split(df, test_size=0.3, shuffle=False)\n", | |
"train.shape, test.shape\n", | |
"print(train)\n", | |
"print(test)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment