帶有postgres和jupyter筆記本的Titanic數據集

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.

PostgreSQL是一個功能強大的開源對象關系數據庫系統,經過30多年的積極開發,在可靠性,功能強大和性能方面贏得了極高的聲譽。

Why use Postgres?

為什么要使用Postgres?

Postgres has a lot of capability. Built using an object-relational model, it supports complex structures and a breadth of built-in and user-defined data types. It provides extensive data capacity and is trusted for its data integrity.

Postgres具有很多功能。 它使用對象關系模型構建,支持復雜的結構以及內置和用戶定義的數據類型的范圍。 它提供了廣泛的數據容量,并因其數據完整性而受到信賴。

It comes with many features aimed to help developers build applications, administrators to protect data integrity and build fault-tolerant environments, and help you manage your data no matter how big or small the dataset.

它具有許多功能,旨在幫助開發人員構建應用程序,幫助管理員保護數據完整性和構建容錯環境,并幫助您管理數據(無論數據集大小)。

We will be using the famous Titanic dataset from Kaggle to predict whether the people aboard were likely to survive the sinkage of the world’s greatest ship or not.

我們將使用來自Kaggle的著名的《泰坦尼克號》數據集來預測船上的人們是否有可能幸免于世界上最偉大的船只的沉沒。

In the first step make sure the you have valid Postgres credentials, a created database with the data already imported. Check the Kaggle website to downloads the csv files: https://www.kaggle.com/c/titanic/data. The data should look something like this:

第一步,請確保您具有有效的Postgres憑據,即已導入數據的已創建數據庫。 檢查Kaggle網站以下載csv文件: https : //www.kaggle.com/c/titanic/data 。 數據應如下所示:

Image for post

We’ll first import the proper libraries. Make sure you pip install them. I’m using a local jupyter environment. Apart from the obvious ones, psycopg2 and sqlalchemy are crucial for creating a connection to postgres. Just pip install them as well. :)

我們將首先導入適當的庫。 確保您點安裝它們。 我正在使用本地jupyter環境。 除了顯而易見的以外,psycopg2和sqlalchemy對于創建與postgres的連接至關重要。 只需點安裝它們。 :)

Next, we’ll be using a create_engine form sqlalchemy. It’s too simple to use.

接下來,我們將使用sqlalchemy形式的create_engine。 使用起來太簡單了。

Image for post

Replace <enter yours> with your own credentials. The default port is 5432 and username is ‘postgres’. If the code prints ‘Connected to database’ you have succesfully made a connection to your postgres database.

用您自己的憑據替換<enter yours>。 默認端口為5432,用戶名為“ postgres”。 如果代碼顯示“已連接到數據庫”,則說明您已成功連接到Postgres數據庫。

Next, let’s convert the query result set to a pandas dataframe.

接下來,讓我們將查詢結果集轉換為pandas數據框。

Image for post
Image for post

As you can see the dataframe has 887 rows and 9 columns with the first being id.

如您所見,數據框具有887行和9列,第一個是id。

In the next section, let’s try to figure out if any data is directly associated with the survival rate. We’ll take if sex, passenger class and having a family has anything to do with their chance of surviving.

在下一節中,讓我們嘗試確定是否有任何數據與生存率直接相關。 我們將考慮性別,旅客階層和家庭是否與他們生存的機會有關。

Image for post

As you can see, 74% of women aboard survived and only 19% of men did. Passenger class also has an enormous affect. Having siblings or spouses is not correlated. Let’s take a look at a visual correlation between age and survival.

如您所見,船上74%的女性得以幸存,只有19%的男性得以幸存。 客運等級也有巨大影響。 有兄弟姐妹或配偶不相關。 讓我們看一下年齡和生存率之間的視覺關聯。

Image for post

There is a significant ammount of toddlers that died in the accident. Most of passengers were middle-aged.

事故中有大量嬰兒喪生。 大多數乘客是中年人。

Since computers like numbers more than words I have converted sex into a binary classifier.

由于計算機比數字更喜歡數字,因此我已將性別轉換為二進制分類器。

Image for post

The data still remains the same.

數據仍然保持不變。

Finally, let’s dive into preprocessing for classification.

最后,讓我們深入進行分類預處理。

Image for post

I used sklearn’s train_test_split to create a training and test dataset.

我使用sklearn的train_test_split創建了訓練和測試數據集。

We have to drop the ‘survived’ column in the train set otherwise the data serves no purpose.

我們必須在訓練集中刪除“幸存”列,否則數據沒有任何作用。

Image for post

Finally, we fit the training data and got the accuracy of 74.33 which is not great. But not bad either. Let’s save the predicted values to a csv file called ‘submission.csv’. It will only have two values: passengerId and a boolean indicating survival.

最后,我們擬合了訓練數據并獲得了74.33的準確度,這并不是一個很好的結果。 但也不錯。 讓我們將預測值保存到一個名為“ submission.csv”的csv文件中。 它只有兩個值:passengerId和一個表示生存期的布爾值。

Summary:

摘要:

  • use postgres as transactional database management system for data pipelines

    使用postgres作為數據管道的事務數據庫管理系統
  • have fun manipulating data with pandas and visualisation libraries such as matplotlib and seaborn.

    使用熊貓和可視化庫(例如matplotlib和seaborn)來處理數據很有趣。
  • make predictions using the machine learning algorithms provided to you by scikit-learn and tensorflow.

    使用scikit-learn和tensorflow提供給您的機器學習算法進行預測。

Thanks ;)

謝謝 ;)

翻譯自: https://medium.com/@cvetko.tim/titanic-dataset-with-postgres-and-jupyter-notebook-69073c4a67e6

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389387.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389387.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389387.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Django學習--數據庫同步操作技巧

同步數據庫&#xff1a;使用上述兩條命令同步數據庫1.認識migrations目錄&#xff1a;migrations目錄作用&#xff1a;用來存放通過makemigrations命令生成的數據庫腳本&#xff0c;里面的生成的腳本不要輕易修改。要正常的使用數據庫同步的功能&#xff0c;app目錄下必須要有m…

《20天吃透Pytorch》Pytorch自動微分機制學習

自動微分機制 Pytorch一般通過反向傳播 backward 方法 實現這種求梯度計算。該方法求得的梯度將存在對應自變量張量的grad屬性下。 除此之外&#xff0c;也能夠調用torch.autograd.grad 函數來實現求梯度計算。 這就是Pytorch的自動微分機制。 一&#xff0c;利用backward方…

React 新 Context API 在前端狀態管理的實踐

2019獨角獸企業重金招聘Python工程師標準>>> 本文轉載至&#xff1a;今日頭條技術博客 眾所周知&#xff0c;React的單向數據流模式導致狀態只能一級一級的由父組件傳遞到子組件&#xff0c;在大中型應用中較為繁瑣不好管理&#xff0c;通常我們需要使用Redux來幫助…

機器學習模型 非線性模型_機器學習模型說明

機器學習模型 非線性模型A Case Study of Shap and pdp using Diabetes dataset使用糖尿病數據集對Shap和pdp進行案例研究 Explaining Machine Learning Models has always been a difficult concept to comprehend in which model results and performance stay black box (h…

5分鐘內完成胸部CT掃描機器學習

This post provides an overview of chest CT scan machine learning organized by clinical goal, data representation, task, and model.這篇文章按臨床目標&#xff0c;數據表示&#xff0c;任務和模型組織了胸部CT掃描機器學習的概述。 A chest CT scan is a grayscale 3…

Pytorch高階API示范——線性回歸模型

本文與《20天吃透Pytorch》有所不同&#xff0c;《20天吃透Pytorch》中是繼承之前的模型進行擬合&#xff0c;本文是單獨建立網絡進行擬合。 代碼實現&#xff1a; import torch import numpy as np import matplotlib.pyplot as plt import pandas as pd from torch import …

vue 上傳圖片限制大小和格式

<div class"upload-box clear"><span class"fl">上傳圖片</span><div class"artistDet-logo-box fl"><el-upload :action"this.baseServerUrl/fileUpload/uploadPic?filepathartwork" list-type"pic…

作業要求 20181023-3 每周例行報告

本周要求參見&#xff1a;https://edu.cnblogs.com/campus/nenu/2018fall/homework/2282 1、本周PSP 總計&#xff1a;927min 2、本周進度條 代碼行數 博文字數 用到的軟件工程知識點 217 757 PSP、版本控制 3、累積進度圖 &#xff08;1&#xff09;累積代碼折線圖 &…

算命數據_未來的數據科學家或算命精神向導

算命數據Real Estate Sale Prices, Regression, and Classification: Data Science is the Future of Fortune Telling房地產銷售價格&#xff0c;回歸和分類&#xff1a;數據科學是算命的未來 As we all know, I am unusually blessed with totally-real psychic abilities.眾…

openai-gpt_為什么到處都看到GPT-3?

openai-gptDisclaimer: My opinions are informed by my experience maintaining Cortex, an open source platform for machine learning engineering.免責聲明&#xff1a;我的看法是基于我維護 機器學習工程的開源平臺 Cortex的 經驗而 得出 的。 If you frequent any part…

Pytorch高階API示范——DNN二分類模型

代碼部分&#xff1a; import numpy as np import pandas as pd from matplotlib import pyplot as plt import torch from torch import nn import torch.nn.functional as F from torch.utils.data import Dataset,DataLoader,TensorDataset""" 準備數據 &qu…

OO期末總結

$0 寫在前面 善始善終&#xff0c;臨近期末&#xff0c;為一學期的收獲和努力畫一個圓滿的句號。 $1 測試與正確性論證的比較 $1-0 什么是測試&#xff1f; 測試是使用人工操作或者程序自動運行的方式來檢驗它是否滿足規定的需求或弄清預期結果與實際結果之間的差別的過程。 它…

puppet puppet模塊、file模塊

轉載&#xff1a;http://blog.51cto.com/ywzhou/1577356 作用&#xff1a;通過puppet模塊自動控制客戶端的puppet配置&#xff0c;當需要修改客戶端的puppet配置時不用在客戶端一一設置。 1、服務端配置puppet模塊 &#xff08;1&#xff09;模塊清單 [rootpuppet ~]# tree /et…

數據可視化及其重要性:Python

Data visualization is an important skill to possess for anyone trying to extract and communicate insights from data. In the field of machine learning, visualization plays a key role throughout the entire process of analysis.對于任何試圖從數據中提取和傳達見…

熊貓數據集_熊貓邁向數據科學的第三部分

熊貓數據集Data is almost never perfect. Data Scientist spend more time in preprocessing dataset than in creating a model. Often we come across scenario where we find some missing data in data set. Such data points are represented with NaN or Not a Number i…

Pytorch有關張量的各種操作

一&#xff0c;創建張量 1. 生成float格式的張量: a torch.tensor([1,2,3],dtype torch.float)2. 生成從1到10&#xff0c;間隔是2的張量: b torch.arange(1,10,step 2)3. 隨機生成從0.0到6.28的10個張量 注意&#xff1a; (1).生成的10個張量中包含0.0和6.28&#xff…

mongodb安裝失敗與解決方法(附安裝教程)

安裝mongodb遇到的一些坑 浪費了大量的時間 在此記錄一下 主要是電腦系統win10企業版自帶的防火墻 當然還有其他的一些坑 一般的問題在第6步驟都可以解決&#xff0c;本教程的安裝步驟不夠詳細的話 請自行百度或谷歌 安裝教程很多 我是基于node.js使用mongodb結合Robo 3T數…

【洛谷算法題】P1046-[NOIP2005 普及組] 陶陶摘蘋果【入門2分支結構】Java題解

&#x1f468;?&#x1f4bb;博客主頁&#xff1a;花無缺 歡迎 點贊&#x1f44d; 收藏? 留言&#x1f4dd; 加關注?! 本文由 花無缺 原創 收錄于專欄 【洛谷算法題】 文章目錄 【洛谷算法題】P1046-[NOIP2005 普及組] 陶陶摘蘋果【入門2分支結構】Java題解&#x1f30f;題目…

web性能優化(理論)

什么是性能優化&#xff1f; 就是讓用戶感覺你的網站加載速度很快。。。哈哈哈。 分析 讓我們來分析一下從用戶按下回車鍵到網站呈現出來經歷了哪些和前端相關的過程。 緩存 首先看本地是否有緩存&#xff0c;如果有符合使用條件的緩存則不需要向服務器發送請求了。DNS查詢建立…

python多項式回歸_如何在Python中實現多項式回歸模型

python多項式回歸Let’s start with an example. We want to predict the Price of a home based on the Area and Age. The function below was used to generate Home Prices and we can pretend this is “real-world data” and our “job” is to create a model which wi…