Skip to content

Instantly share code, notes, and snippets.

@UmarZein
Created November 2, 2023 06:46
Show Gist options
  • Save UmarZein/38ef35b8fef7b648b1185cd16e3d57f7 to your computer and use it in GitHub Desktop.
Save UmarZein/38ef35b8fef7b648b1185cd16e3d57f7 to your computer and use it in GitHub Desktop.
Titanic prediction
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8baf8dff-6e38-442d-a36e-81b362e13a5f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cc84628b-29ab-4981-a365-1c3d7d766d0a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"train=pd.read_csv(\"train.csv\")\n",
"test=pd.read_csv(\"test.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7e5259dc-de29-4160-bd4d-ce650e6343a8",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(891, 12)\n",
"(418, 11)\n"
]
}
],
"source": [
"print(train.shape)\n",
"print(test.shape)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e835574a-e03f-4823-ba5d-d955553bed99",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"preds=[0]*418"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "eecea174-aa89-4425-b28d-0e4a6f14fc89",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\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>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>413</th>\n",
" <td>1305</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>414</th>\n",
" <td>1306</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>415</th>\n",
" <td>1307</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>416</th>\n",
" <td>1308</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>417</th>\n",
" <td>1309</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>418 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived\n",
"0 892 0\n",
"1 893 0\n",
"2 894 0\n",
"3 895 0\n",
"4 896 0\n",
".. ... ...\n",
"413 1305 0\n",
"414 1306 0\n",
"415 1307 0\n",
"416 1308 0\n",
"417 1309 0\n",
"\n",
"[418 rows x 2 columns]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"submission=pd.DataFrame({\n",
" 'PassengerId':test['PassengerId'],\n",
" 'Survived':preds\n",
"})\n",
"submission"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "70f8dc5e-93ed-41be-87d9-cbd6c1b15060",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"submission.to_csv(\"submission.csv\", index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment