From a6153e50201f629ea778b1113e151fb6ea03df6e Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Fri, 20 Mar 2015 12:54:20 -0400 Subject: [PATCH] Tweaked slicing indices to use single : instead of ::, which I find more readable. Tweaked Feature: Sex headers. --- kaggle/titanic.ipynb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/kaggle/titanic.ipynb b/kaggle/titanic.ipynb index 3ae77e3..f78e43b 100644 --- a/kaggle/titanic.ipynb +++ b/kaggle/titanic.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:708d730926b0a00b95815375c1e8d7f632ca75b748195364102868ffc231fc0c" + "signature": "sha256:46dbdb2807e4db85f0d0d4ed570394551bba3d8cbcdb541f8dd2115388981545" }, "nbformat": 3, "nbformat_minor": 0, @@ -26,7 +26,7 @@ "* Setup Imports and Variables\n", "* Explore the Data\n", "* Feature: Passenger Classes\n", - "* Feature: Sex (Gender)\n", + "* Feature: Sex\n", "* Feature: Embarked\n", "* Feature: Age\n", "* Feature: Family Size\n", @@ -854,7 +854,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Feature: Sex (Gender)" + "## Feature: Sex" ] }, { @@ -2403,10 +2403,10 @@ "collapsed": false, "input": [ "# Training data (features), skip the first column 'Survived'\n", - "training_input = train_data[0::, 1::]\n", + "training_input = train_data[:, 1:]\n", "\n", "# 'Survived' column values\n", - "target_values = train_data[0::, 0]\n", + "target_values = train_data[:, 0]\n", "\n", "# Fit the model to our training data\n", "forest = forest.fit(training_input, target_values)" @@ -2556,7 +2556,7 @@ "collapsed": false, "input": [ "# Test data (features), skip the first column 'PassengerId'\n", - "test_input = test_data[0::, 1::]\n", + "test_input = test_data[:, 1:]\n", "\n", "# Predict the Survival values for the test data\n", "output = forest.predict(test_input)" @@ -2584,8 +2584,9 @@ "cell_type": "code", "collapsed": false, "input": [ + "# Concatenate PassengerId and Survived predictions\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)" ], "language": "python", @@ -2659,7 +2660,7 @@ ], "metadata": {}, "output_type": "pyout", - "prompt_number": 43, + "prompt_number": 61, "text": [ " PassengerId Survived\n", "0 892 0\n", @@ -2675,7 +2676,7 @@ ] } ], - "prompt_number": 43 + "prompt_number": 61 }, { "cell_type": "markdown",