metacountregressor 0.1.93__py3-none-any.whl → 0.1.98__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: metacountregressor
3
- Version: 0.1.93
3
+ Version: 0.1.98
4
4
  Summary: Extensions for a Python package for estimation of count models.
5
5
  Home-page: https://github.com/zahern/CountDataEstimation
6
6
  Author: Zeke Ahern
@@ -274,6 +274,8 @@ Let's begin by fitting very simple models and use the structure of these models
274
274
 
275
275
 
276
276
  ```python
277
+
278
+ '''Setup Data'''
277
279
  df = pd.read_csv(
278
280
  "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
279
281
  X = df
@@ -281,25 +283,158 @@ y = df['FREQ'] # Frequency of crashes
281
283
  X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
282
284
  # Drop Y, selected offset term and ID as there are no panels
283
285
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
284
-
286
+ '''Aguments for Solution'''
285
287
  arguments = {
286
- 'algorithm': 'hs', #alternatively input 'de', or 'sa'
287
- 'is_multi': 1,
288
+ 'is_multi': 1, #is two objectives considered
288
289
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
289
290
  'val_percentage:': 0.2, # Saves 20% of data for testing.
290
291
  'test_complexity': 3, # For Very simple Models
291
292
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
292
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
293
+ 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
293
294
  'distribution': ['Normal'],
294
- 'Model': [0], # or equivalently ['POS', 'NB']
295
+ 'Model': [0, 1], # or equivalently ['POS', 'NB']
295
296
  'transformations': ['no', 'sqrt', 'archsinh'],
296
297
  '_max_time': 10000
297
- }
298
+ } '''Arguments for the solution algorithm'''
299
+ argument_hs = {
300
+ '_hms': 20, #harmony memory size,
301
+ '_mpai': 1, #adjustement inded
302
+ '_par': 0.3,
303
+ '_hmcr': .5
304
+ }
298
305
  obj_fun = ObjectiveFunction(X, y, **arguments)
299
- results = harmony_search(obj_fun)
306
+ results = harmony_search(obj_fun, None, argument_hs)
300
307
  print(results)
301
308
  ```
302
309
 
310
+ ## Example: Assistance by Differential Evololution and Simulated Annealing
311
+ Similiar to the above example we only need to change the hyperparamaters, the obj_fun can remane the same
312
+
313
+
314
+ ```python
315
+ argument_de = {'_AI': 2,
316
+ '_crossover_perc': .2,
317
+ '_max_iter': 1000,
318
+ '_pop_size': 25
319
+ }
320
+ de_results = differential_evolution(obj_fun, None, **argument_de)
321
+ print(de_results)
322
+
323
+
324
+ args_sa = {'alpha': .99,
325
+ 'STEPS_PER_TEMP': 10,
326
+ 'INTL_ACPT': 0.5,
327
+ '_crossover_perc': .3,
328
+ 'MAX_ITERATIONS': 1000,
329
+ '_num_intl_slns': 25,
330
+ }
331
+
332
+ sa_results = simulated_annealing(obj_fun, None, **args_sa)
333
+ print(sa_results)
334
+ ```
335
+
336
+ ## Comparing to statsmodels
337
+ The following example illustrates how the output compares to well-known packages, including Statsmodels."
338
+
339
+
340
+ ```python
341
+ # Load modules and data
342
+ import statsmodels.api as sm
343
+
344
+ data = sm.datasets.sunspots.load_pandas().data
345
+ #print(data.exog)
346
+ data_exog = data['YEAR']
347
+ data_exog = sm.add_constant(data_exog)
348
+ data_endog = data['SUNACTIVITY']
349
+
350
+ # Instantiate a gamma family model with the default link function.
351
+ import numpy as np
352
+
353
+ gamma_model = sm.NegativeBinomial(data_endog, data_exog)
354
+ gamma_results = gamma_model.fit()
355
+
356
+ print(gamma_results.summary())
357
+
358
+
359
+
360
+
361
+ #NOW LET's COMPARE THIS TO METACOUNTREGRESSOR
362
+
363
+
364
+
365
+
366
+ #Model Decisions,
367
+ manual_fit_spec = {
368
+ 'fixed_terms': ['const','YEAR'],
369
+ 'rdm_terms': [],
370
+ 'rdm_cor_terms': [],
371
+ 'grouped_terms': [],
372
+ 'hetro_in_means': [],
373
+ 'transformations': ['no', 'no'],
374
+ 'dispersion': 1 #Negative Binomial
375
+ }
376
+
377
+
378
+ #Arguments
379
+ arguments = {
380
+ 'algorithm': 'hs',
381
+ 'test_percentage': 0,
382
+ 'test_complexity': 6,
383
+ 'instance_number': 'name',
384
+ 'Manual_Fit': manual_fit_spec
385
+ }
386
+ obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+ ```
395
+
396
+ Optimization terminated successfully.
397
+ Current function value: 4.877748
398
+ Iterations: 22
399
+ Function evaluations: 71
400
+ Gradient evaluations: 70
401
+ NegativeBinomial Regression Results
402
+ ==============================================================================
403
+ Dep. Variable: SUNACTIVITY No. Observations: 309
404
+ Model: NegativeBinomial Df Residuals: 307
405
+ Method: MLE Df Model: 1
406
+ Date: Tue, 13 Aug 2024 Pseudo R-squ.: 0.004087
407
+ Time: 14:13:22 Log-Likelihood: -1507.2
408
+ converged: True LL-Null: -1513.4
409
+ Covariance Type: nonrobust LLR p-value: 0.0004363
410
+ ==============================================================================
411
+ coef std err z P>|z| [0.025 0.975]
412
+ ------------------------------------------------------------------------------
413
+ const 0.2913 1.017 0.287 0.774 -1.701 2.284
414
+ YEAR 0.0019 0.001 3.546 0.000 0.001 0.003
415
+ alpha 0.7339 0.057 12.910 0.000 0.622 0.845
416
+ ==============================================================================
417
+ 0.1.88
418
+ Setup Complete...
419
+ Benchmaking test with Seed 42
420
+ 1
421
+ --------------------------------------------------------------------------------
422
+ Log-Likelihood: -1509.0683662284273
423
+ --------------------------------------------------------------------------------
424
+ bic: 3035.84
425
+ --------------------------------------------------------------------------------
426
+ MSE: 10000000.00
427
+ +--------+--------+-------+----------+----------+------------+
428
+ | Effect | $\tau$ | Coeff | Std. Err | z-values | Prob |z|>Z |
429
+ +========+========+=======+==========+==========+============+
430
+ | const | no | 0.10 | 0.25 | 0.39 | 0.70 |
431
+ +--------+--------+-------+----------+----------+------------+
432
+ | YEAR | no | 0.00 | 0.00 | 20.39 | 0.00*** |
433
+ +--------+--------+-------+----------+----------+------------+
434
+ | nb | | 1.33 | 0.00 | 50.00 | 0.00*** |
435
+ +--------+--------+-------+----------+----------+------------+
436
+
437
+
303
438
  ## Paper
304
439
 
305
440
  The following tutorial is in conjunction with our latest paper. A link the current paper can be found here [MetaCountRegressor](https://www.overleaf.com/read/mszwpwzcxsng#c5eb0c)
@@ -12,8 +12,8 @@ metacountregressor/setup.py,sha256=8w6IqX0tJsbYrOI1BJLIJCIvOnunKli5I9fsF5PhHv4,9
12
12
  metacountregressor/single_objective_finder.py,sha256=jVG7GJBqzSP4_riYr-kMMKy_LE3SlGmKMunNhHYxgRg,8011
13
13
  metacountregressor/solution.py,sha256=wigjQ4tJrMS0EvbzmRMb2JRT7s0guvPdpCXRwEWUGQg,266891
14
14
  metacountregressor/test_generated_paper2.py,sha256=pwOoRzl1jJIIOUAAvbkT6HmmTQ81mwpsshn9SLdKOg8,3927
15
- metacountregressor-0.1.93.dist-info/LICENSE.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
16
- metacountregressor-0.1.93.dist-info/METADATA,sha256=lxko7pOT-xFIpuqN3cUYr9hF3SIWszwVmGcfASHysOY,18165
17
- metacountregressor-0.1.93.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
18
- metacountregressor-0.1.93.dist-info/top_level.txt,sha256=zGG7UC5WIpr76gsFUpwJ4En2aCcoNTONBaS3OewwjR0,19
19
- metacountregressor-0.1.93.dist-info/RECORD,,
15
+ metacountregressor-0.1.98.dist-info/LICENSE.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
16
+ metacountregressor-0.1.98.dist-info/METADATA,sha256=B3xPXQpSXnvAQjJ6O1aXhum9TGgq55Lg148A7TvTWZ4,22685
17
+ metacountregressor-0.1.98.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
18
+ metacountregressor-0.1.98.dist-info/top_level.txt,sha256=zGG7UC5WIpr76gsFUpwJ4En2aCcoNTONBaS3OewwjR0,19
19
+ metacountregressor-0.1.98.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (72.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5