[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 ...
随机推荐
- 【webpack 系列】进阶篇
本文将继续引入更多的 webpack 配置,建议先阅读[webpack 系列]基础篇的内容.如果发现文中有任何错误,请在评论区指正.本文所有代码都可在 github 找到. 打包多页应用 之前我们配置 ...
- list容器排除重复单词的程序
#include<iostream> #include<fstream> #include<string> #include<algorithm> #i ...
- DAO,Service,Controler的简介
DAO层: DAO层叫数据访问层,全称为data access object,属于一种比较底层,比较基础的操作,具体到对于某个表的增删改查,也就是说某个DAO一定是和数据库的某一张表一一对应的,其中封 ...
- markdown多张图片并排显示
在markdown中,目前,让图片像这样并排居中的方式主要是两种:  2.匿名函数(意义:减少内存占用) lambada 定义一个匿名函数,eg:lambad x,b:x+b (:前面是入参eg:x,b,:后 ...