[Hands-on-Machine-Learning-master] 02 Housing
用到的函数
numpy.random.permutation
随机排列一个序列,返回一个排列的序列。
>>> np.random.permutation(10)
array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) >>> np.random.permutation([1, 4, 9, 12, 15])
array([15, 1, 9, 4, 12]) >>> arr = np.arange(9).reshape((3, 3))
>>> np.random.permutation(arr)
array([[6, 7, 8],
[0, 1, 2],
[3, 4, 5]])
iloc
Pandas中的 iloc 是用基于整数的下标来进行数据定位/选择
iloc 的语法是 data.iloc[<row selection>, <column selection>], iloc 在Pandas中是用来通过数字来选择数据中具体的某些行和列。你可以设想每一行都有一个对应的下标(0,1,2,...),通过 iloc 我们可以利用这些下标去选择相应的行数据。同理,对于行也一样,想象每一列也有对应的下标(0,1,2,...),通过这些下标也可以选择相应的列数据。
在iloc中一共有 2 个 “参数” -行选择器 和 -列选择器,例如:
# 使用DataFrame 和 iloc 进行单行/列的选择
# 行选择:
data.iloc[0] # 数据中的第一行
data.iloc[1] # 数据中的第二行
data.iloc[-1] # 数据中的最后一行 # 列选择:
data.iloc[:, 0] # 数据中的第一列
data.iloc[:, 1] # 数据中的第二列
data.iloc[:, -1] # 数据中的最后一列
行列混合选择
iloc 同样可以进行和列的混合选择,例如:
# 使用 iloc 进行行列混合选择
data.iloc[0:5] # 数据中的第 1-5 行
data.iloc[:, 0:2] # 选择数据中的前2列和所有行
data.iloc[[0, 3, 6, 24], [0, 5, 6]] # 选择第 1,4,7,25行 和 第 1,6,7 列
data.iloc[0:5, 5:8] # 选择第1-6行 和 6-9列
使用 iloc 注意以下两点:
如果使用iloc只选择了单独的一行会返回 Series 类型,而如果选择了多行数据则会返回 DataFrame 类型,如果你只选择了一行,但如果想要返回 DataFrame 类型可以传入一个单值list.
当你使用 [1:5] 这种语法对数据进行切片的时候,要注意只选择了 1,2,3,4 这 4 个下标,而 5 并没有被包括进去,即使用[x:y]选择了下标从 x 到 y-1 的数据
实际工作中,其实很少用到 iloc ,除非你想选择第一行( data.iloc[0] ) 或者 最后一行( data.iloc[-1] )
.
[Hands-on-Machine-Learning-master] 02 Housing的更多相关文章
- 机器学习实战(Machine Learning in Action)学习笔记————02.k-邻近算法(KNN)
机器学习实战(Machine Learning in Action)学习笔记————02.k-邻近算法(KNN) 关键字:邻近算法(kNN: k Nearest Neighbors).python.源 ...
- Google's Machine Learning Crash Course #02# Descending into ML
INDEX How do we know if we have a good line Linear Regression Training and Loss How do we know if we ...
- ML Lecture 0-2: Why we need to learn machine learning?
在Github上也po了这个系列学习笔记(MachineLearningCourseNote),觉得写的不错的小伙伴欢迎来给项目点个赞哦~~ ML Lecture 0-2: Why we need t ...
- [C2P3] Andrew Ng - Machine Learning
##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)
##机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)---#####注:机器学习资料[篇目一](https://github.co ...
- 聊天机器人(chatbot)终极指南:自然语言处理(NLP)和深度机器学习(Deep Machine Learning)
在过去的几个月中,我一直在收集自然语言处理(NLP)以及如何将NLP和深度学习(Deep Learning)应用到聊天机器人(Chatbots)方面的最好的资料. 时不时地我会发现一个出色的资源,因此 ...
- 学习笔记之机器学习(Machine Learning)
机器学习 - 维基百科,自由的百科全书 https://zh.wikipedia.org/wiki/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0 机器学习是人工智能的一个分 ...
- 壁虎书2 End-to-End Machine Learning Project
the main steps: 1. look at the big picture 2. get the data 3. discover and visualize the data to gai ...
- 人工智能(Machine Learning)—— 机器学习
https://blog.csdn.net/luyao_cxy/article/details/82383091 转载:https://blog.csdn.net/qq_27297393/articl ...
- [C5] Andrew Ng - Structuring Machine Learning Projects
About this Course You will learn how to build a successful machine learning project. If you aspire t ...
随机推荐
- CVE-2020-2551复现过程
项目地址 cnsimo/CVE-2020-2551 CVE-2020-2551 weblogic iiop 反序列化漏洞 该项目的搭建脚本在10.3.6版本经过测试,12版本未测试. 环境 kali+ ...
- 针对Kafka的centos系统参数优化
TCP网络优化 sudo vim /etc/sysctl.conf vm.max_map_count=655360net.core.rmem_default=262144net.core.rmem_m ...
- (CSS):last-child与:last-of-type区别
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>la ...
- Shell脚本的编写及测试
Shell脚本的编写及测试 1.1问题 本例要求两个简单的Shell脚本程序,任务目标如下: 编写一 ...
- Scratch 全套学习资料
链接:https://pan.baidu.com/s/1qX0T2B_zczcLaCCpiRrsnA提取码:xfp8
- 【Linux】LAMP环境搭建(简易版)
一. 辅助软件包安装 准备工作:1.Linux系统准备 恢复快照(初始化安装) 设置IP 关闭SELINUX 配置yum源 2.yum -y install gcc gcc-c++ 3.关闭防火墙 4 ...
- Spring(三):bean的自动装配
Bean的自动装配 自动装配是Spring满足bean依赖的一种方式. Spring会在上下文中自动寻找,并自动给bean装配属性 Spring中三种装配方式 在xml中显式的配置. 在java中显式 ...
- Linux基础篇,Shell
一.基本知识 Shell Script是一种脚本.可以用来极大的简化计算机的管理.在谱写shell script的时候,需要注意以下问题: 1. 指令的执行是从上而下. 从左而右的分析与执行: 2. ...
- 第二章 IBM
1.不要招惹IBM,这可是一家做过军火的公司,一家参与了曼哈顿计划的公司. 同时也是世界上最大的服务公司.第二大软件公司.第二大数据库公司.拥有工业界最大的实验室.第一专利申请大户.最大的开源linu ...
- 10.6 IoStudentManager
package day11_io_student.student_demo; public class Student { private String id; private String name ...