stemflow.model.STEM
STEM
Bases: AdaSTEM
A STEM model class (allow fixed grid size)
Parents
stemflow.model.AdaSTEM.AdaSTEM
Children
None
Source code in stemflow/model/STEM.py
10 11 12 13 14 15 16 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 |
|
__init__(base_model, task='hurdle', ensemble_fold=10, min_ensemble_required=7, grid_len=25, 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=None, plot_ylims=None, verbosity=0, plot_empty=False, completely_random_rotation=False, lazy_loading=False, lazy_loading_dir=None, min_class_sample=1)
Make a STEM 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
(Union[float, int]
, default:25
) –length of the grids. Defaults to 25.
-
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. Defaults to 'longitude'.
-
Spatio2
(str
, default:'latitude'
) –Spatial column name 2 in data. Defaults to '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:None
) –If save_gridding_plot=true, what is the xlims of the plot. Defaults to the extent of input X varibale.
-
plot_ylims
(Tuple[Union[float, int], Union[float, int]]
, default:None
) –If save_gridding_plot=true, what is the ylims of the plot. Defaults to the extent of input Y varibale.
-
verbosity
(int
, default:0
) –0 to output nothing and everything otherwise.
-
plot_empty
(bool
, default:False
) –Whether to plot the empty grid.
-
completely_random_rotation
(bool
, default:False
) –If True, the rotation angle will be generated completely randomly, as in paper https://doi.org/10.1002/eap.2056. If False, the ensembles will split the 90 degree with equal angle intervals. e.g., if ensemble_fold=9, then each ensemble will rotate 10 degree futher than the previous ensemble. Defalt to False, because if ensemble fold is small, it will be more robust to equally devide the data; and if ensemble fold is large, they are effectively similar than complete random.
-
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 'random'
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/STEM.py
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 |
|
STEMClassifier
Bases: AdaSTEMClassifier
STEM model Classifier interface (allow fixed grid size)
Parents
stemflow.model.AdaSTEM.AdaSTEMClassifier
Children
None
Example
>>> from stemflow.model.STEM import STEMClassifier
>>> from xgboost import XGBClassifier
>>> model = STEMClassifier(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=25,
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/STEM.py
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 |
|
STEMRegressor
Bases: AdaSTEMRegressor
STEM model Regressor interface (allow fixed grid size)
Parents
stemflow.model.AdaSTEM.AdaSTEMRegressor
Children
None
Example:
>>> from stemflow.model.STEM import STEMRegressor
>>> from xgboost import XGBRegressor
>>> model = STEMRegressor(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=25,
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/STEM.py
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 |
|