Browse all docs

Machine Learning in Earth Engine

Code status: The code on this page was corrected on 17 September 2026 against the current Earth Engine Data Catalog and API documentation. It has not been executed against Earth Engine. Screenshots, printed values and described outputs come from earlier versions of this lesson and may differ from what the corrected code produces.

Google Earth Engine (GEE) is equipped with built-in tools for conducting machine learning (ML) and statistical analysis on imagery data. To effectively leverage these tools, users must have a foundational understanding of ML concepts, as the application of these tools varies significantly depending on the specific use case and user preferences. It’s important to note the distinction between machine learning and deep learning within the context of GEE. While GEE facilitates traditional ML tasks, including supervised and unsupervised classification, as well as regression, it does not natively support training deep learning frameworks like PyTorch and TensorFlow. However, GEE can be used to preprocess and extract features from imagery, which can then be fed into external deep learning models, and it can run predictions from a model hosted on Vertex AI through ee.Model.fromVertexAi (currently in public preview).

GEE has powerful capabilities in pixel characterization and aggregation, processes for which machine learning (ML) techniques are not only helpful but essential. GEE supports a range of ML algorithms, such as Random Forest and Support Vector Machines (SVM), that are instrumental in analyzing and interpreting satellite imagery and raster data. These algorithms enable users to classify pixels, identify patterns, and aggregate data across vast geographic areas efficiently. This allows for the extraction of meaningful insights from complex environmental data, facilitating a wide array of applications from land cover classification to change detection and beyond.

Basic Suite of ML Algorithms

GEE offers a basic suite of ML algorithms that are particularly strong for pixel characterization tasks. Some of the key algorithms available include:

  • Random Forest: A versatile algorithm useful for both classification and regression tasks. It builds multiple decision trees and merges them to get a more accurate and stable prediction.
  • Support Vector Machines (SVM): Effective for high-dimensional spaces, SVM is used for classification tasks by finding the hyperplane that best divides the classes.
  • K-means Clustering: An unsupervised learning algorithm used to partition data into distinct clusters based on feature similarity.

These algorithms are well-suited for various remote sensing applications, including land cover classification, vegetation mapping, and environmental monitoring.

Integration with External ML Frameworks

While GEE’s built-in ML capabilities are robust, users often need to leverage more advanced machine learning frameworks such as Scikit-learn, TensorFlow, and PyTorch for specific tasks. Although GEE does not directly support these frameworks on its servers, it provides seamless integration through data preprocessing and feature extraction. Users can export processed data from GEE and then import it into their local or cloud-based ML environments to build and train advanced models.

Here’s a general workflow for integrating GEE with external ML frameworks:

Data Preprocessing in GEE:

  • Use GEE to preprocess satellite imagery, including tasks like cloud masking, normalization, and feature extraction.

Python setup: every Python cell on this page assumes this block has already run in the same session. Registering a Cloud project and authenticating are covered in Getting Started with Earth Engine.

import ee
import geemap

ee.Authenticate()  # opens the sign-in flow when no stored credentials exist
ee.Initialize(project='your-cloud-project-id')  # use your registered Cloud project ID

def build_map(lat, lon, zoom, vis_params, image, name):
    m = geemap.Map(center=[lat, lon], zoom=zoom)
    m.addLayer(image, vis_params, name)
    return m
# Example code to preprocess data in GEE
# Study area: a rectangle around Blacksburg, VA ([west, south, east, north])
geometry = ee.Geometry.Rectangle([-80.6, 37.1, -80.2, 37.4])

# Load an image collection, filtered to the study area, a summer and low cloud cover
collection = (ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
              .filterBounds(geometry)
              .filterDate('2024-06-01', '2024-09-01')
              .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)))

# Preprocess and extract features
def preprocess(image):
    return image.normalizedDifference(['B8', 'B4']).rename('NDVI')

# Median NDVI composite for the summer
processed = collection.map(preprocess).median()

Export Processed Data:

  • Export the processed data to Google Drive, Google Cloud Storage or an Earth Engine asset. Earth Engine cannot export directly to your local disk; download the file from Drive or Cloud Storage afterwards. The export below writes a GeoTIFF.
# Export the image to Google Cloud Storage
export_task = ee.batch.Export.image.toCloudStorage(
    image=processed,
    description='ProcessedImage',
    bucket='your-bucket-name',
    fileNamePrefix='processed_image',
    scale=10,  # Sentinel-2 B4 and B8 are 10 m bands
    region=geometry,
    maxPixels=1e9)
export_task.start()

Import into External ML Framework:

  • Load the exported data into your preferred ML framework for further analysis and model training. The exported GeoTIFF holds pixel values only, so read it with a raster library such as rasterio and pair the pixels with your own reference labels first. The example below assumes you saved those pairs as a .npz file with named features and labels arrays.
# Example with Scikit-learn
from sklearn.ensemble import RandomForestClassifier
import numpy as np

# Load your prepared data: a .npz file with named 'features' and 'labels' arrays
data = np.load('path_to_your_data.npz')

# Train a Random Forest model
model = RandomForestClassifier(n_estimators=100)
model.fit(data['features'], data['labels'])

Building Your Own Workflow

One of the strengths of working with machine learning in GEE is the flexibility it offers. There are numerous ways to build your workflow depending on your specific needs and the complexity of your analysis. Users can:

  • Combine multiple algorithms: Use a combination of different ML algorithms to enhance the accuracy and robustness of your analysis.
  • Leverage cloud computing: Utilize cloud-based platforms like Google Cloud Platform or AWS to handle large-scale data processing and model training.
  • Integrate with other tools: Incorporate other geospatial and data science tools such as QGIS, ArcGIS, and various Python libraries to complement your GEE workflow.

The versatility of GEE, combined with its integration capabilities with powerful external ML frameworks, allows researchers and practitioners to develop tailored solutions for their specific remote sensing and geospatial analysis needs. Whether you’re conducting basic pixel classification or advanced deep learning analyses, GEE provides a solid foundation to build upon.

Summary

Google Earth Engine is a powerful platform for conducting machine learning on geospatial data. Its built-in algorithms are well-suited for a range of remote sensing applications, while its ability to integrate with external ML frameworks like Scikit-learn and TensorFlow extends its utility even further. By leveraging GEE’s capabilities, users can preprocess and analyze vast amounts of imagery data efficiently, then export these data for advanced analysis in other environments. This flexibility allows for the creation of customized workflows that meet the unique demands of various projects, from environmental monitoring to land cover classification and beyond.