ml module¶
Module for machine learning with Google Earth Engine.
csv_to_classifier(in_csv)
¶
Returns an ee.Classifier from a CSV file.
The file must contain a list of strings (an ensemble of decision trees).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
File path to the input CSV. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
object |
Classifier
|
ee.Classifier. |
Source code in geemap/ml.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
export_trees_to_fc(trees, asset_id, description='geemap_rf_export')
¶
Starts an export task to create a feature collection of a decision tree.
Creates a feature collection with a property tree which contains the string representation of decision trees and exports to ee asset for later use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
list[str]
|
List of string representation of the decision trees. |
required |
asset_id
|
str
|
ee asset id path to export the feature collection to. |
required |
kwargs
description (str): optional description to provide export information. default = "geemap_rf_export"
Source code in geemap/ml.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
fc_to_classifier(fc)
¶
Returns an ee.Classifier from a feature collection.
The feature collection must be from from export_trees_to_fc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fc
|
FeatureCollection
|
feature collection that has trees property for each feature that represents the decision tree |
required |
Returns:
| Name | Type | Description |
|---|---|---|
classifier |
Classifier
|
ee classifier object representing an ensemble decision tree |
Source code in geemap/ml.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
rf_to_strings(estimator, feature_names, processes=2, output_mode='INFER')
¶
Convert a ensemble of decision trees into a list of strings.
Wraps tree_to_string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
estimator
|
A decision tree classifier or regressor object created using sklearn. |
required |
feature_names
|
list[str]
|
List of strings that define the name of features (i.e., bands) used to create the model. |
required |
processes
|
int
|
Number of cpu processes to spawn. Increasing processes will improve speed for large models. default = 2 |
2
|
output_mode
|
str
|
Output mode of the estimator. Options are "INFER", "CLASSIFIATION", or "REGRESSION" (capitalization does not matter). default = "INFER" |
'INFER'
|
Returns:
| Name | Type | Description |
|---|---|---|
trees |
list[str]
|
list of strings where each string represents a decision tree estimator and collectively represent an ensemble decision tree estimator (i.e., RandomForest) |
Source code in geemap/ml.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
strings_to_classifier(trees)
¶
Returns an ee.Classifier from a string representation of decision trees.
Source code in geemap/ml.py
326 327 328 329 330 331 332 333 334 335 336 | |
tree_to_string(estimator, feature_names, labels=None, output_mode='INFER')
¶
Convert a sklearn decision tree object to a string format that EE can interpret
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
estimator
|
An estimator consisting of multiple decision tree classifiers. Expects object to contain estimators_ attribute |
required |
feature_names
|
Iterable[str]
|
List of strings that define the name of features (i.e., bands) used to create the model |
required |
labels
|
Iterable[numeric]
|
List of class labels to map outputs to, must be numeric values. If None, then raw outputs will be used. default = None |
None
|
output_mode
|
str
|
the output mode of the estimator. Options are "INFER", "CLASSIFIATION", or "REGRESSION" (capitalization does not matter). default = "INFER" |
'INFER'
|
Returns:
| Name | Type | Description |
|---|---|---|
tree_str |
str
|
string representation of decision tree estimator |
1 2 | |
Source code in geemap/ml.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
trees_to_csv(trees, out_csv)
¶
Save a list of strings (an ensemble of decision trees) to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
list[str]
|
A list of strings (an ensemble of decision trees). |
required |
out_csv
|
str
|
File path to the output csv. |
required |
Source code in geemap/ml.py
399 400 401 402 403 404 405 406 407 408 | |