TransWikia.com

GEE Linear Regression Error - ReduceBands reducer must have one input:

Geographic Information Systems Asked by Rebecca Dell on April 8, 2021

I am having a problem with the Linear Regression function (code attached) when I try to regress latitude or longitude against B4 reflectance for a S2 image. I am getting the following error:

ReduceBands reducer must have one input: <Reducer>.

https://code.earthengine.google.com/ef8f966b9ac39b308198968d45af58be

One Answer

The problem is that the way you are reducing, the inputs to the reducer will be the values of different bands in a pixel. In case of linear regression, it does not work as linear regression is trying to fit a linear equation by minimizing the rmse but one pixel is essentially just a single feature. Think of it this way, to do linear regression you need (x1,y1),(x2,y2),..... not just (x1,y1). So one of the following two is solution depending what you were trying to achieve.

  • If you were trying to get a single regression throughout the image, you should use reduceRegion instead. This will give you a set of coefficients and residuals rather than an image.
var linear = albedo.select(['longitude', 'B4'])
  .reduceRegion(ee.Reducer.linearRegression(1,1),image.get('system:footprint'),10);
  • If you were trying to get a regression going in each pixel, you'd need to reduce over an image collection rather than an image like in the example in gee docs. In this case, the way you are doing should work. You'd just need to change albedo to an image collection.

Answered by Nishanta Khanal on April 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP