Tweaked slicing indices to use single : instead of ::, which I find more readable. Tweaked Feature: Sex headers.

This commit is contained in:
Donne Martin 2015-03-20 12:54:20 -04:00
parent 5bc4d9bef4
commit a6153e5020

View File

@ -1,7 +1,7 @@
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:708d730926b0a00b95815375c1e8d7f632ca75b748195364102868ffc231fc0c" "signature": "sha256:46dbdb2807e4db85f0d0d4ed570394551bba3d8cbcdb541f8dd2115388981545"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
@ -26,7 +26,7 @@
"* Setup Imports and Variables\n", "* Setup Imports and Variables\n",
"* Explore the Data\n", "* Explore the Data\n",
"* Feature: Passenger Classes\n", "* Feature: Passenger Classes\n",
"* Feature: Sex (Gender)\n", "* Feature: Sex\n",
"* Feature: Embarked\n", "* Feature: Embarked\n",
"* Feature: Age\n", "* Feature: Age\n",
"* Feature: Family Size\n", "* Feature: Family Size\n",
@ -854,7 +854,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Feature: Sex (Gender)" "## Feature: Sex"
] ]
}, },
{ {
@ -2403,10 +2403,10 @@
"collapsed": false, "collapsed": false,
"input": [ "input": [
"# Training data (features), skip the first column 'Survived'\n", "# Training data (features), skip the first column 'Survived'\n",
"training_input = train_data[0::, 1::]\n", "training_input = train_data[:, 1:]\n",
"\n", "\n",
"# 'Survived' column values\n", "# 'Survived' column values\n",
"target_values = train_data[0::, 0]\n", "target_values = train_data[:, 0]\n",
"\n", "\n",
"# Fit the model to our training data\n", "# Fit the model to our training data\n",
"forest = forest.fit(training_input, target_values)" "forest = forest.fit(training_input, target_values)"
@ -2556,7 +2556,7 @@
"collapsed": false, "collapsed": false,
"input": [ "input": [
"# Test data (features), skip the first column 'PassengerId'\n", "# Test data (features), skip the first column 'PassengerId'\n",
"test_input = test_data[0::, 1::]\n", "test_input = test_data[:, 1:]\n",
"\n", "\n",
"# Predict the Survival values for the test data\n", "# Predict the Survival values for the test data\n",
"output = forest.predict(test_input)" "output = forest.predict(test_input)"
@ -2584,8 +2584,9 @@
"cell_type": "code", "cell_type": "code",
"collapsed": false, "collapsed": false,
"input": [ "input": [
"# Concatenate PassengerId and Survived predictions\n",
"result = np.c_[test_data[:, 0].astype(int), output.astype(int)]\n", "result = np.c_[test_data[:, 0].astype(int), output.astype(int)]\n",
"df_result = pd.DataFrame(result[:, 0:2], columns=['PassengerId', 'Survived'])\n", "df_result = pd.DataFrame(result[:, :], columns=['PassengerId', 'Survived'])\n",
"df_result.head(10)" "df_result.head(10)"
], ],
"language": "python", "language": "python",
@ -2659,7 +2660,7 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 43, "prompt_number": 61,
"text": [ "text": [
" PassengerId Survived\n", " PassengerId Survived\n",
"0 892 0\n", "0 892 0\n",
@ -2675,7 +2676,7 @@
] ]
} }
], ],
"prompt_number": 43 "prompt_number": 61
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",