当前位置: 首页 > 编程日记 > 正文

[Machine Learning with Python] Data Visualization by Matplotlib Library

Before you can plot anything, you need to specify which backend Matplotlib should use. The simplest option is to use Jupyter’s magic command %matplotlib inline. This tells Jupyter to set up Matplotlib so it uses Jupyter’s own backend.

Scatter Plot

housing.plot(kind="scatter", x="longitude", y="latitude")

You can set the parameter alpha to study the density of points:

housing.plot(kind="scatter", x="longitude", y="latitude", alpha=0.1)

The plot can convey more information by setting different colors, sizes, shapes, etc. Here we will use a predefined color map (option cmap) called jet. As an example, we plot the house prices in different locations and let the radius of each circle represents the district’s population (option s), and the color represents the price (option c).

1 %matplotlib inline
2 import matplotlib.pyplot as plt
3 housing.plot(kind="scatter", x="longitude", y="latitude", alpha=0.4,
4     s=housing["population"]/100, label="population", figsize=(10,7),
5     c="median_house_value", cmap=plt.get_cmap("jet"), colorbar=True,
6     sharex=False)
7 plt.legend()
8 save_fig("housing_prices_scatterplot")

Note that the argument sharex=False fixes a display bug (the x-axis values and legend were not displayed). This is a temporary fix (see: https://github.com/pandas-dev/pandas/issues/10611).

Scatter Matrix

1 from pandas.plotting import scatter_matrix
2 
3 attributes = ["median_house_value", "median_income", "total_rooms",
4               "housing_median_age"]
5 scatter_matrix(housing[attributes], figsize=(12, 8))
6 save_fig("scatter_matrix_plot")

Histogram

Histogram is a useful method to study the distribution of numeric attributes.

1 %matplotlib inline
2 import matplotlib.pyplot as plt
3 housing.hist(bins=50, figsize=(20,15))
4 save_fig("attribute_histogram_plots")
5 plt.show()

For single attribute, you can use the following statement:

housing["median_income"].hist()

Correlation Plot

We can calculate the correlation coefficients between each pair of attributes using corr() method and look at the value by sort_values():

corr_matrix = housing.corr()
corr_matrix["median_house_value"].sort_values(ascending=False)

Also, we can use scatter_matrix function, which plots every numerical attribute against every other numerical attribute. The diagonal displays the histogram of each attribute.

from pandas.tools.plotting import scatter_matrix
attributes = ["median_house_value", "median_income", "total_rooms", "housing_median_age"]
scatter_matrix(housing[attributes], figsize=(12, 8))

转载于:https://www.cnblogs.com/sherrydatascience/p/10201343.html

相关文章:

贪心:Burst Balloons 最少次数完成射击气球

已知在一个平面上有一定数量的气球,平面可以看作一个坐标系,在平面的x轴的不同位 置安排弓箭手向y轴方向射箭,弓箭可以向y轴走无穷远;给定气球的宽度 xstart ≤ x ≤ xend,问至少需要多少弓箭手,将全部气球打爆? 例如…

linux服务器加固的命令,Linux 服务器安全加固

一、summary随着互联网的发展,隐私以及安全被大家看的越来越重视,越来越多的重要交易正在通过网络完成,与此同时数据被损坏、截取和修改的风险也在增加。优秀的系统应当拥有完善的安全措施,应当足够坚固、能够抵抗来自Internet的侵…

devexpress toolbar 填充整行宽度

设置 bar 的 optionsBar.UseWholeRow True 然后可设置Bar 中 Item的右对齐属性。转载于:https://www.cnblogs.com/perpetual/p/3756101.html

【java】staitc

一、static变量 二、static方法 三、static代码块 四、static类:只能是内部类

002.Docker安装部署

一 docker安装-CentOS系统1.1 docker自动安装脚本 1 rootdocker:~# wget -qO- https://get.docker.com/ | sh2 或——3 rootdocker:~# curl -sSL https://get.docker.com/ | sh 注意:若出现以下错误,可使用yum解决依赖——Delta RPMs disabled because /…

贪心:expedition 最优加油方法

已知一条公路上,有一个起点与一个终点,这之间有n个加油站;已知从这n个加 油站到终点的距离d与各个加油站可以加油的量l,起点位置至终点的距离L与起 始时刻油箱中汽油量P;假设使用1个单位的汽油即走1个单位的距离,油箱没有 上限&am…

UML for Java Programmers之dx实战

dx是一套简单的开发规则。它说白了就是迭代开发,在短周期内迭代处理”所有事情“,这里所指的”所有事情“包括需求、分析、设计、实现、测试和文档等等。 它的大概流程是这样:1. 初始探索 跟客户坐下来一起讨论系统到底是做什么的。在这个…

linux进程池动态维护,可直接商用的跨平台c,c++动态线程池,任务池stpool库

stpool是一个轻便高效的动态跨平台的线程池/任务池库.常规线程池的缺点:1. 总是启动时候就开启固定数目的线程,而不管系统的繁忙状态(这是很浪费系统资源的).2. 当任务繁重的时候,即使线程池被设计成可继续添加更多线程来服务,由于实时服务状…

hdu 1286( 欧拉函数 )

题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1286 数学题真的是有点吃不消了。。。 View Code 1 #include<iostream>2 #include<cmath>3 using namespace std;4 //可以快速求出欧拉函数的值 ( P为N的质因子 )5 //若(N%P0 && (N/P)%P0…

CF 1093 E. Intersection of Permutations

E. Intersection of Permutations 链接 题意&#xff1a; 给定两个序列&#xff0c;询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数&#xff0c;支持在第二个排列中交换两个数。 分析&#xff1a; 首先求出一个数组&#xff0c;c[i]&#xff0c;第二个排列的这…

s-seq 生成序列化数字

前言 seq命令用于产生从某个数到另外一个数之间的所有整数。 命令格式 seq [OPTION]... LAST seq [OPTION]... FIRST LAST seq [OPTION]... FIRST INCREMENT LAST 支持将指定范围的数字打印出来&#xff0c;按照指定的递增规律 -f, --format格式 使用printf 样式的浮点格式…

linux c++ 目录操作,C++文件及文件夹操作整理(代码示例)

一 文件1.1 使用C标准库中的IO库(fstream)读写文件#include #include using namespace std;int main(){char szData[200] "123456 test";fstream fFile;fFile.open("test.txt", ios::app | ios::out | ios::in);/****************将数据写入文件-begin***…

cocos2d-x 音效中断问题

做跑酷重吃金币播音效时&#xff0c;播放其它音效会使得音效所有中断&#xff0c;最后发现时音效上限的问题&#xff0c;2.2.3默认的似乎是5个音效&#xff0c;改动成50后问题解决。 在java中的org.cocos2dx.lib包下有一个Cocos2dxSound.java文件&#xff0c;改动里面 private …

AStyle - SourceInsight

SourceInsight : Options : Custom Commands Add 在弹出对话框写入 C/C Formatter "C:\AStyle\AStyle.exe" --styleansi -s2 --convert-tabs %f SourceInsight : Options : Key Assignments

c# blockingcollections

1 class Program2 {3 static BlockingCollection<int> cols new BlockingCollection<int>(2); //设置阻塞队列最大的容量&#xff1b;4 public static void Main(string[] args)5 {6 7 8 var t1…

递归/回溯:subsets求子集

前言 回溯法又称为试探法&#xff0c;但当探索到某一步时&#xff0c;发现原先选择达不到 目标&#xff0c;就退回一步重新选择&#xff0c;这种走不通就退回再走的技术为回溯法。 已知一组数(其中无重复元素)&#xff0c;求这组数可以组成的所有子集。 结果中不可有无重复的子…

C++ stl vector介绍

转自&#xff1a; STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector&#xff0c;如何恰当地使用它们的成员函数等操作。本文中还讨论了条件函数和函数指针在迭代算法中使用&#xff0c;如在remove_if()和for_each()中的使用。通过阅读这篇文章读者应该能够有效地使…

Linux服务器部署ssl证书教程,linux服务器在wdcp面板安装ssl证书教程

不少站长如今越来越在意站内数据传输的安全性&#xff0c;想着把自己建设的网站加密传输&#xff0c;许多站长都需要安装ssl证书&#xff0c;且很多站长都在找寻centos系统服务器linux服务器或者是wdcp面板怎么安装ssl证书&#xff0c;网上找了下没有完整步骤教程&#xff0c;所…

设备节点注册和操作方法连接

今天把驱动程序乱七八糟的看了一通&#xff0c;简单总结一下。 一个完整的驱动&#xff0c;需要提供如下的东西&#xff0c; 第一&#xff0c;用户空间/dev下面的设备节点。当然&#xff0c;如果该设备仅仅是内核的使用&#xff0c;例如I2C&#xff0c;则不需要在/dev下面建立…

maven(一 基本操作 命令 标签)

原来一直没有使用maven 小公司&#xff0c;只是听说过这个东西&#xff0c;我没事就喜欢 去学习一些新东西。maven学了几次&#xff0c;但是 没有用上 所以 最后还是忘记了&#xff0c;或者说不知道怎么使用maven&#xff0c;一年半以前公司 改革 &#xff0c;招了一个技术大牛…

递归/回溯:Subsets II求子集(有重复元素)

上一篇描述了针对数组中没有重复元素进行子集的求取过程递归/回溯&#xff1a;subsets求子集 但是当出现如下数组时&#xff1a; 例如: nums[] [2, 1, 2, 2] 结果为: [[], [1], [1,2], [1,2,2], [1,2,2,2], [2], [2,2], [2,2,2]] 注意: [2,1,2]与[1,2,2]是重复的集合,则不满足…

[WP]使用ApacheCordova开发HTML5-WindowsPhone应用程序

下载代码示例 这篇文章介绍 Apache 科尔多瓦&#xff0c;创建使用 HTML5 和 JavaScript&#xff0c;跨平台移动应用程序的框架&#xff0c;并显示了如何使用它为 Windows Phone 开发应用程序。 Windows Phone 和其本机开发平台允许您轻松地创建美丽地铁样式的应用程序。 最近诺…

linux 不能运行程序代码,linux-无法在Ubuntu上运行我自己的OpenGL 3程序

我正在尝试OpenGL 2.x和3.x教程.程序进行编译和链接,然后在看似无害的行上进行段错误处理,例如glGenBuffers (1, &m_buffer);我的main()以glewInit和glutInit开头. OpenGL 1程序可以编译并正常运行,这似乎是由glew包装的新功能.一个教程说,在尝试任何其他操作之前,我应该先…

Cocos2d-x Eclipse下程序运行产生错误Effect initCheck() returned -1

错误大致显示如下信息&#xff1a;04-14 07:39:18.325: E/AudioEffect(20584): set(): AudioFlinger could not create effect, status: -104-14 07:39:18.325: E/libOpenSLES(20584): Effect initCheck() returned -104-14 07:39:18.325: E/libOpenSLES(20584): Environmental…

H2:开源内存数据库引擎

本资源由 伯乐在线 - 刘立华 整理H2是一个开源的内存数据库。Java编写、快速、小巧&#xff08;1.5MB jar包&#xff09;还提供了Web控制台管理数据库内容。 主要功能 非常快速的数据库引擎。开源。Java编写。支持标准SQL、JDBC API。支持嵌入式模式、服务器模式和集群。强大的…

递归/回溯:Combination Sum II数组之和

问题如下&#xff1a; 已知一组数(其中有重复元素)&#xff0c;求这组数可以组成的所有子集中&#xff0c;子 集中的各个元素和为整数target的子集&#xff0c;结果中无重复的子集。 例如: nums[] [10, 1, 2, 7, 6, 1, 5]&#xff0c; target 8 结果为: [[1, 7], [1, 2, 5], …

如何在SharePoint2010中添加Deep Zoom Image

如何在SharePoint2010中添加Deep Zoom Image 应用范围 SharePoint 2010 Foundation&#xff1b;SharePoint 2010 Standard&#xff1b;SharePoint 2010 Enterprise所需材料 1. SeaDragon Ajax Viewer Web部件&#xff08;点击此处下载&#xff09;2. Deep Zoom Image Composer&…

linux 读取磁盘扇区,linux 下检查硬盘坏道/扇区

文章摘自&#xff1a;Linux检测硬盘坏道Linux检测硬盘坏道badblocks功能说明&#xff1a;检查磁盘装置中损坏的区块。语法&#xff1a;badblocks [-svw][-b ][-o ][磁盘装置][磁盘区块数][启始区块]补充说明&#xff1a;执行指令时须指定所要检查的磁盘装置&#xff0c;及此装置…

Pjax是什么以及为什么推荐大家用

什么是pjax? 现在很多网站( facebook, twitter) 都支持这样的一种浏览方式&#xff0c; 当你点击一个站内的链接的时候&#xff0c; 不是做页面跳转&#xff0c; 而是只是站内页面刷新。 这样的用户体验&#xff0c; 比起整个页面都闪一下来说&#xff0c; 好很多。 其中有一…

Scrapy框架CrawlSpider类爬虫实例

CrawlSpider类爬虫中&#xff1a; rules用于定义提取URl地址规则&#xff0c;元祖数据有顺序 #LinkExtractor 连接提取器&#xff0c;提取url地址 #callback 提取出来的url地址的response会交给callback处理 #follow 当前url地址的响应是否重新经过rules进行提取url地址 cf.py具…