stemflow.model.SphereAdaSTEM
SphereAdaSTEM
Bases: AdaSTEM
A SphereAdaSTEm model class (allow fixed grid size)
Parents
stemflow.model.AdaSTEM
Children
stemflow.model.SphereAdaSTEM.SphereAdaSTEMClassifier
stemflow.model.SphereAdaSTEM.SphereAdaSTEMRegressor
Source code in stemflow/model/SphereAdaSTEM.py
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 250 251 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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 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 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
SAC_ensemble_predict(index_df, data)
A sub-module of SAC prediction function. Predict only one ensemble.
Parameters:
-
index_df
(DataFrame
) –ensemble data (model.ensemble_df)
-
data
(DataFrame
) –input covariates to predict
Returns: pd.core.frame.DataFrame: Prediction result of one ensemble.
Source code in stemflow/model/SphereAdaSTEM.py
405 406 407 408 409 410 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 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
|
SAC_ensemble_training(index_df, data)
A sub-module of SAC training function. Train only one ensemble.
Parameters:
-
index_df
(DataFrame
) –ensemble data (model.ensemble_df)
-
data
(DataFrame
) –input covariates to train
Source code in stemflow/model/SphereAdaSTEM.py
__init__(base_model, task='hurdle', ensemble_fold=10, min_ensemble_required=7, grid_len_upper_threshold=8000, grid_len_lower_threshold=500, points_lower_threshold=50, stixel_training_size_threshold=None, temporal_start=1, temporal_end=366, temporal_step=20, temporal_bin_interval=50, temporal_bin_start_jitter='adaptive', spatio_bin_jitter_magnitude='adaptive', random_state=None, save_gridding_plot=True, sample_weights_for_classifier=True, Spatio1='longitude', Spatio2='latitude', Temporal1='DOY', use_temporal_to_train=True, n_jobs=1, subset_x_names=False, plot_xlims=(-180, 180), plot_ylims=(-90, 90), verbosity=0, plot_empty=False, radius=6371.0, lazy_loading=False, lazy_loading_dir=None, min_class_sample=1)
Make a Spherical AdaSTEM object
Parameters:
-
base_model
(BaseEstimator
) –base model estimator
-
task
(str
, default:'hurdle'
) –task of the model. One of 'classifier', 'regressor' and 'hurdle'. Defaults to 'hurdle'.
-
ensemble_fold
(int
, default:10
) –Ensembles count. Higher, better for the model performance. Time complexity O(N). Defaults to 10.
-
min_ensemble_required
(int
, default:7
) –Only points with more than this number of model ensembles available are predicted. In the training phase, if stixels contain less than
points_lower_threshold
of data records, the results are set to np.nan, making themunpredictable
. Defaults to 7. -
grid_len_upper_threshold
(Union[float, int]
, default:8000
) –force divide if grid length (km) larger than the threshold. Defaults to 8000 km.
-
grid_len_lower_threshold
(Union[float, int]
, default:500
) –stop divide if grid length (km) will be below than the threshold. Defaults to 500 km.
-
points_lower_threshold
(int
, default:50
) –Do not further split the gird if split results in less samples than this threshold. Overriden by grid_len_*_upper_threshold parameters. Defaults to 50.
-
stixel_training_size_threshold
(int
, default:None
) –Do not train the model if the available data records for this stixel is less than this threshold, and directly set the value to np.nan. Defaults to 50.
-
temporal_start
(Union[float, int]
, default:1
) –start of the temporal sequence. Defaults to 1.
-
temporal_end
(Union[float, int]
, default:366
) –end of the temporal sequence. Defaults to 366.
-
temporal_step
(Union[float, int]
, default:20
) –step of the sliding window. Defaults to 20.
-
temporal_bin_interval
(Union[float, int]
, default:50
) –size of the sliding window. Defaults to 50.
-
temporal_bin_start_jitter
(Union[float, int, str]
, default:'adaptive'
) –jitter of the start of the sliding window. If 'adaptive', a random jitter of range (-bin_interval, 0) will be generated for the start. Defaults to 'adaptive'.
-
spatio_bin_jitter_magnitude
(Union[float, int]
, default:'adaptive'
) –jitter of the spatial gridding. Defaults to 'adaptive'.
-
random_state
–None or int. After setting the same seed, the model will generate the same results each time. For reproducibility.
-
save_gridding_plot
(bool
, default:True
) –Whether ot save gridding plots. Defaults to True.
-
sample_weights_for_classifier
(bool
, default:True
) –Whether to adjust for unbanlanced data for the classifier. Default to True.
-
Spatio1
(str
, default:'longitude'
) –Spatial column name 1 in data. For SphereAdaSTEM, this HAS to be 'longitude'.
-
Spatio2
(str
, default:'latitude'
) –Spatial column name 2 in data. For SphereAdaSTEM, this HAS to be 'latitude'.
-
Temporal1
(str
, default:'DOY'
) –Temporal column name 1 in data. Defaults to 'DOY'.
-
use_temporal_to_train
(bool
, default:True
) –Whether to use temporal variable to train. For example in modeling the daily abundance of bird population, whether use 'day of year (DOY)' as a training variable. Defaults to True.
-
n_jobs
(int
, default:1
) –Number of multiprocessing in fitting the model. Defaults to 1.
-
subset_x_names
(bool
, default:False
) –Whether to only store variables with std > 0 for each stixel. Set to False will significantly increase the training speed.
-
plot_xlims
(Tuple[Union[float, int], Union[float, int]]
, default:(-180, 180)
) –If save_gridding_plot=true, what is the xlims of the plot. Defaults to (-180,180).
-
plot_ylims
(Tuple[Union[float, int], Union[float, int]]
, default:(-90, 90)
) –If save_gridding_plot=true, what is the ylims of the plot. Defaults to (-90,90).
-
verbosity
(int
, default:0
) –0 to output nothing and everything otherwise.
-
plot_empty
(bool
, default:False
) –Whether to plot the empty grid
-
radius
(float
, default:6371.0
) –radius of earth in km.
-
lazy_loading
(bool
, default:False
) –If True, ensembles of models will be saved in disk, and only loaded when being used (e.g., prediction phase), and the ensembles of models are dump to disk once it is used.
-
lazy_loading_dir
(Union[str, None]
, default:None
) –If lazy_loading, the directory of the model to temporary save to. Default to None, where a random number will be generated as folder name.
-
min_class_sample
(int
, default:1
) –Minimum umber of samples needed to train the classifier in each stixel. If the sample does not satisfy, fit a dummy one. This parameter does not influence regression tasks.
Raises:
-
AttributeError
–Base model do not have method 'fit' or 'predict'
-
AttributeError
–task not in one of ['regression', 'classification', 'hurdle']
-
AttributeError
–temporal_bin_start_jitter not in one of [str, float, int]
-
AttributeError
–temporal_bin_start_jitter is type str, but not 'adaptive'
Attributes:
-
x_names
(list
) –All training variables used.
-
stixel_specific_x_names
(dict
) –stixel specific x_names (predictor variable names) for each stixel. We remove the variables that have no variation for each stixel. Therefore, the x_names are different for each stixel.
-
ensemble_df
(DataFrame
) –A dataframe storing the stixel gridding information.
-
gridding_plot
(Figure
) –Ensemble plot.
-
model_dict
(dict
) –Dictionary of {stixel_index: trained_model}.
-
grid_dict
(dict
) –An array of stixels assigned to each ensemble.
-
feature_importances_
(DataFrame
) –feature importance dataframe for each stixel.
Source code in stemflow/model/SphereAdaSTEM.py
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 |
|
split(X_train, verbosity=None, ax=None, n_jobs=1)
QuadTree indexing the input data
Parameters:
-
X_train
(DataFrame
) –Input training data
-
verbosity
(Union[None, int]
, default:None
) –0 to output nothing, everything other wise. Default None set it to the verbosity of AdaSTEM model class.
-
ax
–matplotlit Axes to add to.
Returns:
-
dict
–self.grid_dict, a dictionary of one DataFrame for each grid, containing the gridding information
Source code in stemflow/model/SphereAdaSTEM.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 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 324 325 326 327 328 329 330 331 332 333 |
|
SphereAdaSTEMClassifier
Bases: SphereAdaSTEM
SphereAdaSTEM model Classifier interface
Example
>>> from stemflow.model.SphereAdaSTEM import SphereAdaSTEMClassifier
>>> from xgboost import XGBClassifier
>>> model = SphereAdaSTEMClassifier(base_model=XGBClassifier(tree_method='hist',random_state=42, verbosity = 0, n_jobs=1),
save_gridding_plot = True,
ensemble_fold=10,
min_ensemble_required=7,
grid_len_upper_threshold=8000,
grid_len_lower_threshold=500,
points_lower_threshold=50,
Spatio1='longitude',
Spatio2 = 'latitude',
Temporal1 = 'DOY',
use_temporal_to_train=True)
>>> model.fit(X_train, y_train)
>>> pred = model.predict(X_test)
Source code in stemflow/model/SphereAdaSTEM.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
SphereAdaSTEMRegressor
Bases: SphereAdaSTEM
SphereAdaSTEM model Regressor interface
Example:
>>> from stemflow.model.SphereAdaSTEM import SphereAdaSTEMRegressor
>>> from xgboost import XGBRegressor
>>> model = SphereAdaSTEMRegressor(base_model=XGBRegressor(tree_method='hist',random_state=42, verbosity = 0, n_jobs=1),
save_gridding_plot = True,
ensemble_fold=10,
min_ensemble_required=7,
grid_len_upper_threshold=8000,
grid_len_lower_threshold=500,
points_lower_threshold=50,
Spatio1='longitude',
Spatio2 = 'latitude',
Temporal1 = 'DOY',
use_temporal_to_train=True)
>>> model.fit(X_train, y_train)
>>> pred = model.predict(X_test)
Source code in stemflow/model/SphereAdaSTEM.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
|