# Difference between GEE and sklearn random forest output

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

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?

• 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. Mar 26, 2019 at 16:03