Added Random Forest: Prepare for Kaggle Submission section.

This commit is contained in:
Donne Martin 2015-03-20 11:36:41 -04:00
parent 055cd52cd3
commit 01d65fd232

View File

@ -1,7 +1,7 @@
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:d50d4742eadf392ff4590f3569ff98f508db3dacbf33e0a31bd799b6bf4826ac" "signature": "sha256:fa67591f8fc6a26469c4ee41e525877faea06787800b22b7273babe8116a05c4"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
@ -29,6 +29,7 @@
"* Data Munging Summary\n", "* Data Munging Summary\n",
"* Random Forest: Training\n", "* Random Forest: Training\n",
"* Random Forest: Predicting\n", "* Random Forest: Predicting\n",
"* Random Forest: Prepare for Kaggle Submission\n",
"* Support Vector Machine: Training\n", "* Support Vector Machine: Training\n",
"* Support Vector Machine: Predicting" "* Support Vector Machine: Predicting"
] ]
@ -2552,6 +2553,135 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"prompt_number": 42 "prompt_number": 42
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random Forest: Prepare for Kaggle Submission"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a DataFrame by combining the index from the test data with the output of predictions:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"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.head(10)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>PassengerId</th>\n",
" <th>Survived</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td> 892</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td> 893</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td> 894</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td> 895</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td> 896</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td> 897</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td> 898</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td> 899</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td> 900</td>\n",
" <td> 1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td> 901</td>\n",
" <td> 0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 43,
"text": [
" PassengerId Survived\n",
"0 892 0\n",
"1 893 0\n",
"2 894 0\n",
"3 895 0\n",
"4 896 0\n",
"5 897 0\n",
"6 898 0\n",
"7 899 0\n",
"8 900 1\n",
"9 901 0"
]
}
],
"prompt_number": 43
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write the results to csv:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"df_result.to_csv('../data/titanic/results-rf.csv', index=False)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 44
} }
], ],
"metadata": {} "metadata": {}