ilovetools 0.1.4__py3-none-any.whl → 0.1.5__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.
- ilovetools/__init__.py +1 -1
- ilovetools/ml/__init__.py +97 -1
- ilovetools/ml/cross_validation.py +612 -0
- ilovetools/ml/metrics.py +43 -31
- ilovetools/ml/tuning.py +781 -0
- {ilovetools-0.1.4.dist-info → ilovetools-0.1.5.dist-info}/METADATA +1 -1
- {ilovetools-0.1.4.dist-info → ilovetools-0.1.5.dist-info}/RECORD +10 -8
- {ilovetools-0.1.4.dist-info → ilovetools-0.1.5.dist-info}/WHEEL +0 -0
- {ilovetools-0.1.4.dist-info → ilovetools-0.1.5.dist-info}/licenses/LICENSE +0 -0
- {ilovetools-0.1.4.dist-info → ilovetools-0.1.5.dist-info}/top_level.txt +0 -0
ilovetools/ml/metrics.py
CHANGED
|
@@ -16,7 +16,11 @@ __all__ = [
|
|
|
16
16
|
'mean_absolute_error',
|
|
17
17
|
'root_mean_squared_error',
|
|
18
18
|
'r2_score',
|
|
19
|
-
'roc_auc_score'
|
|
19
|
+
'roc_auc_score',
|
|
20
|
+
# Aliases
|
|
21
|
+
'mse',
|
|
22
|
+
'mae',
|
|
23
|
+
'rmse',
|
|
20
24
|
]
|
|
21
25
|
|
|
22
26
|
|
|
@@ -331,6 +335,8 @@ def mean_squared_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
331
335
|
"""
|
|
332
336
|
Calculate Mean Squared Error for regression.
|
|
333
337
|
|
|
338
|
+
Alias: mse()
|
|
339
|
+
|
|
334
340
|
MSE = Average of (actual - predicted)^2
|
|
335
341
|
|
|
336
342
|
Args:
|
|
@@ -341,25 +347,23 @@ def mean_squared_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
341
347
|
float: MSE value
|
|
342
348
|
|
|
343
349
|
Examples:
|
|
344
|
-
>>> from ilovetools.ml import
|
|
350
|
+
>>> from ilovetools.ml import mse # Short alias
|
|
345
351
|
|
|
346
352
|
# Perfect predictions
|
|
347
353
|
>>> y_true = [1.0, 2.0, 3.0, 4.0]
|
|
348
354
|
>>> y_pred = [1.0, 2.0, 3.0, 4.0]
|
|
349
|
-
>>>
|
|
355
|
+
>>> mse(y_true, y_pred)
|
|
350
356
|
0.0
|
|
351
357
|
|
|
352
358
|
# With errors
|
|
353
359
|
>>> y_true = [100, 200, 300, 400]
|
|
354
360
|
>>> y_pred = [110, 190, 310, 390]
|
|
355
|
-
>>>
|
|
356
|
-
>>> print(f"MSE: {
|
|
361
|
+
>>> error = mse(y_true, y_pred)
|
|
362
|
+
>>> print(f"MSE: {error:.2f}")
|
|
357
363
|
MSE: 100.00
|
|
358
364
|
|
|
359
|
-
#
|
|
360
|
-
>>>
|
|
361
|
-
>>> predicted_prices = [245000, 310000, 340000]
|
|
362
|
-
>>> mse = mean_squared_error(actual_prices, predicted_prices)
|
|
365
|
+
>>> from ilovetools.ml import mean_squared_error # Full name
|
|
366
|
+
>>> error = mean_squared_error(y_true, y_pred)
|
|
363
367
|
|
|
364
368
|
Notes:
|
|
365
369
|
- Penalizes large errors heavily
|
|
@@ -374,10 +378,16 @@ def mean_squared_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
374
378
|
return sum(squared_errors) / len(squared_errors)
|
|
375
379
|
|
|
376
380
|
|
|
381
|
+
# Create alias
|
|
382
|
+
mse = mean_squared_error
|
|
383
|
+
|
|
384
|
+
|
|
377
385
|
def mean_absolute_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
378
386
|
"""
|
|
379
387
|
Calculate Mean Absolute Error for regression.
|
|
380
388
|
|
|
389
|
+
Alias: mae()
|
|
390
|
+
|
|
381
391
|
MAE = Average of |actual - predicted|
|
|
382
392
|
|
|
383
393
|
Args:
|
|
@@ -388,27 +398,23 @@ def mean_absolute_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
388
398
|
float: MAE value
|
|
389
399
|
|
|
390
400
|
Examples:
|
|
391
|
-
>>> from ilovetools.ml import
|
|
401
|
+
>>> from ilovetools.ml import mae # Short alias
|
|
392
402
|
|
|
393
403
|
# Perfect predictions
|
|
394
404
|
>>> y_true = [1.0, 2.0, 3.0, 4.0]
|
|
395
405
|
>>> y_pred = [1.0, 2.0, 3.0, 4.0]
|
|
396
|
-
>>>
|
|
406
|
+
>>> mae(y_true, y_pred)
|
|
397
407
|
0.0
|
|
398
408
|
|
|
399
409
|
# With errors
|
|
400
410
|
>>> y_true = [100, 200, 300, 400]
|
|
401
411
|
>>> y_pred = [110, 190, 310, 390]
|
|
402
|
-
>>>
|
|
403
|
-
>>> print(f"MAE: ${
|
|
412
|
+
>>> error = mae(y_true, y_pred)
|
|
413
|
+
>>> print(f"MAE: ${error:.2f}")
|
|
404
414
|
MAE: $10.00
|
|
405
415
|
|
|
406
|
-
#
|
|
407
|
-
>>>
|
|
408
|
-
>>> predicted_prices = [245000, 310000, 340000]
|
|
409
|
-
>>> mae = mean_absolute_error(actual_prices, predicted_prices)
|
|
410
|
-
>>> print(f"Average error: ${mae:,.0f}")
|
|
411
|
-
Average error: $8,333
|
|
416
|
+
>>> from ilovetools.ml import mean_absolute_error # Full name
|
|
417
|
+
>>> error = mean_absolute_error(y_true, y_pred)
|
|
412
418
|
|
|
413
419
|
Notes:
|
|
414
420
|
- Easy to interpret
|
|
@@ -423,10 +429,16 @@ def mean_absolute_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
423
429
|
return sum(absolute_errors) / len(absolute_errors)
|
|
424
430
|
|
|
425
431
|
|
|
432
|
+
# Create alias
|
|
433
|
+
mae = mean_absolute_error
|
|
434
|
+
|
|
435
|
+
|
|
426
436
|
def root_mean_squared_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
427
437
|
"""
|
|
428
438
|
Calculate Root Mean Squared Error for regression.
|
|
429
439
|
|
|
440
|
+
Alias: rmse()
|
|
441
|
+
|
|
430
442
|
RMSE = sqrt(MSE)
|
|
431
443
|
|
|
432
444
|
Args:
|
|
@@ -437,27 +449,23 @@ def root_mean_squared_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
437
449
|
float: RMSE value
|
|
438
450
|
|
|
439
451
|
Examples:
|
|
440
|
-
>>> from ilovetools.ml import
|
|
452
|
+
>>> from ilovetools.ml import rmse # Short alias
|
|
441
453
|
|
|
442
454
|
# Perfect predictions
|
|
443
455
|
>>> y_true = [1.0, 2.0, 3.0, 4.0]
|
|
444
456
|
>>> y_pred = [1.0, 2.0, 3.0, 4.0]
|
|
445
|
-
>>>
|
|
457
|
+
>>> rmse(y_true, y_pred)
|
|
446
458
|
0.0
|
|
447
459
|
|
|
448
460
|
# With errors
|
|
449
461
|
>>> y_true = [100, 200, 300, 400]
|
|
450
462
|
>>> y_pred = [110, 190, 310, 390]
|
|
451
|
-
>>>
|
|
452
|
-
>>> print(f"RMSE: {
|
|
463
|
+
>>> error = rmse(y_true, y_pred)
|
|
464
|
+
>>> print(f"RMSE: {error:.2f}")
|
|
453
465
|
RMSE: 10.00
|
|
454
466
|
|
|
455
|
-
#
|
|
456
|
-
>>>
|
|
457
|
-
>>> predicted_prices = [245000, 310000, 340000]
|
|
458
|
-
>>> rmse = root_mean_squared_error(actual_prices, predicted_prices)
|
|
459
|
-
>>> print(f"RMSE: ${rmse:,.0f}")
|
|
460
|
-
RMSE: $8,165
|
|
467
|
+
>>> from ilovetools.ml import root_mean_squared_error # Full name
|
|
468
|
+
>>> error = root_mean_squared_error(y_true, y_pred)
|
|
461
469
|
|
|
462
470
|
Notes:
|
|
463
471
|
- Most common regression metric
|
|
@@ -465,8 +473,12 @@ def root_mean_squared_error(y_true: List[float], y_pred: List[float]) -> float:
|
|
|
465
473
|
- Penalizes large errors
|
|
466
474
|
- Lower is better
|
|
467
475
|
"""
|
|
468
|
-
|
|
469
|
-
return
|
|
476
|
+
mse_value = mean_squared_error(y_true, y_pred)
|
|
477
|
+
return mse_value ** 0.5
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
# Create alias
|
|
481
|
+
rmse = root_mean_squared_error
|
|
470
482
|
|
|
471
483
|
|
|
472
484
|
def r2_score(y_true: List[float], y_pred: List[float]) -> float:
|