-
-
Save swkm/46b3eafd5945bef545c3d644d3304632 to your computer and use it in GitHub Desktop.
Titanicデータの確認
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": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# ライブラリのインポート\n", | |
"import numpy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# titanicデータを読み込む\n", | |
"titanic = numpy.loadtxt('titanic.dat.txt', dtype='i8')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"2201\n" | |
] | |
} | |
], | |
"source": [ | |
"# 人数を数える\n", | |
"print(len(titanic))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# 10人を抜き出す\n", | |
"numpy.random.seed(64)\n", | |
"titanic_10keys = numpy.random.choice(len(titanic), 10, replace=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[1639 128 569 955 1136 394 1260 1325 429 1411]\n" | |
] | |
} | |
], | |
"source": [ | |
"# 抜き出した10人の番号の確認\n", | |
"print(titanic_10keys)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ID,Class(等級)\n", | |
"0,0\n", | |
"1,1\n", | |
"2,2\n", | |
"3,3\n", | |
"4,3\n", | |
"5,2\n", | |
"6,3\n", | |
"7,0\n", | |
"8,2\n", | |
"9,0\n" | |
] | |
} | |
], | |
"source": [ | |
"# 1変数データの表示\n", | |
"# 変数1: Class(乗船していた座席の等級)\n", | |
"print('ID,Class(等級)')\n", | |
"for (i, v) in enumerate(titanic[titanic_10keys, 0]):\n", | |
" print('{0},{1}'.format(i, v))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ID,Class(等級),Age(大まかな年齢)\n", | |
"0,0,1\n", | |
"1,1,1\n", | |
"2,2,1\n", | |
"3,3,1\n", | |
"4,3,1\n", | |
"5,2,1\n", | |
"6,3,0\n", | |
"7,0,1\n", | |
"8,2,1\n", | |
"9,0,1\n" | |
] | |
} | |
], | |
"source": [ | |
"# 2変数データの表示\n", | |
"# 変数1: Class(乗船していた座席の等級)\n", | |
"# 変数2: Age(大まかな年齢)\n", | |
"print('ID,Class(等級),Age(大まかな年齢)')\n", | |
"for (i, v) in enumerate(titanic[titanic_10keys, 0:2]):\n", | |
" print('{0},{1},{2}'.format(i, v[0], v[1]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ID,Class(等級),Age(大まかな年齢),Sex(性別)\n", | |
"0,0,1,1\n", | |
"1,1,1,1\n", | |
"2,2,1,0\n", | |
"3,3,1,1\n", | |
"4,3,1,0\n", | |
"5,2,1,1\n", | |
"6,3,0,1\n", | |
"7,0,1,1\n", | |
"8,2,1,1\n", | |
"9,0,1,1\n" | |
] | |
} | |
], | |
"source": [ | |
"# 3変数データの表示\n", | |
"# 変数1: Class(乗船していた座席の等級)\n", | |
"# 変数2: Age(大まかな年齢)\n", | |
"# 変数3: Sex(性別)\n", | |
"print('ID,Class(等級),Age(大まかな年齢),Sex(性別)')\n", | |
"for (i, v) in enumerate(titanic[titanic_10keys, 0:3]):\n", | |
" print('{0},{1},{2},{3}'.format(i, v[0], v[1], v[2]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ID,Class(等級),Age(大まかな年齢),Sex(性別),Survived(生存?)\n", | |
"0,0,1,1,0\n", | |
"1,1,1,1,0\n", | |
"2,2,1,0,1\n", | |
"3,3,1,1,0\n", | |
"4,3,1,0,1\n", | |
"5,2,1,1,0\n", | |
"6,3,0,1,0\n", | |
"7,0,1,1,1\n", | |
"8,2,1,1,0\n", | |
"9,0,1,1,1\n" | |
] | |
} | |
], | |
"source": [ | |
"# 4変数データの表示\n", | |
"# 変数1: Class(乗船していた座席の等級)\n", | |
"# 変数2: Age(大まかな年齢)\n", | |
"# 変数3: Sex(性別)\n", | |
"# 変数4: Survived(生存?)\n", | |
"print('ID,Class(等級),Age(大まかな年齢),Sex(性別),Survived(生存?)')\n", | |
"for (i, v) in enumerate(titanic[titanic_10keys, 0:4]):\n", | |
" print('{0},{1},{2},{3},{4}'.format(i, v[0], v[1], v[2], v[3]))" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [conda root]", | |
"language": "python", | |
"name": "conda-root-py" | |
}, | |
"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.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment