GEE学习笔记 八十六:分类中的特征重要性分析

2024-02-11 01:10

本文主要是介绍GEE学习笔记 八十六:分类中的特征重要性分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

    宅在家里不能回去工作,还是学习一下GEE吧!借用网友绘制的图片,加油,一切都会好起来的!

 

    之前在GEE中做随机森林分类时候,很多人都在问如何做特征重要性分析?但是在GEE之前并没有相关API可以做特征重要性分析,最新的API更新后GEE也可以做特征重要性分析了。

 

1、目前常用的包含特征重要信息分析的分类方法包括:

(1)决策树

ee.Classifier.smileCart(maxNodes, minLeafPopulation)

(2)随机森林

ee.Classifier.smileRandomForest(numberOfTrees, variablesPerSplit, minLeafPopulation, bagFraction, maxNodes, seed)

    这两个方法和之前的分类决策树和随机森林分类方法参数非常类似,只不过调用这两个定义方法在使用explain()方法就可以得到每个分类特征重要性的信息。

 

2、得到特征重要性的API方法:

    也就是之前在分类器中的方法explain,这个方法是最开始就有的,只不过是最近GEE官方加入了特征重要性的分析返回信息,下面通过一个具体例子说明一下如何使用以及具体输出。

 

具体代码:

var roi =/* color: #d63000 *//* shown: false *//* displayProperties: [{"type": "rectangle"}] */ee.Geometry.Polygon([[[114.23790821489501, 36.43657462800738],[114.23790821489501, 36.29834769127675],[114.49265369829345, 36.29834769127675],[114.49265369829345, 36.43657462800738]]], null, false),crop =/* color: #98ff00 *//* shown: false */ee.FeatureCollection([ee.Feature(ee.Geometry.Point([114.31343922075439, 36.356156419842804]),{"type": 0,"system:index": "0"}),ee.Feature(ee.Geometry.Point([114.31056389269042, 36.35499859187555]),{"type": 0,"system:index": "1"}),ee.Feature(ee.Geometry.Point([114.31236633714843, 36.3529248270982]),{"type": 0,"system:index": "2"}),ee.Feature(ee.Geometry.Point([114.32159313615966, 36.35461840580203]),{"type": 0,"system:index": "3"}),ee.Feature(ee.Geometry.Point([114.32348141130615, 36.35638107103549]),{"type": 0,"system:index": "4"}),ee.Feature(ee.Geometry.Point([114.32936081346679, 36.35589720612248]),{"type": 0,"system:index": "5"}),ee.Feature(ee.Geometry.Point([114.33515438493896, 36.35565527253804]),{"type": 0,"system:index": "6"}),ee.Feature(ee.Geometry.Point([114.33545479234863, 36.35855842592195]),{"type": 0,"system:index": "7"}),ee.Feature(ee.Geometry.Point([114.29468521532226, 36.35679580999553]),{"type": 0,"system:index": "8"}),ee.Feature(ee.Geometry.Point([114.29979214128662, 36.34922647614173]),{"type": 0,"system:index": "9"}),ee.Feature(ee.Geometry.Point([114.28871998247314, 36.3387180531404]),{"type": 0,"system:index": "10"}),ee.Feature(ee.Geometry.Point([114.28279766496826, 36.33833778756726]),{"type": 0,"system:index": "11"}),ee.Feature(ee.Geometry.Point([114.39553627428222, 36.3299369018726]),{"type": 0,"system:index": "12"}),ee.Feature(ee.Geometry.Point([114.39725288805175, 36.32997147527504]),{"type": 0,"system:index": "13"}),ee.Feature(ee.Geometry.Point([114.39712414201904, 36.32796619257241]),{"type": 0,"system:index": "14"}),ee.Feature(ee.Geometry.Point([114.39918407854248, 36.3291762831369]),{"type": 0,"system:index": "15"}),ee.Feature(ee.Geometry.Point([114.39845451769042, 36.3274475765775]),{"type": 0,"system:index": "16"}),ee.Feature(ee.Geometry.Point([114.40467724260498, 36.32900341420687]),{"type": 0,"system:index": "17"}),ee.Feature(ee.Geometry.Point([114.40480598863769, 36.32734385296429]),{"type": 0,"system:index": "18"}),ee.Feature(ee.Geometry.Point([114.38210377153564, 36.33612529650057]),{"type": 0,"system:index": "19"}),ee.Feature(ee.Geometry.Point([114.38034424242187, 36.336194437797644]),{"type": 0,"system:index": "20"}),ee.Feature(ee.Geometry.Point([114.38098797258544, 36.34041194086619]),{"type": 0,"system:index": "21"}),ee.Feature(ee.Geometry.Point([114.38785442766357, 36.337473540724005]),{"type": 0,"system:index": "22"}),ee.Feature(ee.Geometry.Point([114.38532242235351, 36.34227863160822]),{"type": 0,"system:index": "23"})]),nocrop =/* color: #0b4a8b *//* shown: false */ee.FeatureCollection([ee.Feature(ee.Geometry.Point([114.36832794603515, 36.344663782445146]),{"type": 1,"system:index": "0"}),ee.Feature(ee.Geometry.Point([114.37463650163818, 36.345078583829164]),{"type": 1,"system:index": "1"}),ee.Feature(ee.Geometry.Point([114.37742599901367, 36.34576991455905]),{"type": 1,"system:index": "2"}),ee.Feature(ee.Geometry.Point([114.378026813833, 36.34860430638123]),{"type": 1,"system:index": "3"}),ee.Feature(ee.Geometry.Point([114.37386402544189, 36.35009059256129]),{"type": 1,"system:index": "4"}),ee.Feature(ee.Geometry.Point([114.36987289842773, 36.352198996374725]),{"type": 1,"system:index": "5"}),ee.Feature(ee.Geometry.Point([114.37695393022705, 36.351887923993054]),{"type": 1,"system:index": "6"}),ee.Feature(ee.Geometry.Point([114.3797005122583, 36.35392715363849]),{"type": 1,"system:index": "7"}),ee.Feature(ee.Geometry.Point([114.37352070268798, 36.35627738595022]),{"type": 1,"system:index": "8"}),ee.Feature(ee.Geometry.Point([114.31785950121093, 36.34438724696162]),{"type": 1,"system:index": "9"}),ee.Feature(ee.Geometry.Point([114.31657204088378, 36.34345393245458]),{"type": 1,"system:index": "10"}),ee.Feature(ee.Geometry.Point([114.34390911516357, 36.33512274079625]),{"type": 1,"system:index": "11"}),ee.Feature(ee.Geometry.Point([114.35094723161865, 36.33723154988948]),{"type": 1,"system:index": "12"}),ee.Feature(ee.Geometry.Point([114.35309299883056, 36.337058698833104]),{"type": 1,"system:index": "13"}),ee.Feature(ee.Geometry.Point([114.35296425279785, 36.33501902740074]),{"type": 1,"system:index": "14"}),ee.Feature(ee.Geometry.Point([114.41952058729305, 36.35091929703152]),{"type": 1,"system:index": "15"}),ee.Feature(ee.Geometry.Point([114.41966006216182, 36.3516321782695]),{"type": 1,"system:index": "16"}),ee.Feature(ee.Geometry.Point([114.41982099470272, 36.35252219053154]),{"type": 1,"system:index": "17"}),ee.Feature(ee.Geometry.Point([114.42009458002224, 36.35383558809808]),{"type": 1,"system:index": "18"}),ee.Feature(ee.Geometry.Point([114.42027697023525, 36.35499343336394]),{"type": 1,"system:index": "19"}),ee.Feature(ee.Geometry.Point([114.42028233465328, 36.35609509850472]),{"type": 1,"system:index": "20"}),ee.Feature(ee.Geometry.Point([114.42228326257839, 36.35603461533285]),{"type": 1,"system:index": "21"}),ee.Feature(ee.Geometry.Point([114.42357072290554, 36.35606053669799]),{"type": 1,"system:index": "22"})]),water =/* color: #ffc82d *//* shown: false */ee.FeatureCollection([ee.Feature(ee.Geometry.Point([114.3321717685144, 36.3306024371752]),{"type": 2,"system:index": "0"}),ee.Feature(ee.Geometry.Point([114.33210739549804, 36.333592954210076]),{"type": 2,"system:index": "1"}),ee.Feature(ee.Geometry.Point([114.28854832109619, 36.41266166922327]),{"type": 2,"system:index": "2"}),ee.Feature(ee.Geometry.Point([114.29610142168212, 36.40879346635716]),{"type": 2,"system:index": "3"}),ee.Feature(ee.Geometry.Point([114.28580173906494, 36.40547771059803]),{"type": 2,"system:index": "4"}),ee.Feature(ee.Geometry.Point([114.29541477617431, 36.40160915003326]),{"type": 2,"system:index": "5"}),ee.Feature(ee.Geometry.Point([114.3057144587915, 36.40547771059803]),{"type": 2,"system:index": "6"}),ee.Feature(ee.Geometry.Point([114.29953464922119, 36.39829308768715]),{"type": 2,"system:index": "7"}),ee.Feature(ee.Geometry.Point([114.39435610231533, 36.3617846267207]),{"type": 2,"system:index": "8"}),ee.Feature(ee.Geometry.Point([114.39429172929897, 36.361179837099506]),{"type": 2,"system:index": "9"}),ee.Feature(ee.Geometry.Point([114.38845524248256, 36.35940000037548]),{"type": 2,"system:index": "10"}),ee.Feature(ee.Geometry.Point([114.38152441438808, 36.35701530096524]),{"type": 2,"system:index": "11"}),ee.Feature(ee.Geometry.Point([114.38133129533901, 36.35653143999478]),{"type": 2,"system:index": "12"}),ee.Feature(ee.Geometry.Point([114.39965614732876, 36.36371992192421]),{"type": 2,"system:index": "13"}),ee.Feature(ee.Geometry.Point([114.40693029817714, 36.3668473954689]),{"type": 2,"system:index": "14"}),ee.Feature(ee.Geometry.Point([114.41094288286342, 36.36890351124372]),{"type": 2,"system:index": "15"}),ee.Feature(ee.Geometry.Point([114.40238127168789, 36.36840244602017]),{"type": 2,"system:index": "16"})]);//监督分类Map.centerObject(roi, 11);Map.addLayer(roi, {color: "red"}, "roi", false);var sampleData = crop.merge(nocrop).merge(water);//Landsat8 SR数据去云function rmCloud(image) {var cloudShadowBitMask = (1 << 3);var cloudsBitMask = (1 << 5);var qa = image.select("pixel_qa");var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(qa.bitwiseAnd(cloudsBitMask).eq(0));return image.updateMask(mask);}//缩放function scaleImage(image) {var time_start = image.get("system:time_start");image = image.multiply(0.0001);image = image.set("system:time_start", time_start);return image;}//NDVIfunction NDVI(image) {return image.addBands(image.normalizedDifference(["B5", "B4"]).rename("NDVI"));}//NDWIfunction NDWI(image) {return image.addBands(image.normalizedDifference(["B3", "B5"]).rename("NDWI"));}//NDBIfunction NDBI(image) {return image.addBands(image.normalizedDifference(["B6", "B5"]).rename("NDBI"));}var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").filterBounds(roi).filterDate("2018-1-1", "2019-1-1").map(rmCloud).map(scaleImage).map(NDVI).map(NDWI).map(NDBI);var bands = ["B1", "B2", "B3", "B4", "B5", "B6", "B7","NDBI", "NDWI", "NDVI"];var l8Image = l8Col.median().clip(roi).select(bands);var rgbVisParam = {min: 0,max: 0.3,bands: ["B4", "B3", "B2"]};Map.addLayer(l8Image, rgbVisParam, "l8Image");//生成监督分类训练使用的样本数据var training = l8Image.sampleRegions({collection: sampleData,properties: ["type"],scale: 30});//初始化分类器// var classifier = ee.Classifier.smileCart().train({//   features: training,//   classProperty: "type",//   inputProperties: bands// });var classifier = ee.Classifier.smileRandomForest(10).train({features: training,classProperty: "type",inputProperties: bands});print(classifier.explain());//影像数据调用classify利用训练数据训练得到分类结果var classified = l8Image.classify(classifier);//训练结果的混淆矩阵var trainAccuracy = classifier.confusionMatrix();Map.addLayer(classified, {min:0, max:2, palette: ["green", "orange", "blue"]}, "classify");

 

代码分析:

(1)这段代码做的是一个简单的监督分类,通过自己标注的样本将影像分成3大类(作物、非作物和水),样本由于是我做测试随机标注的,所以测试精度和分类准确度不高。

(2)和之前的分类代码相比较,这里只是更换了分类方法,比如随机森林我使用的是smileRandomForest方法,参数和之前的方法的参数类似,这里只是简单设置了树的个数为10。

(3)然后对分类器调用explain方法就可以查看特征重要性信息,输出结果如下面所示。

 

运行结果:

    比如使用ee.Classifier.smileRandomForest()方法做的分类结果,使用explain后的信息如下图:

 


大家如果有问题需要交流或者有项目需要合作,可以微信联系我,加微信好友请留言加上“GEE”。

知乎专栏:https://zhuanlan.zhihu.com/c_123993183

CSDN:https://blog.csdn.net/shi_weihappy

微信号:shi_weihappy

这篇关于GEE学习笔记 八十六:分类中的特征重要性分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/698471

相关文章

MyBatis Plus 中 update_time 字段自动填充失效的原因分析及解决方案(最新整理)

《MyBatisPlus中update_time字段自动填充失效的原因分析及解决方案(最新整理)》在使用MyBatisPlus时,通常我们会在数据库表中设置create_time和update... 目录前言一、问题现象二、原因分析三、总结:常见原因与解决方法对照表四、推荐写法前言在使用 MyBATis

Python主动抛出异常的各种用法和场景分析

《Python主动抛出异常的各种用法和场景分析》在Python中,我们不仅可以捕获和处理异常,还可以主动抛出异常,也就是以类的方式自定义错误的类型和提示信息,这在编程中非常有用,下面我将详细解释主动抛... 目录一、为什么要主动抛出异常?二、基本语法:raise关键字基本示例三、raise的多种用法1. 抛

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

github打不开的问题分析及解决

《github打不开的问题分析及解决》:本文主要介绍github打不开的问题分析及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、找到github.com域名解析的ip地址二、找到github.global.ssl.fastly.net网址解析的ip地址三

Mysql的主从同步/复制的原理分析

《Mysql的主从同步/复制的原理分析》:本文主要介绍Mysql的主从同步/复制的原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录为什么要主从同步?mysql主从同步架构有哪些?Mysql主从复制的原理/整体流程级联复制架构为什么好?Mysql主从复制注意

java -jar命令运行 jar包时运行外部依赖jar包的场景分析

《java-jar命令运行jar包时运行外部依赖jar包的场景分析》:本文主要介绍java-jar命令运行jar包时运行外部依赖jar包的场景分析,本文给大家介绍的非常详细,对大家的学习或工作... 目录Java -jar命令运行 jar包时如何运行外部依赖jar包场景:解决:方法一、启动参数添加: -Xb

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

Linux中的more 和 less区别对比分析

《Linux中的more和less区别对比分析》在Linux/Unix系统中,more和less都是用于分页查看文本文件的命令,但less是more的增强版,功能更强大,:本文主要介绍Linu... 目录1. 基础功能对比2. 常用操作对比less 的操作3. 实际使用示例4. 为什么推荐 less?5.

spring-gateway filters添加自定义过滤器实现流程分析(可插拔)

《spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔)》:本文主要介绍spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔),本文通过实例图... 目录需求背景需求拆解设计流程及作用域逻辑处理代码逻辑需求背景公司要求,通过公司网络代理访问的请求需要做请