Random-Forest-Python
1. 近期目标,实现随机森林进行点云分类
1)学习阶段:
Kaggle Machine Learning Competition: Predicting Titanic Survivors
Kaggle Titanic 生存预测 -- 详细流程吐血梳理
https://www.codeproject.com/Articles/1197167/Random-Forest-Python
https://blog.csdn.net/hexingwei/article/details/50740404
2)实践阶段:
(1)原始点云字段(X,Y,Z,density,curvature,Classification),利用点云的高程Z,密度和曲率进行train和分类。分类结果很差就是了。
需要考虑哪些特征对分类结果的影响比较大?用什么样的点云特征更好,特征工程问题?
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 10 10:12:02 2018
@author: yhexie
"""
import numpy as np
import pandas as pd
from sklearn import model_selection
from sklearn.ensemble import RandomForestClassifier df = pd.read_csv('C:/Users/yhexie/.spyder-py3/pointcloudcls/train_pcloud2.csv', header=0)
x_train = df[['Z','Volume','Ncr']]
y_train = df.Classification df2 = pd.read_csv('C:/Users/yhexie/.spyder-py3/pointcloudcls/test_pcloud2.csv', header=0)
x_test = df2[['Z','Volume','Ncr']] clf = RandomForestClassifier(n_estimators=10)
clf.fit(x_train, y_train)
clf_y_predict = clf.predict(x_test) data_arry=[]
data_arry.append(df2.X)
data_arry.append(df2.Y)
data_arry.append(df2.Z)
data_arry.append(clf_y_predict) np_data = np.array(data_arry)
np_data = np_data.T
np.array(np_data)
save = pd.DataFrame(np_data, columns = ['X','Y','Z','Classification'])
save.to_csv('C:/Users/yhexie/.spyder-py3/pointcloudcls/predict_pcloud2.csv',index=False,header=True) #index=False,header=False表示不保存行索引和列标题
(2)对训练集进行split,用75%的数据训练,25%的数据验证模型的拟合精度和泛化能力。
a. 增加定性特征,进行dummy处理。
目前采用Z值和8个特征相关的点云特征进行分类,点云近邻搜索半径2.5m
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 28 10:54:48 2018 @author: yhexie
""" import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import model_selection
from sklearn.ensemble import RandomForestClassifier df = pd.read_csv('C:/Users/yhexie/.spyder-py3/pointcloudcls/train_pc.csv', header=0)
x_train = df[['Z','Linearity', 'Planarity','Scattering','Omnivariance', 'Anisotropy',
'EigenEntropy','eig_sum' ,'changeOfcurvature']]
y_train = df.Classification from sklearn.cross_validation import train_test_split
train_data_X,test_data_X,train_data_Y,test_data_Y = train_test_split(x_train, y_train, test_size=0.25, random_state=33) df2 = pd.read_csv('C:/Users/yhexie/.spyder-py3/pointcloudcls/test_pc.csv', header=0)
x_test = df2[['Z','Linearity', 'Planarity','Scattering','Omnivariance', 'Anisotropy',
'EigenEntropy','eig_sum' ,'changeOfcurvature']] clf = RandomForestClassifier(n_estimators=10)
clf.fit(train_data_X, train_data_Y) print('Accuracy on training set:{:.3f}:'.format(clf.score(train_data_X,train_data_Y)))
print('Accuracy on training set:{:.3f}:'.format(clf.score(test_data_X,test_data_Y)))
print('Feature inportances:{}'.format(clf.feature_importances_))
n_features=9
plt.barh(range(n_features),clf.feature_importances_,align='center')
plt.yticks(np.arange(n_features),['Z','Linearity', 'Planarity','Scattering','Omnivariance', 'Anisotropy',
'EigenEntropy','eig_sum' ,'changeOfcurvature'])
plt.xlabel('Feature importance')
plt.ylabel('Feature') clf_y_predict = clf.predict(x_test) data_arry=[]
data_arry.append(df2.X)
data_arry.append(df2.Y)
data_arry.append(df2.Z)
data_arry.append(clf_y_predict) np_data = np.array(data_arry)
np_data = np_data.T
np.array(np_data)
save = pd.DataFrame(np_data, columns = ['X','Y','Z','Classification'])
save.to_csv('C:/Users/yhexie/.spyder-py3/pointcloudcls/predict_pcloud2.csv',index=False,header=True) #index=False,header=False表示不保存行索引和列标题
计算结果:可以看到在测试集上的结果还是很差
Accuracy on training set:0.984:
Accuracy on test set:0.776:
特征重要程度:

新的测试:
Accuracy on training set:0.994:
Accuracy on training set:0.891:
Feature inportances:[0.02188956 0.02742479 0.10124688 0.01996966 0.1253002 0.02563489
0.03265565 0.100919 0.15808224 0.01937961 0.02727676 0.05498342
0.0211147 0.02387439 0.01900164 0.023478 0.02833916 0.0302441
0.02249598 0.06629199 0.05039737]


感觉Z值的重要程度太高了。房屋分类结果应该是很差,绿色的很多被错误分类了。
问题:目前训练集中的每个类别的样本数目并不相同,这个对训练结果有没有影响?
Random-Forest-Python的更多相关文章
- 随机森林random forest及python实现
引言想通过随机森林来获取数据的主要特征 1.理论根据个体学习器的生成方式,目前的集成学习方法大致可分为两大类,即个体学习器之间存在强依赖关系,必须串行生成的序列化方法,以及个体学习器间不存在强依赖关系 ...
- [Machine Learning & Algorithm] 随机森林(Random Forest)
1 什么是随机森林? 作为新兴起的.高度灵活的一种机器学习算法,随机森林(Random Forest,简称RF)拥有广泛的应用前景,从市场营销到医疗保健保险,既可以用来做市场营销模拟的建模,统计客户来 ...
- sklearn_随机森林random forest原理_乳腺癌分类器建模(推荐AAA)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- 随机森林(Random Forest)
阅读目录 1 什么是随机森林? 2 随机森林的特点 3 随机森林的相关基础知识 4 随机森林的生成 5 袋外错误率(oob error) 6 随机森林工作原理解释的一个简单例子 7 随机森林的Pyth ...
- 随机森林(Random Forest),决策树,bagging, boosting(Adaptive Boosting,GBDT)
http://www.cnblogs.com/maybe2030/p/4585705.html 阅读目录 1 什么是随机森林? 2 随机森林的特点 3 随机森林的相关基础知识 4 随机森林的生成 5 ...
- [Machine Learning & Algorithm] 随机森林(Random Forest)-转载
作者:Poll的笔记 博客出处:http://www.cnblogs.com/maybe2030/ 阅读目录 1 什么是随机森林? 2 随机森林的特点 3 随机森林的相关基础知识 4 随机森林的生成 ...
- 随机森林(Random Forest,简称RF)
阅读目录 1 什么是随机森林? 2 随机森林的特点 3 随机森林的相关基础知识 4 随机森林的生成 5 袋外错误率(oob error) 6 随机森林工作原理解释的一个简单例子 7 随机森林的Pyth ...
- 随机森林(Random Forest)详解(转)
来源: Poll的笔记 cnblogs.com/maybe2030/p/4585705.html 1 什么是随机森林? 作为新兴起的.高度灵活的一种机器学习算法,随机森林(Random Fores ...
- 随机森林分类器(Random Forest)
阅读目录 1 什么是随机森林? 2 随机森林的特点 3 随机森林的相关基础知识 4 随机森林的生成 5 袋外错误率(oob error) 6 随机森林工作原理解释的一个简单例子 7 随机森林的Pyth ...
- paper 85:机器统计学习方法——CART, Bagging, Random Forest, Boosting
本文从统计学角度讲解了CART(Classification And Regression Tree), Bagging(bootstrap aggregation), Random Forest B ...
随机推荐
- djjango安装及其 操作命令
一 首先掌握HTTP协议 HTTP四大特性: 1 基于tcp/IP作用在应用层之上的协议 2 基于请求响应 3 无状态(不识别来的用户的状态) 4 无连接(请求完返回响应后就断开) 数据格式: 请求 ...
- C语言经典题目
回顾一下吧: 一. 有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 解析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. 常规 ...
- Excel VBA入门(8): 代码调试/错误处理/代码优化
VBE有丰富的调试工具, 比如立即窗口, 本地窗口, 监视窗口, 断点调试... 第一个博文中已经讲过调试的基本操作: 设置断点, F5运行, F8逐条运行 断点就是程序中暂停停止运行的位置, 设置断 ...
- cc.Component 的使用
1.组件入口函数,常有的:onLoad,start,update //组件在加载的时候运行,并且场景的初始化工作已经完成 onLoad() { }, //组件在第一次update调用之前调用 star ...
- apache 配置反向代理 设置
1.下载 安装 下载地址:http://httpd.apache.org/download.cgi 将apache 安装到某个目录中 修改conf/http.conf文件 修改配置文件端口 (端口为 ...
- 【EasyNetQ】- 发布/订阅模式
EasyNetQ支持的最简单的消息传递模式是发布/ 订阅.这种模式是消除消费者信息提供者的绝佳方式.出版商简单地向全世界说,“这已经发生了”或“我现在有了这些信息”.它不关心是否有人正在倾听,他们可能 ...
- mysql的配置说明
查询最高内存占用 使用以下命令可以知道mysql的配置使用多少 RAM SELECT ( @@key_buffer_size + @@query_cache_size + @@innodb_buffe ...
- sqlserver 脚本生成数据库文档
SELECT ( then d.name else '' end)表名, --a.colorder 字段序号, a.name 字段名, --(case ...
- js中一个对象中遇到一个相同的key所对应的value值相加
如图: 变成: js原生如下: var abc=[ {typeid:1,ade:1}, {typeid:2,ade:1}, {typeid:1,ade:2}, {typeid:1,ade:2}, {t ...
- BZOJ4503 两个串 多项式 FFT
题目传送门 - BZOJ4503 题意概括 给定两个字符串S和T,回答T在S中出现了几次,在哪些位置出现.注意T中可能有?字符,可以匹配任何字符. 题解 首先,假装你已经知道了这是一道$FFT$题. ...