stemflow.model.static_func_AdaSTEM
This file is to store static functions for multi-processing
assign_points_to_one_ensemble(ensemble, ensemble_df, Sample_ST_df, Temporal1, Spatio1, Spatio2, feature_importances_)
assign points to one ensemble
Parameters:
-
ensemble_df
(DataFrame
) –ensemble_df
-
ensemble
(str
) –name of the ensemble
-
Sample_ST_df
(DataFrame
) –input sample spatio-temporal points of interest
-
Temporal1
(str
) –Temporal variable name 1
-
Spatio1
(str
) –Spatio variable name 1
-
Spatio2
(str
) –Spatio variable name 2
-
feature_importances_
(DataFrame
) –feature_importances_ dataframe
Returns:
-
DataFrame
–A DataFrame containing the aggregated feature importance
Source code in stemflow/model/static_func_AdaSTEM.py
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 |
|
assign_points_to_one_ensemble_sphere(ensemble, ensemble_df, Sample_ST_df, Temporal1, Spatio1, Spatio2, feature_importances_, radius=6371)
assign points to one ensemble, for spherical indexing
Parameters:
-
ensemble_df
(DataFrame
) –ensemble_df
-
ensemble
(str
) –name of the ensemble
-
Sample_ST_df
(DataFrame
) –input sample spatio-temporal points of interest
-
Temporal1
(str
) –Temporal variable name 1
-
Spatio1
(str
) –Spatio variable name 1
-
Spatio2
(str
) –Spatio variable name 2
-
feature_importances_
(DataFrame
) –feature_importances_ dataframe
-
radius
(Union[float, int]
, default:6371
) –radius of earth in km
Returns:
-
DataFrame
–A DataFrame containing the aggregated feature importance
Source code in stemflow/model/static_func_AdaSTEM.py
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 |
|
get_model_and_stixel_specific_x_names(model_dict, grid_index, stixel_specific_x_names_dict, x_names)
get_model_and_stixel_specific_x_names
Parameters:
-
model_dict
(dict
) –self.model_dict. Dictionary of trained models.
-
grid_index
(str
) –grid index.
-
stixel_specific_x_names_dict
(dict
) –the stixel_specific_x_names dictionary. Generated after training.
-
x_names
(list
) –Total x_names. All variables.
Returns:
-
Tuple[Union[None, BaseEstimator], list]
–A tuple of (model, stixel_specific_x_names) for this stixel
Source code in stemflow/model/static_func_AdaSTEM.py
get_model_by_name(model_dict, grid_index)
get_model_by_name
Parameters:
-
model_dict
(dict
) –self.model_dict. Dictionary of trained models.
-
grid_index
(str
) –grid index
Returns:
-
Union[None, BaseEstimator]
–The trained model.
Source code in stemflow/model/static_func_AdaSTEM.py
get_stixel_specific_name_by_model(model, stixel_specific_x_names_dict, x_names, grid_index)
get_stixel_specific_name_by_model
Parameters:
-
model
(Union[None, BaseEstimator]
) –model of this stixel
-
stixel_specific_x_names_dict
(dict
) –the stixel_specific_x_names dictionary. Generated after training.
-
x_names
(list
) –total x_names. All variables.
-
grid_index
(str
) –grid index.
Returns:
-
Union[None, list]
–stixel specific x_names.
Source code in stemflow/model/static_func_AdaSTEM.py
predict_one_stixel(X_test_stixel, task, model_x_names_tuple, **base_model_prediction_param)
predict_one_stixel
Parameters:
-
X_test_stixel
(DataFrame
) –Input testing variables
-
task
(str
) –One of 'regression', 'classification' and 'hurdle'
-
model_x_names_tuple
(tuple[Union[None, BaseEstimator], list]
) –A tuple of (model, stixel_specific_x_names)
-
base_model_prediction_param
–Additional parameter passed to base_model.predict_proba or base_model.predict
Returns:
-
DataFrame
–A Dataframe of predicted results. With 'index' the same as the input indexes.
Source code in stemflow/model/static_func_AdaSTEM.py
train_one_stixel(stixel_training_size_threshold, x_names, task, base_model, sample_weights_for_classifier, subset_x_names, stixel_X_train, min_class_sample)
Train one stixel
Parameters:
-
stixel_training_size_threshold
(int
) –Only stixels with data points above this threshold are trained.
-
x_names
(Union[list, ndarray]
) –Total x_names. Predictor variable.s
-
task
(str
) –One of 'regression', 'classification' and 'hurdle'
-
base_model
(BaseEstimator
) –Base model estimator.
-
sample_weights_for_classifier
(bool
) –Whether to balance the sample weights in classifier for imbalanced samples.
-
subset_x_names
(bool
) –Whether to only store variables with std > 0 for each stixel.
-
sub_X_train
(DataFrame
) –Input training dataframe for THE stixel.
-
min_class_sample
(int
) –Minimum umber of samples needed to train the classifier in each stixel. If the sample does not satisfy, fit a dummy one.
Returns:
-
Tuple[Union[None, BaseEstimator], list]
–tuple[Union[None, BaseEstimator], list]: trained_model, stixel_specific_x_names
Source code in stemflow/model/static_func_AdaSTEM.py
transform_pred_set_to_STEM_quad(Spatio1, Spatio2, X_train, ensemble_info)
Project the input data points to the space of quadtree stixels.
Parameters:
-
Spatio1
(str
) –Name of the spatio column 1
-
Spatio2
(str
) –Name of the spatio column 2
-
X_train
(DataFrame
) –Training/Testing variables
-
ensemble_info
(DataFrame
) –the DataFrame with information of the stixel.
Returns:
-
DataFrame
–Projected X_train
Source code in stemflow/model/static_func_AdaSTEM.py
transform_pred_set_to_Sphere_STEM_quad(Spatio1, Spatio2, X_train, ensemble_info, radius=6371.0)
Project the input data points to the space of quadtree stixels. For spherical indexing.
Parameters:
-
Spatio1
(str
) –Name of the spatio column 1
-
Spatio2
(str
) –Name of the spatio column 2
-
X_train
(DataFrame
) –Training/Testing variables
-
ensemble_info
(DataFrame
) –the DataFrame with information of the stixel.
Returns:
-
DataFrame
–Projected X_train