dquant 1.2.0__tar.gz → 1.2.1__tar.gz
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.
- {dquant-1.2.0/src/DQuant.egg-info → dquant-1.2.1}/PKG-INFO +1 -1
- {dquant-1.2.0 → dquant-1.2.1}/pyproject.toml +1 -1
- {dquant-1.2.0 → dquant-1.2.1/src/DQuant.egg-info}/PKG-INFO +1 -1
- {dquant-1.2.0 → dquant-1.2.1}/src/dquant/models.py +97 -305
- {dquant-1.2.0 → dquant-1.2.1}/src/dquant/visual.py +3 -9
- {dquant-1.2.0 → dquant-1.2.1}/LICENSE +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/README.md +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/setup.cfg +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/DQuant.egg-info/SOURCES.txt +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/DQuant.egg-info/dependency_links.txt +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/DQuant.egg-info/requires.txt +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/DQuant.egg-info/top_level.txt +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/__init__.py +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/dquant/__init__.py +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/dquant/get_data.py +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/src/dquant/metrics.py +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/test/test.py +0 -0
- {dquant-1.2.0 → dquant-1.2.1}/test/test_load.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dquant
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: DQuant is an open-source Python library for automated volatility forecasting of financial time series. It handles all stages of model construction, from raw prices to the final forecast.
|
|
5
5
|
Author: Denis Makarov
|
|
6
6
|
Project-URL: Homepage, https://dquant.space
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dquant
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: DQuant is an open-source Python library for automated volatility forecasting of financial time series. It handles all stages of model construction, from raw prices to the final forecast.
|
|
5
5
|
Author: Denis Makarov
|
|
6
6
|
Project-URL: Homepage, https://dquant.space
|
|
@@ -33,7 +33,6 @@ class FichEn:
|
|
|
33
33
|
eps = 1e-8
|
|
34
34
|
y_pred = np.clip(y_pred, eps, None)
|
|
35
35
|
|
|
36
|
-
# Градиент (оставляем истинный)
|
|
37
36
|
grad = 1.0 / y_pred - y_true / (y_pred ** 2)
|
|
38
37
|
|
|
39
38
|
hess_approx = 1.0 / (y_pred ** 2)
|
|
@@ -44,16 +43,13 @@ class FichEn:
|
|
|
44
43
|
if self.output == False:
|
|
45
44
|
return
|
|
46
45
|
if file is None:
|
|
47
|
-
file = sys.stdout
|
|
46
|
+
file = sys.stdout
|
|
48
47
|
|
|
49
|
-
# Преобразуем все аргументы в строки и соединяем через sep
|
|
50
48
|
output = sep.join(str(arg) for arg in args)
|
|
51
|
-
output += end
|
|
49
|
+
output += end
|
|
52
50
|
|
|
53
|
-
# Записываем в файловый объект
|
|
54
51
|
file.write(output)
|
|
55
52
|
|
|
56
|
-
# Принудительно сбрасываем буфер, если нужно
|
|
57
53
|
if flush:
|
|
58
54
|
file.flush()
|
|
59
55
|
|
|
@@ -71,7 +67,7 @@ class FichEn:
|
|
|
71
67
|
|
|
72
68
|
for col in required:
|
|
73
69
|
if col not in data.columns:
|
|
74
|
-
raise ValueError(f"
|
|
70
|
+
raise ValueError(f"Column '{col}' is not found")
|
|
75
71
|
|
|
76
72
|
raw_windows_X = []
|
|
77
73
|
raw_windows_y = []
|
|
@@ -95,13 +91,12 @@ class FichEn:
|
|
|
95
91
|
|
|
96
92
|
for col in required:
|
|
97
93
|
if col not in data.columns:
|
|
98
|
-
raise ValueError(f"
|
|
94
|
+
raise ValueError(f"Column '{col}' is not found")
|
|
99
95
|
|
|
100
96
|
feature_list_final = []
|
|
101
97
|
single_feature_list_final = []
|
|
102
98
|
single_feature_dict = {}
|
|
103
99
|
|
|
104
|
-
# Сначала рассчитываем TR, так как он нужен для ATR
|
|
105
100
|
if 'TR' in feature_list or any(f.startswith('atr_') for f in feature_list) or any(
|
|
106
101
|
f.startswith('roll_atr_') for f in feature_list):
|
|
107
102
|
prev_close = data['close'].shift(1).fillna(data['close'])
|
|
@@ -145,7 +140,6 @@ class FichEn:
|
|
|
145
140
|
feature_list_final.append(i)
|
|
146
141
|
|
|
147
142
|
elif i == 'abs_returns':
|
|
148
|
-
# Используем уже рассчитанные returns
|
|
149
143
|
if 'returns' in data.columns:
|
|
150
144
|
data[i] = data['returns'].abs()
|
|
151
145
|
else:
|
|
@@ -265,7 +259,7 @@ class FichEn:
|
|
|
265
259
|
f'Not enough data to calculate BB: max BB period is {len(close_values)} and yours {window}')
|
|
266
260
|
sma = close_values.mean()
|
|
267
261
|
std = close_values.std()
|
|
268
|
-
single_feature_dict[f'bb_{window}'] = (4 * std) / (sma + epsilon)
|
|
262
|
+
single_feature_dict[f'bb_{window}'] = (4 * std) / (sma + epsilon)
|
|
269
263
|
single_feature_list_final.append(f'bb_{window}')
|
|
270
264
|
|
|
271
265
|
elif i[:9] == 'roll_rsi_':
|
|
@@ -316,7 +310,7 @@ class FichEn:
|
|
|
316
310
|
window = int(window)
|
|
317
311
|
sma = data['close'].rolling(window=window, min_periods=window).mean()
|
|
318
312
|
std = data['close'].rolling(window=window, min_periods=window).std()
|
|
319
|
-
data[f'roll_bb_{window}'] = (4 * std) / (sma + epsilon)
|
|
313
|
+
data[f'roll_bb_{window}'] = (4 * std) / (sma + epsilon)
|
|
320
314
|
feature_list_final.append(f'roll_bb_{window}')
|
|
321
315
|
|
|
322
316
|
else:
|
|
@@ -327,14 +321,6 @@ class FichEn:
|
|
|
327
321
|
|
|
328
322
|
data = data.fillna(0)
|
|
329
323
|
|
|
330
|
-
"""feature_vector = []
|
|
331
|
-
for i in range(1, len(data)):
|
|
332
|
-
for feat in existing_features:
|
|
333
|
-
feature_vector.append(data[feat].iloc[i])
|
|
334
|
-
|
|
335
|
-
for i in single_feature_list_final:
|
|
336
|
-
feature_vector.append(single_feature_dict[i])"""
|
|
337
|
-
|
|
338
324
|
feature_vector = data[existing_features].iloc[1:].to_numpy(dtype=np.float64).ravel()
|
|
339
325
|
single_vals = np.array([single_feature_dict[f] for f in single_feature_list_final], dtype=np.float64)
|
|
340
326
|
feature_vector = np.concatenate([feature_vector, single_vals])
|
|
@@ -352,20 +338,7 @@ class FichEn:
|
|
|
352
338
|
|
|
353
339
|
for col in required:
|
|
354
340
|
if col not in data.columns:
|
|
355
|
-
raise ValueError(f"
|
|
356
|
-
|
|
357
|
-
"""tr_values = []
|
|
358
|
-
|
|
359
|
-
for i in range(1, len(data)):
|
|
360
|
-
if i == 0:
|
|
361
|
-
tr = (data['high'].iloc[i] - data['low'].iloc[i]) / data['close'].iloc[i]
|
|
362
|
-
else:
|
|
363
|
-
hl = data['high'].iloc[i] - data['low'].iloc[i]
|
|
364
|
-
hc = abs(data['high'].iloc[i] - data['close'].iloc[i - 1])
|
|
365
|
-
lc = abs(data['low'].iloc[i] - data['close'].iloc[i - 1])
|
|
366
|
-
tr = max(hl/data['close'].iloc[i], hc/data['close'].iloc[i], lc/data['close'].iloc[i])
|
|
367
|
-
|
|
368
|
-
tr_values.append(tr)"""
|
|
341
|
+
raise ValueError(f"Column '{col}' is not found")
|
|
369
342
|
|
|
370
343
|
high = data['high']
|
|
371
344
|
low = data['low']
|
|
@@ -419,35 +392,32 @@ class FichEn:
|
|
|
419
392
|
bar = '█' * filled_chars + '░' * (50 - filled_chars)
|
|
420
393
|
time_per = time.time() - startt
|
|
421
394
|
if percent < 10:
|
|
422
|
-
self.dquantprint(f'\
|
|
395
|
+
self.dquantprint(f'\rData preparation: |{bar}| {percent:.2f}% {time_per*(lx-i):.2f} seconds left', end='', flush=True)
|
|
423
396
|
elif percent >= 10 and percent < 100:
|
|
424
|
-
self.dquantprint(f'\
|
|
397
|
+
self.dquantprint(f'\rData preparation: |{bar}| {percent:.2f}% {time_per*(lx-i):.2f} seconds left', end='', flush=True)
|
|
425
398
|
else:
|
|
426
|
-
self.dquantprint(f'\
|
|
399
|
+
self.dquantprint(f'\rData preparation: |{bar}| {percent:.2f}% {time_per*(lx-i):.2f} seconds left', end='', flush=True)
|
|
427
400
|
|
|
428
401
|
self.dquantprint()
|
|
429
402
|
x = np.array(XX)
|
|
430
403
|
y = np.array(YY)
|
|
431
404
|
|
|
432
|
-
|
|
433
|
-
train_window_size = input_bars # сколько последних окон использовать для обучения
|
|
434
|
-
# Минимальный индекс, с которого можно начинать валидацию (должен быть >= train_window_size)
|
|
405
|
+
train_window_size = input_bars
|
|
435
406
|
start_val_idx = train_window_size
|
|
436
407
|
|
|
437
408
|
total_iterations = len(x) - start_val_idx
|
|
438
409
|
if total_iterations <= 0:
|
|
439
|
-
raise ValueError(f"
|
|
410
|
+
raise ValueError(f"Too little data: total windows {len(x)}, and train_window_size={train_window_size}")
|
|
440
411
|
|
|
441
|
-
self.dquantprint(f"
|
|
442
|
-
self.dquantprint(f"
|
|
443
|
-
self.dquantprint(f"
|
|
412
|
+
self.dquantprint(f"Total windows: {len(x)}")
|
|
413
|
+
self.dquantprint(f"Training window size: {train_window_size}")
|
|
414
|
+
self.dquantprint(f"Validation steps: {total_iterations}")
|
|
444
415
|
|
|
445
416
|
all_train_errors = []
|
|
446
417
|
all_val_errors = []
|
|
447
418
|
all_train_r2 = []
|
|
448
419
|
all_val_r2 = []
|
|
449
420
|
|
|
450
|
-
# horizon может быть числом или списком, приведём к списку индексов
|
|
451
421
|
if isinstance(horizon, int):
|
|
452
422
|
horizon_list = list(range(horizon))
|
|
453
423
|
else:
|
|
@@ -457,16 +427,15 @@ class FichEn:
|
|
|
457
427
|
start_it = time.time()
|
|
458
428
|
iter_num = val_idx - start_val_idx + 1
|
|
459
429
|
|
|
460
|
-
# === Обучающая выборка: последние train_window_size окон перед val_idx ===
|
|
461
430
|
train_indices = list(range(val_idx - train_window_size, val_idx))
|
|
462
431
|
X_train = x[train_indices]
|
|
463
432
|
y_train = y[train_indices]
|
|
464
433
|
|
|
465
|
-
# ===
|
|
466
|
-
X_val = x[val_idx:val_idx + 1] #
|
|
467
|
-
y_val_true = y[val_idx] #
|
|
434
|
+
# === Validation window ===
|
|
435
|
+
X_val = x[val_idx:val_idx + 1] # form (1, n_features)
|
|
436
|
+
y_val_true = y[val_idx] # form (horizon,)
|
|
468
437
|
|
|
469
|
-
# ===
|
|
438
|
+
# === Normalization ===
|
|
470
439
|
scaler_X = StandardScaler()
|
|
471
440
|
scaler_y_local = StandardScaler()
|
|
472
441
|
|
|
@@ -475,46 +444,40 @@ class FichEn:
|
|
|
475
444
|
|
|
476
445
|
X_val_scaled = scaler_X.transform(X_val)
|
|
477
446
|
|
|
478
|
-
# ===
|
|
447
|
+
# === training for each horizon ===
|
|
479
448
|
model_ex = self.base_model.__class__(**self.base_model.get_params())
|
|
480
449
|
model_ex.set_params(n_estimators=trees)
|
|
481
450
|
models_temp = []
|
|
482
451
|
for h_idx in horizon_list:
|
|
483
452
|
if h_idx >= y_train_scaled.shape[1]:
|
|
484
|
-
continue
|
|
453
|
+
continue
|
|
485
454
|
|
|
486
455
|
y_h = y_train_scaled[:, h_idx]
|
|
487
456
|
|
|
488
|
-
# Создаём модель с параметрами, как у self.base_model
|
|
489
457
|
model = model_ex
|
|
490
|
-
# При желании можно задать n_estimators из self.trees_count, но для чистоты
|
|
491
|
-
# walk-forward оставим обучение до конца (или фиксированное число деревьев).
|
|
492
|
-
# Если нужен early_stopping по числу деревьев - можно добавить.
|
|
493
458
|
model.fit(X_train_scaled, y_h)
|
|
494
459
|
models_temp.append(model)
|
|
495
460
|
|
|
496
|
-
# ===
|
|
497
|
-
# На тренировочных данных
|
|
461
|
+
# === Foracesting train ===
|
|
498
462
|
train_preds_list = []
|
|
499
463
|
for model in models_temp:
|
|
500
464
|
train_preds_list.append(model.predict(X_train_scaled))
|
|
501
465
|
train_preds = np.column_stack(train_preds_list) # (train_windows, horizon)
|
|
502
466
|
|
|
503
|
-
#
|
|
467
|
+
# Forecasting on validation data
|
|
504
468
|
val_preds_list = []
|
|
505
469
|
for model in models_temp:
|
|
506
470
|
val_preds_list.append(model.predict(X_val_scaled))
|
|
507
471
|
val_preds = np.array(val_preds_list).flatten() # (horizon,)
|
|
508
472
|
|
|
509
|
-
|
|
473
|
+
|
|
510
474
|
y_train_inv = scaler_y_local.inverse_transform(y_train_scaled)
|
|
511
475
|
train_preds_inv = scaler_y_local.inverse_transform(train_preds)
|
|
512
476
|
|
|
513
|
-
y_val_true_inv = y_val_true
|
|
477
|
+
y_val_true_inv = y_val_true
|
|
514
478
|
val_preds_inv = scaler_y_local.inverse_transform(val_preds.reshape(1, -1)).flatten()
|
|
515
479
|
|
|
516
|
-
# ===
|
|
517
|
-
# Усредняем MSE по всем горизонтам
|
|
480
|
+
# === Metrics ===
|
|
518
481
|
train_error = mean_squared_error(y_train_inv.flatten(), train_preds_inv.flatten())
|
|
519
482
|
val_error = mean_squared_error(y_val_true_inv, val_preds_inv)
|
|
520
483
|
train_r2 = r2_score(y_train_inv.flatten(), train_preds_inv.flatten())
|
|
@@ -525,7 +488,7 @@ class FichEn:
|
|
|
525
488
|
all_train_r2.append(train_r2)
|
|
526
489
|
all_val_r2.append(val_r2)
|
|
527
490
|
|
|
528
|
-
# ===
|
|
491
|
+
# === Progress bar ===
|
|
529
492
|
percent = (iter_num / total_iterations) * 100
|
|
530
493
|
filled = int(percent / 2)
|
|
531
494
|
bar = '█' * filled + '░' * (50 - filled)
|
|
@@ -533,11 +496,11 @@ class FichEn:
|
|
|
533
496
|
f'\rWalk-Forward: |{bar}| {percent:.1f}% - Iteration {iter_num}/{total_iterations} - Val MSE: {val_error:.6f} - need time: {(time.time()-start_it)*(total_iterations-iter_num)} seconds',
|
|
534
497
|
end='', flush=True)
|
|
535
498
|
|
|
536
|
-
|
|
537
|
-
self.dquantprint(f"
|
|
538
|
-
self.dquantprint(f"
|
|
539
|
-
self.dquantprint(f"
|
|
540
|
-
self.dquantprint(f"
|
|
499
|
+
|
|
500
|
+
self.dquantprint(f"Mean validation error (MSE): {np.mean(all_val_errors):.6f} +/- {np.std(all_val_errors):.6f}")
|
|
501
|
+
self.dquantprint(f"Mean validation R²: {np.mean(all_val_r2):.4f} +/- {np.std(all_val_r2):.4f}")
|
|
502
|
+
self.dquantprint(f"Maximum validation error: {np.max(all_val_errors):.6f}")
|
|
503
|
+
self.dquantprint(f"Minimum validation error: {np.min(all_val_errors):.6f}")
|
|
541
504
|
if show_results:
|
|
542
505
|
self.V.forward_validation_errors(all_val_errors, all_val_r2)
|
|
543
506
|
return
|
|
@@ -571,7 +534,6 @@ class FichEn:
|
|
|
571
534
|
else:
|
|
572
535
|
window_targets = target_func(y[i])
|
|
573
536
|
|
|
574
|
-
#self.dquantprint(len(window_features))
|
|
575
537
|
XX.append(window_features)
|
|
576
538
|
YY.append(window_targets)
|
|
577
539
|
|
|
@@ -580,11 +542,11 @@ class FichEn:
|
|
|
580
542
|
bar = '█' * filled_chars + '░' * (50 - filled_chars)
|
|
581
543
|
time_per = time.time() - startt
|
|
582
544
|
if percent < 10:
|
|
583
|
-
self.dquantprint(f'\
|
|
545
|
+
self.dquantprint(f'\rData preparation: |{bar}| {percent:.2f}% {time_per*(lx-i):.2f} seconds left', end='', flush=True)
|
|
584
546
|
elif percent >= 10 and percent < 100:
|
|
585
|
-
self.dquantprint(f'\
|
|
547
|
+
self.dquantprint(f'\rData preparation: |{bar}| {percent:.2f}% {time_per*(lx-i):.2f} seconds left', end='', flush=True)
|
|
586
548
|
else:
|
|
587
|
-
self.dquantprint(f'\
|
|
549
|
+
self.dquantprint(f'\rData preparation: |{bar}| {percent:.2f}% {time_per*(lx-i):.2f} seconds left', end='', flush=True)
|
|
588
550
|
|
|
589
551
|
self.dquantprint()
|
|
590
552
|
self.dquantprint("time spended: ", time.time() - start_)
|
|
@@ -627,11 +589,10 @@ class FichEn:
|
|
|
627
589
|
horizon_list = list(range(horizon))
|
|
628
590
|
else:
|
|
629
591
|
horizon_list = horizon
|
|
630
|
-
|
|
631
|
-
if len(Y_scaled.shape) == 2 and Y_scaled.shape[1] > 1:
|
|
592
|
+
if len(Y_scaled.shape) == 2 and Y_scaled.shape[1] > 0:
|
|
632
593
|
for h_idx, h in enumerate(horizon_list):
|
|
633
594
|
if h_idx >= Y_scaled.shape[1]:
|
|
634
|
-
self.dquantprint(f"
|
|
595
|
+
self.dquantprint(f"Warning: horizon {h} extends beyond y, skipping")
|
|
635
596
|
continue
|
|
636
597
|
|
|
637
598
|
y_h = Y_scaled.iloc[:, h_idx] if hasattr(Y_scaled, 'iloc') else Y_scaled[:, h_idx]
|
|
@@ -704,10 +665,10 @@ class FichEn:
|
|
|
704
665
|
self.dquantprint('Validation MSE: ', var_val_error)
|
|
705
666
|
self.dquantprint('Train r2: ', var_test_r2)
|
|
706
667
|
self.dquantprint('Validation r2: ', var_val_r2)
|
|
707
|
-
self.dquantprint(f"
|
|
668
|
+
self.dquantprint(f"{time.time() - start} seconds spent")
|
|
708
669
|
|
|
709
670
|
except KeyboardInterrupt:
|
|
710
|
-
self.dquantprint("\
|
|
671
|
+
self.dquantprint("\nTraining interrupted by Ctrl+C!")
|
|
711
672
|
|
|
712
673
|
if show_results:
|
|
713
674
|
self.V.show_errors(self.train_errors, self.val_errors, self.train_r2, self.val_r2)
|
|
@@ -724,7 +685,7 @@ class FichEn:
|
|
|
724
685
|
X = feature_func(latest_data)
|
|
725
686
|
|
|
726
687
|
if not self.is_fitted and not self.onnx_load:
|
|
727
|
-
raise ValueError("
|
|
688
|
+
raise ValueError("The model is not trained yet!")
|
|
728
689
|
|
|
729
690
|
if self.onnx_load:
|
|
730
691
|
predictions = []
|
|
@@ -743,20 +704,15 @@ class FichEn:
|
|
|
743
704
|
|
|
744
705
|
pred_array = np.array(predictions)
|
|
745
706
|
|
|
746
|
-
# ИСПРАВЛЕНИЕ ЗДЕСЬ:
|
|
747
707
|
if pred_array.ndim == 1:
|
|
748
|
-
# Для одного сэмпла с 30 таргетами: (30,) -> (1, 30)
|
|
749
708
|
pred_array = pred_array.reshape(1, -1)
|
|
750
709
|
elif pred_array.ndim == 2:
|
|
751
710
|
if pred_array.shape[0] == 1 and pred_array.shape[1] == 30:
|
|
752
|
-
# Уже правильно (1, 30) - ничего не делаем
|
|
753
711
|
pass
|
|
754
712
|
elif pred_array.shape[0] == 30 and pred_array.shape[1] == 1:
|
|
755
|
-
# Неправильная форма (30, 1) -> (1, 30)
|
|
756
713
|
pred_array = pred_array.T
|
|
757
714
|
elif pred_array.shape[0] > 1 and pred_array.shape[1] == 30:
|
|
758
|
-
|
|
759
|
-
pred_array = pred_array[0:1, :] # Берем первую модель
|
|
715
|
+
pred_array = pred_array[0:1, :]
|
|
760
716
|
predictions = self.scaler_y.inverse_transform(pred_array).flatten()
|
|
761
717
|
|
|
762
718
|
if show:
|
|
@@ -792,20 +748,15 @@ class FichEn:
|
|
|
792
748
|
|
|
793
749
|
pred_array = np.array(predictions)
|
|
794
750
|
|
|
795
|
-
# ИСПРАВЛЕНИЕ ЗДЕСЬ:
|
|
796
751
|
if pred_array.ndim == 1:
|
|
797
|
-
# Для одного сэмпла с 30 таргетами: (30,) -> (1, 30)
|
|
798
752
|
pred_array = pred_array.reshape(1, -1)
|
|
799
753
|
elif pred_array.ndim == 2:
|
|
800
754
|
if pred_array.shape[0] == 1 and pred_array.shape[1] == 30:
|
|
801
|
-
# Уже правильно (1, 30) - ничего не делаем
|
|
802
755
|
pass
|
|
803
756
|
elif pred_array.shape[0] == 30 and pred_array.shape[1] == 1:
|
|
804
|
-
# Неправильная форма (30, 1) -> (1, 30)
|
|
805
757
|
pred_array = pred_array.T
|
|
806
758
|
elif pred_array.shape[0] > 1 and pred_array.shape[1] == 30:
|
|
807
|
-
|
|
808
|
-
pred_array = pred_array[0:1, :] # Берем первую модель
|
|
759
|
+
pred_array = pred_array[0:1, :]
|
|
809
760
|
predictions = self.scaler_y.inverse_transform(pred_array).flatten()
|
|
810
761
|
|
|
811
762
|
if show:
|
|
@@ -835,7 +786,6 @@ class FichEn:
|
|
|
835
786
|
scaler_data = {
|
|
836
787
|
"mean": self.scaler.mean_.tolist() if self.scaler.mean_ is not None else [],
|
|
837
788
|
"std": self.scaler.scale_.tolist() if self.scaler.scale_ is not None else [],
|
|
838
|
-
# scale_ = стандартное отклонение
|
|
839
789
|
"var": self.scaler.var_.tolist() if self.scaler.var_ is not None else []
|
|
840
790
|
}
|
|
841
791
|
mean_str = ','.join(str(x) for x in scaler_data['mean'])
|
|
@@ -844,7 +794,6 @@ class FichEn:
|
|
|
844
794
|
scaler_data_y = {
|
|
845
795
|
"mean": self.scaler_y.mean_.tolist() if self.scaler_y.mean_ is not None else [],
|
|
846
796
|
"std": self.scaler_y.scale_.tolist() if self.scaler_y.scale_ is not None else [],
|
|
847
|
-
# scale_ = стандартное отклонение
|
|
848
797
|
"var": self.scaler_y.var_.tolist() if self.scaler_y.var_ is not None else []
|
|
849
798
|
}
|
|
850
799
|
mean_str_y = ','.join(str(x) for x in scaler_data_y['mean'])
|
|
@@ -852,14 +801,12 @@ class FichEn:
|
|
|
852
801
|
|
|
853
802
|
|
|
854
803
|
os.makedirs(name, exist_ok=True)
|
|
855
|
-
self.dquantprint(f"
|
|
804
|
+
self.dquantprint(f"Directory '{name}' has been created or already exists")
|
|
856
805
|
|
|
857
|
-
# 2. Создаём папку для ONNX файлов
|
|
858
806
|
onnx_dir = os.path.join(name, f"{name}_onnx")
|
|
859
807
|
os.makedirs(onnx_dir, exist_ok=True)
|
|
860
808
|
|
|
861
|
-
|
|
862
|
-
mq5_file_path = os.path.join(name, f"{name}.mq5") # Изменено с .mql5 на .mq5
|
|
809
|
+
mq5_file_path = os.path.join(name, f"{name}.mq5")
|
|
863
810
|
with open(mq5_file_path, "w", encoding="utf-8") as f:
|
|
864
811
|
f.write("//+------------------------------------------------------------------+\n")
|
|
865
812
|
f.write(f"//| {name}.mq5 |\n")
|
|
@@ -914,10 +861,9 @@ class FichEn:
|
|
|
914
861
|
f.write(f' model_handle{i} = OnnxCreateFromBuffer(ExtModelData{i}, ONNX_USE_CPU_ONLY);\n')
|
|
915
862
|
f.write(f' if (model_handle{i} == INVALID_HANDLE)\n')
|
|
916
863
|
f.write(' {\n')
|
|
917
|
-
f.write(f' Print("
|
|
864
|
+
f.write(f' Print("Error loading ONNX model {i}: ", GetLastError());\n')
|
|
918
865
|
f.write(' return INIT_FAILED;\n')
|
|
919
866
|
f.write(' }\n')
|
|
920
|
-
# f.write(f' Print("ONNX-модель {i} успешно загружена");\n\n')
|
|
921
867
|
|
|
922
868
|
f.write(' return(INIT_SUCCEEDED);\n')
|
|
923
869
|
f.write('}\n\n')
|
|
@@ -1419,7 +1365,6 @@ class FichEn:
|
|
|
1419
1365
|
f.write(' return true;\n')
|
|
1420
1366
|
f.write('}\n\n')
|
|
1421
1367
|
|
|
1422
|
-
# GetForecast function
|
|
1423
1368
|
f.write('//+------------------------------------------------------------------+\n')
|
|
1424
1369
|
f.write('//| Get forecast from ONNX model |\n')
|
|
1425
1370
|
f.write('//+------------------------------------------------------------------+\n')
|
|
@@ -1455,9 +1400,8 @@ class FichEn:
|
|
|
1455
1400
|
f.write(' }\n')
|
|
1456
1401
|
f.write('}\n\n')
|
|
1457
1402
|
|
|
1458
|
-
self.dquantprint(f"
|
|
1403
|
+
self.dquantprint(f"File {mq5_file_path} created successfully")
|
|
1459
1404
|
|
|
1460
|
-
# 4. Создаём файл проекта MQL5 (.mqproj)
|
|
1461
1405
|
proj_file_path = os.path.join(name, f"{name}.mqproj")
|
|
1462
1406
|
with open(proj_file_path, "w", encoding="utf-8-sig") as f:
|
|
1463
1407
|
f.write('{\n')
|
|
@@ -1490,7 +1434,7 @@ class FichEn:
|
|
|
1490
1434
|
f.write(' ]\n')
|
|
1491
1435
|
f.write('}\n')
|
|
1492
1436
|
|
|
1493
|
-
self.dquantprint(f"
|
|
1437
|
+
self.dquantprint(f"File {proj_file_path} created successfully")
|
|
1494
1438
|
|
|
1495
1439
|
|
|
1496
1440
|
|
|
@@ -1564,36 +1508,35 @@ class VolClustGB(FichEn):
|
|
|
1564
1508
|
self.save_mql5(name)
|
|
1565
1509
|
onnx_dir = os.path.join(name, f"{name}_onnx")
|
|
1566
1510
|
os.makedirs(onnx_dir, exist_ok=True)
|
|
1567
|
-
self.dquantprint(f"
|
|
1511
|
+
self.dquantprint(f"Directory for ONNX files created: {onnx_dir}")
|
|
1568
1512
|
|
|
1569
|
-
# 4. Сохраняем модели и scaler в поддиректорию
|
|
1570
1513
|
initial_type = [('float_input', FloatTensorType([None, self.X_shape]))]
|
|
1571
1514
|
|
|
1572
1515
|
if hasattr(self, 'scaler') and self.scaler is not None:
|
|
1573
1516
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler.pkl")
|
|
1574
1517
|
joblib.dump(self.scaler, scaler_path)
|
|
1575
|
-
self.dquantprint(f"Scaler
|
|
1518
|
+
self.dquantprint(f"Scaler is saved in {scaler_path}")
|
|
1576
1519
|
|
|
1577
1520
|
if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1578
1521
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler_y.pkl")
|
|
1579
1522
|
joblib.dump(self.scaler_y, scaler_path)
|
|
1580
|
-
self.dquantprint(f"Scalery
|
|
1523
|
+
self.dquantprint(f"Scalery is saved in {scaler_path}")
|
|
1581
1524
|
|
|
1582
1525
|
for i in range(len(self.models)):
|
|
1583
1526
|
onx = convert_sklearn(self.models[i], initial_types=initial_type, target_opset=12)
|
|
1584
1527
|
file_path = os.path.join(onnx_dir, f"{name}_{i}.onnx")
|
|
1585
1528
|
with open(file_path, "wb") as f:
|
|
1586
1529
|
f.write(onx.SerializeToString())
|
|
1587
|
-
self.dquantprint(f"
|
|
1530
|
+
self.dquantprint(f"Model {i} is saved in {file_path}")
|
|
1588
1531
|
|
|
1589
|
-
self.dquantprint(f"
|
|
1532
|
+
self.dquantprint(f"All operations in directory '{name}' completed successfully!")
|
|
1590
1533
|
|
|
1591
1534
|
|
|
1592
1535
|
def load(self, name):
|
|
1593
1536
|
self.loaded_models = []
|
|
1594
1537
|
|
|
1595
1538
|
if not os.path.exists(name):
|
|
1596
|
-
raise FileNotFoundError(f"
|
|
1539
|
+
raise FileNotFoundError(f"Directory {name} not found")
|
|
1597
1540
|
|
|
1598
1541
|
try:
|
|
1599
1542
|
file_path = os.path.join(name, f"{name}_features.json")
|
|
@@ -1627,7 +1570,7 @@ class VolClustGB(FichEn):
|
|
|
1627
1570
|
model_files = [f for f in os.listdir(name) if f.endswith('.onnx')]
|
|
1628
1571
|
|
|
1629
1572
|
if not model_files:
|
|
1630
|
-
raise FileNotFoundError(f"
|
|
1573
|
+
raise FileNotFoundError(f"No .onnx files found in directory {name}")
|
|
1631
1574
|
|
|
1632
1575
|
model_files.sort()
|
|
1633
1576
|
ml = len(model_files)
|
|
@@ -1666,16 +1609,20 @@ class VolClustXGB(FichEn):
|
|
|
1666
1609
|
self.onnx_load = False
|
|
1667
1610
|
self.early_stopping = early_stopping
|
|
1668
1611
|
self.V = Visualization('dark')
|
|
1669
|
-
# qlike_obj
|
|
1670
1612
|
self.default_sett = {
|
|
1671
|
-
#'objective': 'reg:squarederror',
|
|
1672
1613
|
'learning_rate': 0.1,
|
|
1673
|
-
'
|
|
1674
|
-
'max_depth': 3,
|
|
1614
|
+
'max_depth': 6,
|
|
1675
1615
|
'min_child_weight': 5,
|
|
1616
|
+
'gamma': 0.1,
|
|
1676
1617
|
'subsample': 0.8,
|
|
1677
|
-
'
|
|
1618
|
+
'colsample_bytree': 0.8,
|
|
1619
|
+
'reg_alpha': 0.0,
|
|
1620
|
+
'reg_lambda': 1.0,
|
|
1621
|
+
'random_state': 42,
|
|
1622
|
+
'tree_method': 'hist',
|
|
1623
|
+
'device': 'cpu'
|
|
1678
1624
|
}
|
|
1625
|
+
|
|
1679
1626
|
if qlike == False:
|
|
1680
1627
|
self.default_sett['objective'] = 'reg:squarederror'
|
|
1681
1628
|
|
|
@@ -1689,7 +1636,10 @@ class VolClustXGB(FichEn):
|
|
|
1689
1636
|
else:
|
|
1690
1637
|
self.base_model = xgboost.XGBRegressor(**self.default_sett)
|
|
1691
1638
|
else:
|
|
1692
|
-
|
|
1639
|
+
try:
|
|
1640
|
+
if sett['objective']: del sett['objective']
|
|
1641
|
+
except KeyError:
|
|
1642
|
+
pass
|
|
1693
1643
|
if qlike:
|
|
1694
1644
|
self.base_model = xgboost.XGBRegressor(**sett, objective=self.qlike_obj)
|
|
1695
1645
|
else:
|
|
@@ -1733,28 +1683,27 @@ class VolClustXGB(FichEn):
|
|
|
1733
1683
|
self.save_mql5(name)
|
|
1734
1684
|
onnx_dir = os.path.join(name, f"{name}_onnx")
|
|
1735
1685
|
os.makedirs(onnx_dir, exist_ok=True)
|
|
1736
|
-
self.dquantprint(f"
|
|
1686
|
+
self.dquantprint(f"Directory for ONNX files created: {onnx_dir}")
|
|
1737
1687
|
|
|
1738
|
-
# 4. Сохраняем модели и scaler в поддиректорию
|
|
1739
1688
|
initial_type = [('float_input', FloatTensorType([None, self.X_shape]))]
|
|
1740
1689
|
|
|
1741
1690
|
if hasattr(self, 'scaler') and self.scaler is not None:
|
|
1742
1691
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler.pkl")
|
|
1743
1692
|
joblib.dump(self.scaler, scaler_path)
|
|
1744
|
-
self.dquantprint(f"Scaler
|
|
1693
|
+
self.dquantprint(f"Scaler is saved in {scaler_path}")
|
|
1745
1694
|
|
|
1746
1695
|
if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1747
1696
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler_y.pkl")
|
|
1748
1697
|
joblib.dump(self.scaler_y, scaler_path)
|
|
1749
|
-
self.dquantprint(f"Scalery
|
|
1698
|
+
self.dquantprint(f"Scalery is saved in {scaler_path}")
|
|
1750
1699
|
|
|
1751
1700
|
for i in range(len(self.models)):
|
|
1752
1701
|
onx = onnxmltools.convert_xgboost(self.models[i], initial_types=initial_type, target_opset=9)
|
|
1753
1702
|
model_path = os.path.join(onnx_dir, f"{name}_{i}.onnx")
|
|
1754
1703
|
onnxmltools.utils.save_model(onx, model_path)
|
|
1755
|
-
self.dquantprint(f"
|
|
1704
|
+
self.dquantprint(f"Model {i} is saved in {model_path}")
|
|
1756
1705
|
|
|
1757
|
-
self.dquantprint(f"
|
|
1706
|
+
self.dquantprint(f"All operations in directory '{name}' completed successfully!")
|
|
1758
1707
|
|
|
1759
1708
|
|
|
1760
1709
|
|
|
@@ -1762,7 +1711,7 @@ class VolClustXGB(FichEn):
|
|
|
1762
1711
|
self.loaded_models = []
|
|
1763
1712
|
|
|
1764
1713
|
if not os.path.exists(name):
|
|
1765
|
-
raise FileNotFoundError(f"
|
|
1714
|
+
raise FileNotFoundError(f"Directory {name} not found")
|
|
1766
1715
|
|
|
1767
1716
|
try:
|
|
1768
1717
|
file_path = os.path.join(name, f"{name}_features.json")
|
|
@@ -1796,7 +1745,7 @@ class VolClustXGB(FichEn):
|
|
|
1796
1745
|
model_files = [f for f in os.listdir(name) if f.endswith('.onnx')]
|
|
1797
1746
|
|
|
1798
1747
|
if not model_files:
|
|
1799
|
-
raise FileNotFoundError(f"
|
|
1748
|
+
raise FileNotFoundError(f"No .onnx files found in directory {name}")
|
|
1800
1749
|
|
|
1801
1750
|
model_files.sort()
|
|
1802
1751
|
ml = len(model_files)
|
|
@@ -1834,13 +1783,21 @@ class VolClustLightGBM(FichEn):
|
|
|
1834
1783
|
self.early_stopping = early_stopping
|
|
1835
1784
|
self.V = Visualization('dark')
|
|
1836
1785
|
self.default_sett = {
|
|
1837
|
-
'num_leaves': 7,
|
|
1838
|
-
'min_data_in_leaf': 3,
|
|
1839
|
-
'min_data_in_bin': 3,
|
|
1840
1786
|
'learning_rate': 0.1,
|
|
1787
|
+
'max_depth': 6,
|
|
1788
|
+
'num_leaves': 2**6 - 1,
|
|
1789
|
+
'min_child_samples': 5,
|
|
1790
|
+
'min_split_gain': 0.1,
|
|
1791
|
+
'bagging_fraction': 0.8,
|
|
1792
|
+
'bagging_freq': 1,
|
|
1793
|
+
'feature_fraction': 0.8,
|
|
1794
|
+
'reg_alpha': 0.0,
|
|
1795
|
+
'reg_lambda': 1.0,
|
|
1796
|
+
'random_state': 42,
|
|
1841
1797
|
'verbosity': -1,
|
|
1842
|
-
'
|
|
1798
|
+
'boosting_type': 'gbdt'
|
|
1843
1799
|
}
|
|
1800
|
+
|
|
1844
1801
|
if qlike == False:
|
|
1845
1802
|
self.default_sett['objective'] = 'regression'
|
|
1846
1803
|
|
|
@@ -1854,7 +1811,10 @@ class VolClustLightGBM(FichEn):
|
|
|
1854
1811
|
else:
|
|
1855
1812
|
self.base_model = lgb.LGBMRegressor(**self.default_sett)
|
|
1856
1813
|
else:
|
|
1857
|
-
|
|
1814
|
+
try:
|
|
1815
|
+
if sett['objective']: del sett['objective']
|
|
1816
|
+
except KeyError:
|
|
1817
|
+
pass
|
|
1858
1818
|
if qlike:
|
|
1859
1819
|
self.base_model = lgb.LGBMRegressor(**sett, objective=self.qlike_obj)
|
|
1860
1820
|
else:
|
|
@@ -1898,36 +1858,35 @@ class VolClustLightGBM(FichEn):
|
|
|
1898
1858
|
self.save_mql5(name)
|
|
1899
1859
|
onnx_dir = os.path.join(name, f"{name}_onnx")
|
|
1900
1860
|
os.makedirs(onnx_dir, exist_ok=True)
|
|
1901
|
-
self.dquantprint(f"
|
|
1861
|
+
self.dquantprint(f"Directory for ONNX files created: {onnx_dir}")
|
|
1902
1862
|
|
|
1903
|
-
# 4. Сохраняем модели и scaler в поддиректорию
|
|
1904
1863
|
initial_type = [('float_input', FloatTensorType([None, self.X_shape]))]
|
|
1905
1864
|
|
|
1906
1865
|
if hasattr(self, 'scaler') and self.scaler is not None:
|
|
1907
1866
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler.pkl")
|
|
1908
1867
|
joblib.dump(self.scaler, scaler_path)
|
|
1909
|
-
self.dquantprint(f"Scaler
|
|
1868
|
+
self.dquantprint(f"Scaler is saved in {scaler_path}")
|
|
1910
1869
|
|
|
1911
1870
|
if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1912
1871
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler_y.pkl")
|
|
1913
1872
|
joblib.dump(self.scaler_y, scaler_path)
|
|
1914
|
-
self.dquantprint(f"Scalery
|
|
1873
|
+
self.dquantprint(f"Scalery is saved in {scaler_path}")
|
|
1915
1874
|
|
|
1916
1875
|
for i in range(len(self.models)):
|
|
1917
1876
|
onx = onnxmltools.convert_lightgbm(self.models[i], initial_types=initial_type, zipmap=False,
|
|
1918
1877
|
target_opset=12)
|
|
1919
1878
|
file_path = os.path.join(onnx_dir, f"{name}_{i}.onnx")
|
|
1920
1879
|
onnxmltools.utils.save_model(onx, file_path)
|
|
1921
|
-
self.dquantprint(f"
|
|
1880
|
+
self.dquantprint(f"Model {i} is saved in {file_path}")
|
|
1922
1881
|
|
|
1923
|
-
self.dquantprint(f"
|
|
1882
|
+
self.dquantprint(f"All operations in directory '{name}' completed successfully!")
|
|
1924
1883
|
|
|
1925
1884
|
|
|
1926
1885
|
def load(self, name):
|
|
1927
1886
|
self.loaded_models = []
|
|
1928
1887
|
|
|
1929
1888
|
if not os.path.exists(name):
|
|
1930
|
-
raise FileNotFoundError(f"
|
|
1889
|
+
raise FileNotFoundError(f"Directory {name} not found")
|
|
1931
1890
|
|
|
1932
1891
|
try:
|
|
1933
1892
|
file_path = os.path.join(name, f"{name}_features.json")
|
|
@@ -1961,7 +1920,7 @@ class VolClustLightGBM(FichEn):
|
|
|
1961
1920
|
model_files = [f for f in os.listdir(name) if f.endswith('.onnx')]
|
|
1962
1921
|
|
|
1963
1922
|
if not model_files:
|
|
1964
|
-
raise FileNotFoundError(f"
|
|
1923
|
+
raise FileNotFoundError(f"No .onnx files found in directory {name}")
|
|
1965
1924
|
|
|
1966
1925
|
model_files.sort()
|
|
1967
1926
|
ml = len(model_files)
|
|
@@ -1985,170 +1944,3 @@ class VolClustLightGBM(FichEn):
|
|
|
1985
1944
|
self.loaded_models.append(session)
|
|
1986
1945
|
|
|
1987
1946
|
self.onnx_load = True
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
"""
|
|
1991
|
-
time spended: 65.44393944740295
|
|
1992
|
-
[ 1.00901477e-02 6.06840734e-03 7.89991808e-03 2.40415813e-03
|
|
1993
|
-
1.30973943e-04 2.53802438e-03 7.55212328e-03 6.40525625e-01
|
|
1994
|
-
0.00000000e+00 2.81739978e-02 1.71405577e-02 7.20318643e-03
|
|
1995
|
-
2.66850655e-02 1.37758612e-05 2.63183893e-02 1.85560851e-03
|
|
1996
|
-
9.53905366e-01 0.00000000e+00 4.29736387e-02 2.55626153e-02
|
|
1997
|
-
2.36549673e-02 2.80319922e-02 -3.03892649e-04 2.81246929e-02
|
|
1998
|
-
1.48489457e-02 2.72801986e-01 0.00000000e+00 3.72218795e-02
|
|
1999
|
-
2.20329899e-02 1.21903154e-02 3.24872375e-02 1.21786687e-04
|
|
2000
|
-
3.31424959e-02 4.07938359e-03 1.05498777e-01 0.00000000e+00
|
|
2001
|
-
7.37316373e-02 4.32737643e-02 3.21723278e-02 5.74076879e-02
|
|
2002
|
-
-3.87169703e-04 5.87003299e-02 1.50313074e-02 1.78512223e-01
|
|
2003
|
-
0.00000000e+00 4.04910463e-02 2.44025016e-02 2.97286458e-02
|
|
2004
|
-
4.09296639e-03 5.20381594e-04 4.62173561e-03 3.58693107e-02
|
|
2005
|
-
5.82791094e-01 0.00000000e+00 4.58374744e-02 2.74720640e-02
|
|
2006
|
-
3.16518085e-02 1.28362178e-02 4.88255628e-04 1.34072113e-02
|
|
2007
|
-
3.24302631e-02 4.51602205e-01 0.00000000e+00 2.04805939e-02
|
|
2008
|
-
1.21755897e-02 1.55781241e-02 8.44683596e-03 -1.44448658e-04
|
|
2009
|
-
8.33816248e-03 1.21424314e-02 0.00000000e+00 0.00000000e+00
|
|
2010
|
-
2.98493845e-02 1.78514990e-02 2.09793890e-02 4.31824090e-03
|
|
2011
|
-
2.91972368e-05 4.35677518e-03 2.54926093e-02 3.56991113e-01
|
|
2012
|
-
0.00000000e+00 4.38209920e-02 2.67519393e-02 1.94066006e-02
|
|
2013
|
-
3.52507396e-02 9.13841081e-05 3.45452848e-02 9.27570718e-03
|
|
2014
|
-
8.67142706e-01 0.00000000e+00 2.23729157e-02 1.34131927e-02
|
|
2015
|
-
1.50097284e-02 9.27476481e-03 -4.87292988e-04 8.83061573e-03
|
|
2016
|
-
1.35423000e-02 4.21120863e-01 0.00000000e+00 1.49549846e-02
|
|
2017
|
-
8.95837170e-03 1.02428690e-02 3.70974367e-03 8.63321678e-05
|
|
2018
|
-
3.80296545e-03 1.11520191e-02 3.26991207e-01 0.00000000e+00
|
|
2019
|
-
4.26058712e-02 2.58258056e-02 1.75734110e-02 3.62848420e-02
|
|
2020
|
-
5.55038464e-04 3.50793990e-02 7.30531730e-03 8.35520105e-01
|
|
2021
|
-
0.00000000e+00 1.48660486e-02 8.95036835e-03 9.96263886e-03
|
|
2022
|
-
4.81100437e-03 -4.97779422e-05 4.84922797e-03 1.00168207e-02
|
|
2023
|
-
6.67079520e-01 0.00000000e+00 3.05811410e-02 1.81291235e-02
|
|
2024
|
-
1.35250294e-02 2.35798305e-02 -1.06096226e-04 2.37539365e-02
|
|
2025
|
-
6.82720443e-03 7.05013333e-02 0.00000000e+00 9.97877681e-02
|
|
2026
|
-
5.71429634e-02 9.93251430e-03 9.43035288e-02 -2.15592232e-04
|
|
2027
|
-
9.86776488e-02 1.11011933e-03 3.53888733e-03 0.00000000e+00
|
|
2028
|
-
6.15493679e-02 3.69277996e-02 4.30480571e-02 2.30142933e-02
|
|
2029
|
-
3.82434298e-04 2.36635998e-02 3.78857681e-02 4.78877653e-01
|
|
2030
|
-
0.00000000e+00 4.07323827e-02 2.42627809e-02 3.03729349e-02
|
|
2031
|
-
1.75768508e-03 -1.89331202e-04 1.56989951e-03 3.91624832e-02
|
|
2032
|
-
2.94759703e-01 0.00000000e+00 3.89312610e-02 2.37273964e-02
|
|
2033
|
-
3.48261445e-02 2.14988488e-04 4.55482200e-05 1.69417160e-04
|
|
2034
|
-
3.87618438e-02 8.72129781e-01 0.00000000e+00 6.17359291e-01
|
|
2035
|
-
2.93932853e-01 1.08930483e-01 4.64730175e-01 4.39776373e-04
|
|
2036
|
-
5.92024459e-01 2.53348322e-02 3.59865231e-02 0.00000000e+00
|
|
2037
|
-
3.11147546e-01 2.11229224e-01 2.60957183e-01 1.12686222e-01
|
|
2038
|
-
8.45532816e-03 9.81137169e-02 2.13033829e-01 8.41486709e-01
|
|
2039
|
-
0.00000000e+00 9.61773087e-02 5.59225605e-02 4.42007214e-02
|
|
2040
|
-
6.75355700e-02 1.80191261e-03 7.16702268e-02 2.45070819e-02
|
|
2041
|
-
1.50546410e-01 0.00000000e+00 1.23761654e-01 7.29214118e-02
|
|
2042
|
-
9.68913447e-02 3.62457326e-02 1.29941148e-04 3.54667798e-02
|
|
2043
|
-
8.82948742e-02 3.34199130e-01 0.00000000e+00 1.62919592e-01
|
|
2044
|
-
9.78764618e-02 1.22212154e-01 7.26450577e-02 -1.41299781e-03
|
|
2045
|
-
7.39357846e-02 8.75708093e-02 5.42211975e-01 0.00000000e+00
|
|
2046
|
-
7.45248895e-02 4.52017387e-02 4.64108595e-02 4.12455257e-02
|
|
2047
|
-
-2.27759272e-03 4.26840965e-02 3.18407930e-02 6.25823123e-01
|
|
2048
|
-
0.00000000e+00 5.01099799e-02 3.03195942e-02 3.68273961e-02
|
|
2049
|
-
2.44820439e-03 2.83362114e-04 2.16184786e-03 4.79481321e-02
|
|
2050
|
-
6.44204942e-01 0.00000000e+00 1.76503480e-01 1.13815750e-01
|
|
2051
|
-
6.65450214e-02 1.67104324e-01 1.12708932e-03 1.52761574e-01
|
|
2052
|
-
2.37419066e-02 8.73218209e-01 0.00000000e+00 1.57850455e-01
|
|
2053
|
-
9.26514801e-02 1.13630263e-01 1.22445001e-03 7.43594102e-05
|
|
2054
|
-
1.14934127e-03 1.56701114e-01 3.40320281e-01 0.00000000e+00
|
|
2055
|
-
7.19979354e-02 4.34659656e-02 5.21177072e-02 2.21448508e-03
|
|
2056
|
-
1.25191284e-03 3.46885170e-03 6.85290837e-02 5.66441411e-01
|
|
2057
|
-
0.00000000e+00 9.19313837e-02 5.28749679e-02 4.98083731e-02
|
|
2058
|
-
5.90770239e-02 8.43358015e-05 6.09412847e-02 3.09900990e-02
|
|
2059
|
-
1.22037653e-02 0.00000000e+00 1.02696046e-01 6.47826521e-02
|
|
2060
|
-
3.54393880e-02 9.57832377e-02 1.74497187e-04 9.11645446e-02
|
|
2061
|
-
1.15315016e-02 9.58084134e-01 0.00000000e+00 5.61199048e-02
|
|
2062
|
-
3.44009941e-02 2.49703201e-02 4.84447086e-02 3.01829683e-03
|
|
2063
|
-
4.42716886e-02 1.18482162e-02 8.56546369e-01 0.00000000e+00
|
|
2064
|
-
5.32228122e-02 3.18107827e-02 3.69621168e-02 8.01155994e-03
|
|
2065
|
-
5.85698106e-04 8.62943647e-03 4.45933758e-02 4.05350998e-01
|
|
2066
|
-
0.00000000e+00 2.15145177e-02 1.30245089e-02 1.62742830e-02
|
|
2067
|
-
5.28121136e-03 -8.77263769e-04 6.14455405e-03 1.53699637e-02
|
|
2068
|
-
8.68350803e-01 0.00000000e+00 5.05633636e-02 2.96374579e-02
|
|
2069
|
-
2.35973846e-02 3.74133767e-02 4.55768528e-04 3.85778362e-02
|
|
2070
|
-
1.19855274e-02 9.46606724e-03 0.00000000e+00 5.63840947e-02
|
|
2071
|
-
3.33798150e-02 3.34520599e-02 3.58132408e-02 -4.07618484e-04
|
|
2072
|
-
3.60546411e-02 1.99614159e-02 3.55645082e-01 0.00000000e+00
|
|
2073
|
-
5.57884077e-02 3.26136331e-02 7.71543102e-03 5.26502133e-02
|
|
2074
|
-
5.79304149e-04 5.46401883e-02 1.14821941e-03 5.92355248e-03
|
|
2075
|
-
0.00000000e+00 9.54862414e-02 5.94218027e-02 4.00815346e-02
|
|
2076
|
-
8.22684486e-02 5.43653418e-04 7.84316689e-02 1.70545725e-02
|
|
2077
|
-
8.57720697e-01 0.00000000e+00 2.02454145e-02 1.21577151e-02
|
|
2078
|
-
1.43197749e-02 1.36810741e-03 1.18759225e-04 1.24841275e-03
|
|
2079
|
-
1.89970017e-02 4.94675292e-01 0.00000000e+00 6.20877978e-02
|
|
2080
|
-
3.84604802e-02 4.87031762e-02 2.57778032e-02 -2.00581227e-04
|
|
2081
|
-
2.56489734e-02 3.64388244e-02 9.85866990e-01 0.00000000e+00
|
|
2082
|
-
7.24692836e-02 4.32326577e-02 5.50895288e-02 2.78887560e-02
|
|
2083
|
-
0.00000000e+00 2.75034548e-02 4.49658288e-02 4.01572960e-01
|
|
2084
|
-
0.00000000e+00 4.89923950e-02 2.89772392e-02 3.65664667e-02
|
|
2085
|
-
8.90628383e-03 5.60189477e-04 9.50625226e-03 3.94861427e-02
|
|
2086
|
-
1.82037110e-01 0.00000000e+00 2.65697886e-02 1.61453720e-02
|
|
2087
|
-
1.38432176e-02 1.97258038e-02 7.27424183e-04 1.88050990e-02
|
|
2088
|
-
7.76468969e-03 9.37379581e-01 0.00000000e+00 2.46622989e-02
|
|
2089
|
-
1.47933610e-02 1.67767982e-02 1.11868608e-02 -7.34744665e-04
|
|
2090
|
-
1.05149231e-02 1.41473759e-02 4.48996965e-01 0.00000000e+00
|
|
2091
|
-
6.72313405e-02 4.17978961e-02 7.27511817e-03 6.83840155e-02
|
|
2092
|
-
-4.23498691e-04 6.65217268e-02 7.09613790e-04 1.00000000e+00
|
|
2093
|
-
0.00000000e+00 4.05808633e-02 2.40200436e-02 2.87843914e-02
|
|
2094
|
-
1.32013831e-02 2.59571539e-04 1.35484777e-02 2.70323856e-02
|
|
2095
|
-
1.36321339e-01 0.00000000e+00 2.76677447e-02 1.67989744e-02
|
|
2096
|
-
1.27991081e-02 2.17346261e-02 3.91139046e-04 2.11089920e-02
|
|
2097
|
-
6.55875268e-03 8.90965792e-01 0.00000000e+00 2.22339109e-02
|
|
2098
|
-
1.34302943e-02 1.93488183e-02 4.37399798e-03 5.29667003e-04
|
|
2099
|
-
4.91324488e-03 1.73206660e-02 7.57573661e-01 0.00000000e+00
|
|
2100
|
-
7.30232075e-02 4.27061128e-02 2.56072816e-02 6.16526462e-02
|
|
2101
|
-
2.51412998e-04 6.38442505e-02 9.17895698e-03 1.25699176e-01
|
|
2102
|
-
0.00000000e+00 1.98494355e-02 1.19230831e-02 1.40594483e-02
|
|
2103
|
-
9.34113613e-04 2.83895912e-04 1.21844594e-03 1.86309896e-02
|
|
2104
|
-
5.07988653e-01 0.00000000e+00 4.43071401e-02 2.66348271e-02
|
|
2105
|
-
3.08453405e-02 1.61980943e-02 -1.45620908e-04 1.62132316e-02
|
|
2106
|
-
2.80939085e-02 5.18062994e-01 0.00000000e+00 4.42411056e-02
|
|
2107
|
-
2.62008186e-02 3.37862051e-02 1.82479034e-02 -7.99863781e-04
|
|
2108
|
-
1.76155499e-02 2.58256919e-02 5.94497091e-01 0.00000000e+00
|
|
2109
|
-
2.40756419e-02 1.43885928e-02 1.82440682e-02 3.81350856e-04
|
|
2110
|
-
-2.56613507e-04 1.24810073e-04 2.39508318e-02 2.95056894e-01
|
|
2111
|
-
0.00000000e+00 4.44530014e-02 2.61539413e-02 2.34725191e-02
|
|
2112
|
-
2.97129371e-02 4.71806267e-04 3.06305774e-02 1.38224240e-02
|
|
2113
|
-
2.94891979e-02 0.00000000e+00 8.13491945e-02 5.08256128e-02
|
|
2114
|
-
3.51490041e-02 6.90291127e-02 -2.32655230e-04 6.69331464e-02
|
|
2115
|
-
1.44160481e-02 9.69519652e-01 0.00000000e+00 1.64667468e-02
|
|
2116
|
-
9.87202072e-03 1.14533989e-02 2.90152110e-03 -3.54366267e-05
|
|
2117
|
-
2.87029796e-03 1.35964488e-02 3.92401519e-01 0.00000000e+00
|
|
2118
|
-
2.48991200e-02 1.51168312e-02 7.20748225e-03 2.25009020e-02
|
|
2119
|
-
-5.36407562e-04 2.27860523e-02 2.11306769e-03 9.31981961e-01
|
|
2120
|
-
0.00000000e+00 1.57825262e-02 9.43347831e-03 8.63093904e-03
|
|
2121
|
-
9.44698796e-03 4.53071603e-04 9.94482320e-03 5.83770297e-03
|
|
2122
|
-
1.97150369e-01 0.00000000e+00 5.88186630e-02 3.45510576e-02
|
|
2123
|
-
2.67466667e-02 4.37078926e-02 -3.70718529e-04 4.43064339e-02
|
|
2124
|
-
1.45122291e-02 1.14765291e-01 0.00000000e+00 1.45500976e-02
|
|
2125
|
-
8.73308037e-03 1.03194872e-02 2.37642848e-04 -3.16019514e-04
|
|
2126
|
-
7.83484265e-05 1.44717492e-02 4.58307320e-01 0.00000000e+00
|
|
2127
|
-
3.90720635e-02 2.38379593e-02 1.46013508e-02 3.38498125e-02
|
|
2128
|
-
-1.24039168e-04 3.34073566e-02 5.66470690e-03 8.96944072e-01
|
|
2129
|
-
0.00000000e+00 5.52093720e-02 3.38163892e-02 2.62722462e-02
|
|
2130
|
-
4.29733472e-02 5.51653396e-04 4.15114252e-02 1.36979468e-02
|
|
2131
|
-
8.48703084e-01 0.00000000e+00 1.91329742e-02 1.12056766e-02
|
|
2132
|
-
7.58118553e-03 1.61780845e-02 5.90264833e-04 1.54576573e-02
|
|
2133
|
-
3.08505200e-03 8.33624529e-01 0.00000000e+00 1.58114158e-02
|
|
2134
|
-
9.48141355e-03 1.16968974e-02 2.51773978e-03 -5.52143041e-05
|
|
2135
|
-
2.56978724e-03 1.32416286e-02 4.03234229e-01 0.00000000e+00
|
|
2136
|
-
1.81235587e-02 1.09543091e-02 7.99943802e-03 1.44176361e-02
|
|
2137
|
-
2.64490251e-05 1.42877506e-02 3.83580801e-03 8.51084356e-01
|
|
2138
|
-
0.00000000e+00 1.49035498e-02 9.01786107e-03 0.00000000e+00
|
|
2139
|
-
1.49573560e-02 -5.74993747e-05 1.49035498e-02 0.00000000e+00
|
|
2140
|
-
1.00000000e+00 0.00000000e+00 1.07237191e-02 6.46880826e-03
|
|
2141
|
-
9.26255244e-03 1.46866263e-03 1.75372147e-04 1.29221253e-03
|
|
2142
|
-
9.43150654e-03 9.10789689e-01 0.00000000e+00 1.23360969e-01
|
|
2143
|
-
7.83966160e-02 3.67183038e-02 1.19841406e-01 -3.93352924e-05
|
|
2144
|
-
1.12978228e-01 1.03827418e-02 9.34866426e-01 0.00000000e+00
|
|
2145
|
-
1.04797471e-01 6.06890467e-02 8.08996063e-02 1.63219782e-02
|
|
2146
|
-
-3.88998460e-04 1.60669109e-02 8.87305601e-02 1.38085306e-01
|
|
2147
|
-
0.00000000e+00 4.39345720e-02 2.57854018e-02 2.96597192e-02
|
|
2148
|
-
2.35369104e-02 1.60506376e-03 2.16570141e-02 2.12386179e-02
|
|
2149
|
-
5.18074610e-01 0.00000000e+00]
|
|
2150
|
-
[0.02178552 0.03785454 0.03499315 0.02283531 0.04798502 0.08585039
|
|
2151
|
-
0.023324 0.03473237 0.13709623 0.07662905 0.04318881 0.05538318
|
|
2152
|
-
0.05529575 0.05300378 0.03236753 0.04895759 0.0345107 0.03046795
|
|
2153
|
-
0.03755051 0.0754602 ]
|
|
2154
|
-
"""
|
|
@@ -269,7 +269,7 @@ class Visualization:
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
fig.savefig(filename, **save_kwargs)
|
|
272
|
-
print(f"
|
|
272
|
+
print(f"The graph saved as {filename}")
|
|
273
273
|
|
|
274
274
|
def show_vol(self, df, pred, save_path=None):
|
|
275
275
|
fig, ax = self.__create_figure(figsize=(15, 6))
|
|
@@ -299,9 +299,9 @@ class Visualization:
|
|
|
299
299
|
|
|
300
300
|
ax.set_xlim(-1, len(df))
|
|
301
301
|
ax.set_ylim(0, max_bar_height * 1.3)
|
|
302
|
-
ax.set_xlabel('
|
|
302
|
+
ax.set_xlabel('Time')
|
|
303
303
|
ax.set_ylabel('')
|
|
304
|
-
ax.set_title('
|
|
304
|
+
ax.set_title('Volumetric graph')
|
|
305
305
|
|
|
306
306
|
self.__style_axes(ax)
|
|
307
307
|
|
|
@@ -315,10 +315,8 @@ class Visualization:
|
|
|
315
315
|
plt.show()
|
|
316
316
|
|
|
317
317
|
def forward_validation_errors(self, mse_errors, r2_errors, save_path=None):
|
|
318
|
-
# Первый график - MSE Loss
|
|
319
318
|
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))
|
|
320
319
|
|
|
321
|
-
# Первый график - MSE Loss
|
|
322
320
|
ax1.plot(list(mse_errors), label='Train Loss',
|
|
323
321
|
color=self.config['colors']['primary'])
|
|
324
322
|
ax1.set_xlabel('Trees')
|
|
@@ -329,7 +327,6 @@ class Visualization:
|
|
|
329
327
|
self.__style_axes(ax1)
|
|
330
328
|
self.__style_legend(ax1)
|
|
331
329
|
|
|
332
|
-
# Второй график - R² Score
|
|
333
330
|
ax2.plot(list(r2_errors), label='Train R²',
|
|
334
331
|
color=self.config['colors']['primary'])
|
|
335
332
|
|
|
@@ -350,10 +347,8 @@ class Visualization:
|
|
|
350
347
|
|
|
351
348
|
|
|
352
349
|
def show_errors(self, train_errors, val_errors, train_r2, val_r2, save_path=None):
|
|
353
|
-
# Первый график - MSE Loss
|
|
354
350
|
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))
|
|
355
351
|
|
|
356
|
-
# Первый график - MSE Loss
|
|
357
352
|
ax1.plot(list(train_errors), label='Train Loss',
|
|
358
353
|
color=self.config['colors']['primary'])
|
|
359
354
|
ax1.plot(list(val_errors), label='Validation Loss',
|
|
@@ -366,7 +361,6 @@ class Visualization:
|
|
|
366
361
|
self.__style_axes(ax1)
|
|
367
362
|
self.__style_legend(ax1)
|
|
368
363
|
|
|
369
|
-
# Второй график - R² Score
|
|
370
364
|
ax2.plot(list(train_r2), label='Train R²',
|
|
371
365
|
color=self.config['colors']['primary'])
|
|
372
366
|
ax2.plot(list(val_r2), label='Validation R²',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|