2

I am training a random forest in GEE to predict canopy cover. See here for example. Implementation of RF is

var rf_model = ee.Classifier.randomForest(5).train(to_TrainAll, target, bands);

My predicted output mean value is low (expected ~20%, predicted ~8%) so I exported the training data and estimated using the sklearn implementation of RF and this returned a more realistic value. Training data available here.

import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor

df = pd.read_csv('/Users/phil/Google_Drive/training_data_100.csv')
bands = ['B5','B7','B10', 'B11_mean','B1_variance3','B2_variance3','B8_variance3',
         'B8A_variance3','B12_variance3','B2_variance5','B8_variance5','B9_variance5',
         'B10_variance5', 'ndvi','ndvi_stdDev_5','ndvi_temporal_variance',
         'slope','aspect','precipitation','tavg_min','tavg_max']

output = []

for _ in range(10):
    df.loc[:, 'train'] = np.random.random(size=len(df)) < .95
    X = df[df.train].cc.values.reshape(-1, 1)
    Y = df[df.train][bands].values
    rf = RandomForestRegressor(5).fit(Y, X)
    output.append(rf.predict(df[~df.train][bands]).mean())

print 'actual: {:.2f} predicted: {:.2f}'.format(df.cc.mean(), np.mean(output))

actual: 20.15 predicted: 20.37

Also if I run

ee.Classifier.cart().train(to_TrainAll, target, bands);

I get a more realistic value. What am I doing wrong?

1
  • 2
    Well, to be honest, the only thing that you are doing wrong is trusting GEE. I would go with the model and validation results produced by sklearn. There are some interesting nuances in applying a regression instance of random forest and I do not think that GEE has the model specified correctly. When evaluating output from different software take a close look at the documentation to make sure that there are no hidden parameters that could influence the out come and then go with the more stable, well developed implementation. Commented Mar 26, 2019 at 16:03

2 Answers 2

1

maybe it helps to specify ''setOutputMode'' to "regression" as done here https://doi.org/10.3390/rs10081167

0

This is obviously coming too late to be helpful, but for future visitors to this question I figured I'd add: EE's random forest classifier is not set up to handle regression at all. It's just a classifier. From my experience with it, I would guess that it's giving you such off-base values because it's trying to squeeze your continuous variable into series of unrelated classes, which is of course not what you're asking it to do. Hence, predictions that make no sense.

1
  • 2
    The 'new' classifiers, ee.Classifier.smileRandomForest(), ee.Classifier.smileGradientTreeBoost etc. can do regressions out of the box. You need to set the output mode setOutputMode('REGRESSION') Commented Feb 28, 2022 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.