From 2dfe5ef1b6eb54a3431610e997682dadeaf8fcc6 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 7 Aug 2018 17:54:05 +0200 Subject: [PATCH] Fix kcross validation --- pywatts/kcross.py | 28 ++++++++++------------------ pywatts/test_kcross_train.py | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/pywatts/kcross.py b/pywatts/kcross.py index f4174b9..dc80205 100644 --- a/pywatts/kcross.py +++ b/pywatts/kcross.py @@ -24,15 +24,8 @@ def split(data, k): bucketsize = int(len(samples) / k) - print(k) - print(len(data)) - print(len(samples)) - print(bucketsize) - # K steps for i in range(k): - eval_dict = [] - train_dict = [] eval_samples = [] train_samples = [] for j in range(k): @@ -41,19 +34,18 @@ def split(data, k): else: train_samples.extend(samples[i*bucketsize:(i+1)*bucketsize]) - for s in eval_samples: - # Create new dictionaries in the eval lists - X_eval.append({'dc': s[:-1]}) - y_eval.append({'dc': s[-1]}) + # Create new dictionaries in the eval lists + X_eval.append({'dc': eval_samples[:-1]}) + y_eval.append({'dc': eval_samples[-1]}) - for s in train_samples: - X_train.append({'dc': s[:-1]}) - y_train.append({'dc': s[-1]}) + X_train.append({'dc': train_samples[:-1]}) + y_train.append({'dc': train_samples[-1]}) - print(len(X_train) / 12) - #print(X_train) - #print(y_train) - exit(0) + print(len(X_eval)) + print(len(y_eval)) + + print(len(X_train)) + print(len(y_train)) return X_train, y_train, X_eval, y_eval diff --git a/pywatts/test_kcross_train.py b/pywatts/test_kcross_train.py index 807c0c4..6201fa2 100644 --- a/pywatts/test_kcross_train.py +++ b/pywatts/test_kcross_train.py @@ -25,7 +25,7 @@ n = pywatts.neural.Net(feature_cols=feature_col) (X_train, y_train, X_eval, y_eval) = kcross.split(df, K) -train_eval = {} +#train_eval = {} if TRAIN: # Train the model with the steps given