带有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.mzph.cn/news/389387.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Django学习--数据库同步操作技巧

同步数据库&#xff1a;使用上述两条命令同步数据库1.认识migrations目录&#xff1a;migrations目录作用&#xff1a;用来存放通过makemigrations命令生成的数据库脚本&#xff0c;里面的生成的脚本不要轻易修改。要正常的使用数据库同步的功能&#xff0c;app目录下必须要有m…

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 …

作业要求 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; 测试是使用人工操作或者程序自动运行的方式来检验它是否满足规定的需求或弄清预期结果与实际结果之间的差别的过程。 它…

数据可视化及其重要性: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.对于任何试图从数据中提取和传达见…

【洛谷算法题】P1046-[NOIP2005 普及组] 陶陶摘苹果【入门2分支结构】Java题解

&#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P1046-[NOIP2005 普及组] 陶陶摘苹果【入门2分支结构】Java题解&#x1f30f;题目…

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…

充分利用UC berkeleys数据科学专业

By Kyra Wong and Kendall Kikkawa黄凯拉(Kyra Wong)和菊川健多 ( Kendall Kikkawa) 什么是“数据科学”&#xff1f; (What is ‘Data Science’?) Data collection, an important aspect of “data science”, is not a new idea. Before the tech boom, every industry al…

02-web框架

1 while True:print(server is waiting...)conn, addr server.accept()data conn.recv(1024) print(data:, data)# 1.得到请求的url路径# ------------dict/obj d["path":"/login"]# d.get(”path“)# 按着http请求协议解析数据# 专注于web业…

ai驱动数据安全治理_AI驱动的Web数据收集解决方案的新起点

ai驱动数据安全治理Data gathering consists of many time-consuming and complex activities. These include proxy management, data parsing, infrastructure management, overcoming fingerprinting anti-measures, rendering JavaScript-heavy websites at scale, and muc…

铁拳nat映射_铁拳如何重塑我的数据可视化设计流程

铁拳nat映射It’s been a full year since I’ve become an independent data visualization designer. When I first started, projects that came to me didn’t relate to my interests or skills. Over the past eight months, it’s become very clear to me that when cl…

DengAI —如何应对数据科学竞赛? (EDA)

了解机器学习 (Understanding ML) This article is based on my entry into DengAI competition on the DrivenData platform. I’ve managed to score within 0.2% (14/9069 as on 02 Jun 2020). Some of the ideas presented here are strictly designed for competitions li…

java.net.SocketException: Software caused connection abort: socket write erro

场景&#xff1a;接口测试 编辑器&#xff1a;eclipse 版本&#xff1a;Version: 2018-09 (4.9.0) testng版本&#xff1a;TestNG version 6.14.0 执行testng.xml时报错信息&#xff1a; 出现此报错原因之一&#xff1a;网上有人说是testng版本与eclipse版本不一致造成的&#…

使用K-Means对美因河畔法兰克福的社区进行聚类

介绍 (Introduction) This blog post summarizes the results of the Capstone Project in the IBM Data Science Specialization on Coursera. Within the project, the districts of Frankfurt am Main in Germany shall be clustered according to their venue data using t…