带有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…

《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…