Satellite Context ("A-Train" Constellation) Satellites mentioned: CALIPSO, CloudSat, Glory, Aqua, GCOM-W1, Aura, OCO-2, PARASOL.Typical along-track time separations: CALIPSO–CloudSat 17.5 s 17.5\,\text{s} 17.5 s ; CloudSat–Glory 1 min 1\,\text{min} 1 min ; etc. Used to obtain nearly simultaneous atmospheric / surface observations. Unit 4 – Main Thematic Blocks Introduction to Machine Learning (ML) for remote-sensing imagery. Spectral-index computation & analysis. Re-classification by value intervals. Cloud masking & radiometric correction. Image fusion (Pansharpening). Machine Learning: Foundations Artificial Intelligence ⊃ Machine Learning ⊃ Deep Learning. ML divisionsSupervised Learning (need labelled data) – classification & regression. Unsupervised Learning (no labels) – clustering, dimensionality reduction, visualisation. Reinforcement Learning (agents, decisions, bots). Typical public-sector uses: fraud detection, subsidy optimisation, demography, anomaly compression, NLP for documents. Supervised vs Unsupervised Image Classification SupervisedRequires user-provided training samples; classes predefined. Algorithms: Random Forest, Support Vector Machine, Decision Tree (CART/CAST), k k k -Nearest Neighbors, Naïve Bayes, Logistic Regression, etc. UnsupervisedNo prior labels; algorithm groups pixels by intrinsic similarity. Algorithms: K-Means, ISODATA, DBSCAN, Principal Component Analysis. Core Dataset Terminology Training set – teaches the model. Validation set – tunes hyper-parameters without affecting learning. Test set – unseen data for final assessment. Overfitting – memorises noise, poor generalisation. Underfitting – fails to capture patterns even on training data. Model – mathematical representation that maps inputs to outputs. Evaluation metrics – quantitative performance measures. Hyper-parameters & Cross-Validation (CV) Hyper-parameter = user-set learning configuration (e.g. number of trees, k k k in K-Means, kernel of SVM). k k k -fold CV: split data into k k k parts; rotate train/validate; average score → robust estimate.Grid/Random search on hyper-parameter combinations combined with CV yields best settings. Obtaining Training Samples Field work (GPS ground truth). Visual interpretation on medium- or high-resolution imagery. Existing GIS/remote-sensing databases. Recommendation: mix remote techniques with random points to minimise bias; digitise points/polygons with consistent criteria. QGIS tools (Vertex Editor, Add Feature, Node Tool, etc.) facilitate manual delineation. After digitising, label samples via attribute table. Typical Supervised-Classification Workflow Pre-process satellite scene (cloud mask, radiometric / atmospheric corrections, pansharpen if needed). Gather training polygons/pixels. Stack all spectral bands & indices into multi-band raster cube. Extract pixel values under training geometries → feature table. Split data → train / validate / test; perform normalisation or outlier correction if required. Select algorithm + tune hyper-parameters via CV. Train model, evaluate on validation/test; compute confusion matrix, OA, Kappa, F1, Producer/User accuracies. Apply classifier to full image; post-process (smoothing, majority filters, accuracy assessment with independent samples). Confusion-Matrix–Based Accuracy Metrics Overall Accuracy (OA): OA = ∑ < e m > i n < / e m > i i N \text{OA}=\frac{\sum<em>{i} n</em>{ii}}{N} OA = N ∑ < e m > i n < / e m > ii Producer Accuracy (Recall): PA < e m > i = n < / e m > i i ∑ < e m > j n < / e m > i j \text{PA}<em>i=\frac{n</em>{ii}}{\sum<em>j n</em>{ij}} PA < e m > i = ∑ < e m > j n < / e m > ij n < / e m > ii — how many reference pixels of class i i i were correctly mapped. User Accuracy (Precision): UA < e m > i = n < / e m > i i ∑ < e m > j n < / e m > j i \text{UA}<em>i=\frac{n</em>{ii}}{\sum<em>j n</em>{ji}} UA < e m > i = ∑ < e m > j n < / e m > j i n < / e m > ii — reliability of labelled pixels. Kappa Index: κ = p < e m > o − p < / e m > e 1 − p < e m > e \kappa = \frac{p<em>o-p</em>e}{1-p<em>e} κ = 1 − p < e m > e p < e m > o − p < / e m > e , where p < / e m > o p</em>o p < / e m > o = observed agreement, p e p_e p e = chance agreement. F1-Score: F 1 = 2 Precision ⋅ Recall Precision + Recall F_1=2\frac{\text{Precision}\,\cdot\,\text{Recall}}{\text{Precision}+\text{Recall}} F 1 = 2 Precision + Recall Precision ⋅ Recall . Extract per-band values below vector features: extract(img, shp, bind=T). Convert class field to categorical factor: factor(vector, levels, labels). Core Python Libraries for RS ML rasterio (GDAL-based raster IO), numpy, pandas, matplotlib, scikit-learn.Loading & Cleaning Data (Python Snippet) import pandas as pd, rasterio, numpy as np, matplotlib.pyplot as plt
# 1. tabular samples
samples = pd.read_csv('data_muestras.csv')
print(samples.head(), samples.shape)
# 2. drop NAs
samples = samples.dropna()
# 3. split predictors / labels
X = samples.iloc[:,3:-1] # adjust column indices
y = samples['CLASES_NUM']
Data Normalisation Standard Scaler: z = x − μ σ z=\frac{x-\mu}{\sigma} z = σ x − μ (mean 0 0 0 , std 1 1 1 ) – good for Gaussian-assumption models (SVM, KNN, logistic). Min–Max Scaler: x ′ = x − x < e m > min x < / e m > max − x min x' = \frac{x-x<em>{\min}}{x</em>{\max}-x_{\min}} x ′ = x < / e m > m a x − x m i n x − x < e m > m i n → [ 0 , 1 ] [0,1] [ 0 , 1 ] range – common for neural nets or distance-based models. Decision Tree – CART/CAST Splits data recursively into axis-aligned rectangular regions. Impurity criteriaGini: G = 1 − ∑ < e m > i = 1 C p < / e m > i 2 G = 1-\sum<em>{i=1}^C p</em>i^2 G = 1 − ∑ < e m > i = 1 C p < / e m > i 2 . Entropy (Shannon): H = − ∑ < e m > i = 1 C p < / e m > i log < e m > 2 p < / e m > i H=-\sum<em>{i=1}^C p</em>i\log<em>2 p</em>i H = − ∑ < e m > i = 1 C p < / e m > i log < e m > 2 p < / e m > i . Key terminology: root node, internal decision node, leaf node, splitting, pruning. Stopping rules: pure node (G = 0 G=0 G = 0 ), max depth, min samples per split/leaf, min impurity decrease. Hyper-parameters (Scikit-learn DecisionTreeClassifier)criterion ("gini" | "entropy" | "log_loss"), max_depth, min_samples_split, min_samples_leaf, ccp_alpha (cost-complexity pruning), etc. Pros: intuitive, handles mixed data types, no scaling needed. Cons: prone to overfit; single tree less accurate than ensembles. Python code skeleton provided (train/test split, fit, predict; plot_tree visualisation; printing feature importances, depth, n_leaves). k-Nearest Neighbors (k-NN) For new pixel x x x Compute distance to all training points (often Euclidean d ( x , x < e m > i ) = ∑ ( x < / e m > j − x i j ) 2 d(\mathbf{x},\mathbf{x<em>i}) = \sqrt{\sum (x</em>j-x_{ij})^2} d ( x , x < em > i ) = ∑ ( x < / e m > j − x ij ) 2 ). Select k k k nearest; vote majority class. Critical hyper-parameter k k k → choose via CV, usually odd (3,5,7) when 2 classes. Scaling mandatory; distance sensitive to variable scales. Pros: simple, non-parametric. Cons: expensive prediction on large datasets; sensitive to irrelevant features & class imbalance. Provided code: CV loop for k = 1..19 k=1..19 k = 1..19 plotting mean accuracy; retrain with best k k k . Naïve Bayes (Gaussian NB shown) Based on Bayes theorem P ( C ∣ X ) = P ( X ∣ C ) P ( C ) P ( X ) P(C|X)=\frac{P(X|C)\,P(C)}{P(X)} P ( C ∣ X ) = P ( X ) P ( X ∣ C ) P ( C ) assuming conditional independence among predictors. For Gaussian NB: each feature assumed normally distributed per class P ( x < e m > j ∣ C < / e m > k ) = N ( μ < e m > j k , σ < / e m > j k 2 ) P(x<em>j|C</em>k) = \mathcal{N}(\mu<em>{jk},\sigma</em>{jk}^2) P ( x < e m > j ∣ C < / e m > k ) = N ( μ < e m > j k , σ < / e m > j k 2 ) . StepsEstimate prior P ( C k ) P(C_k) P ( C k ) . Estimate μ < e m > j k , σ < / e m > j k \mu<em>{jk},\sigma</em>{jk} μ < e m > j k , σ < / e m > j k for each feature/class. Compute posteriors for new X X X ; assign largest. Fast, works well with high-dimensional sparse data; independence rarely true → may mis-model interactions. Example training/prediction code with GaussianNB. Random Forest (RF) Ensemble of decision trees built via Bagging + random feature selection. Key conceptsBootstrap sampling (with replacement) per tree. Random subset of predictors at each split (decorrelates trees). Majority voting for classification; averaging for regression. Benefits: reduces overfitting, handles high-dimensional & unbalanced data, needs little tuning. Hyper-parameters (RandomForestClassifier): n_estimators, max_depth, max_features, min_samples_split, min_samples_leaf, class_weight, oob_score (out-of-bag accuracy). Trade-off: more trees ↑ accuracy but ↑ compute. Support Vector Machine (SVM) Finds optimal separating hyperplane w ⋅ x + b = 0 \mathbf{w}\cdot\mathbf{x}+b=0 w ⋅ x + b = 0 maximising margin 2 ∣ ∣ w ∣ ∣ \frac{2}{||\mathbf{w}||} ∣∣ w ∣∣ 2 . Optimisation (soft-margin):min < e m > w , b , ξ 1 2 ∣ ∣ w ∣ ∣ 2 + C ∑ < / e m > i ξ < e m > i \min<em>{\mathbf{w},b,\xi}\;\frac12||\mathbf{w}||^2 + C\sum</em>i\xi<em>i min < e m > w , b , ξ 2 1 ∣∣ w ∣ ∣ 2 + C ∑ < / e m > i ξ < e m > i
subject to y < / e m > i ( w ⋅ x < e m > i + b ) ≥ 1 − ξ < / e m > i , ξ i ≥ 0 y</em>i(\mathbf{w}\cdot\mathbf{x}<em>i+b) \ge 1-\xi</em>i,\;\xi_i\ge0 y < / e m > i ( w ⋅ x < e m > i + b ) ≥ 1 − ξ < / e m > i , ξ i ≥ 0 . Kernel trick projects data into higher-dimensional feature space (radial basis function, polynomial, sigmoid, linear). Key hyper-parameters: C (regularisation), kernel, gamma (RBF width), degree, coef0. Multiclass StrategiesOne-vs-Rest (OvR): k k k classifiers. One-vs-One (OvO): k ( k − 1 ) 2 \frac{k(k-1)}{2} 2 k ( k − 1 ) classifiers (scikit-learn default). Pros: effective in high-dimensional space, flexible kernels. Cons: scaling issues for very large datasets; parameter tuning crucial; limited interpretability. Full-Scene Classification & Export (Python Snippet) with rasterio.open('PROCESADAS/chancay_2020.tif') as src:
bands = src.read() # shape: (n_bands, rows, cols)
profile = src.profile
bands = bands.reshape(bands.shape[0], -1).T # (n_pix, n_bands)
bands_scaled = scaler.transform(bands) # use same scaler as training
nodata = profile.get('nodata')
mask = ~np.any(np.isnan(bands_scaled) | (bands_scaled==nodata), axis=1)
X_valid = bands_scaled[mask]
y_pred = clf.predict(X_valid) # clf from any trained model
# Re-insert into raster grid
pred_full = np.full(bands_scaled.shape[0], nodata, dtype='uint8')
pred_full[mask] = y_pred.astype('uint8')
classified = pred_full.reshape(profile['height'], profile['width'])
# Display & save
plt.imshow(classified, cmap='tab10'); plt.axis('off'); plt.show()
profile.update(dtype=rasterio.uint8, count=1, nodata=0)
with rasterio.open('CAST/cast_2025.tif','w', **profile) as dst:
dst.write(classified, 1)
Additional Practical Tips Always keep identical preprocessing (scaling, cloud masking) between training samples and full-scene classification. Consider balancing classes (e.g. class_weight='balanced' in RF/SVM) when reference data are imbalanced. For spectral-index features, compute NDVI, NDWI, NDBI, etc. and add as additional bands before stacking. Apply majority or sieve filters to reduce salt-and-pepper noise after pixel-based classification. Use independent accuracy samples (separate from training/validation) for final assessment. Ethical / Practical Considerations Training data collection should minimise bias; random, stratified sampling recommended. Over-reliance on automated models without ground verification may propagate systematic errors (e.g., misclassification of clouds/shadows as water). Computational costs (RF with many trees, SVM with non-linear kernels) must be weighed against real-time or resource constraints in public-sector deployments.