Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
optimize the prediction_to_frame function
  • Loading branch information
somefreestring committed Dec 8, 2019
commit 0f51e119649a3ad2112ae3a0358e79349c50d5b2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def labels_source_columns(self) -> List[str]:

@property
def encoded_labels_columns(self) -> List[str]:
#return [str(11) if isinstance(cat, pd._libs.interval.Interval) else str(cat) for cat in self.buckets]
return [str(cat) for cat in self.buckets]

def encode(self, df: pd.DataFrame) -> pd.DataFrame:
Expand Down
6 changes: 3 additions & 3 deletions test/z_component_tests/test__classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ def make_targets(t, frame):
"""then"""
self.assertEqual(len(fit_summary_df), 4023)
self.assertListEqual(fit_summary_df.columns.tolist(),
[(PREDICTION_COLUMN_NAME, 'label #0'), (PREDICTION_COLUMN_NAME, 'label #1'), (PREDICTION_COLUMN_NAME, 'label #2'), (PREDICTION_COLUMN_NAME, 'label #3'),
(LABEL_COLUMN_NAME, 'label #0'), (LABEL_COLUMN_NAME, 'label #1'), (LABEL_COLUMN_NAME, 'label #2'), (LABEL_COLUMN_NAME, 'label #3'),
[(PREDICTION_COLUMN_NAME, '(-inf, -0.05]'), (PREDICTION_COLUMN_NAME, '(-0.05, 0.0]'), (PREDICTION_COLUMN_NAME, '(0.0, 0.05000000000000002]'), (PREDICTION_COLUMN_NAME, '(0.05000000000000002, inf]'),
(LABEL_COLUMN_NAME, '(-inf, -0.05]'), (LABEL_COLUMN_NAME, '(-0.05, 0.0]'), (LABEL_COLUMN_NAME, '(0.0, 0.05000000000000002]'), (LABEL_COLUMN_NAME, '(0.05000000000000002, inf]'),
(TARGET_COLUMN_NAME, 'close <0.1'), (TARGET_COLUMN_NAME, 'close <0.05'), (TARGET_COLUMN_NAME, 'close >0'), (TARGET_COLUMN_NAME, 'close >0.05')])

self.assertListEqual(bt_summary_df.columns.tolist(), fit_summary_df.columns.tolist())

self.assertListEqual(predict_df.columns.tolist(),
[(PREDICTION_COLUMN_NAME, 'label #0'), (PREDICTION_COLUMN_NAME, 'label #1'), (PREDICTION_COLUMN_NAME, 'label #2'), (PREDICTION_COLUMN_NAME, 'label #3'),
[(PREDICTION_COLUMN_NAME, '(-inf, -0.05]'), (PREDICTION_COLUMN_NAME, '(-0.05, 0.0]'), (PREDICTION_COLUMN_NAME, '(0.0, 0.05000000000000002]'), (PREDICTION_COLUMN_NAME, '(0.05000000000000002, inf]'),
(TARGET_COLUMN_NAME, 'close <0.1'), (TARGET_COLUMN_NAME, 'close <0.05'), (TARGET_COLUMN_NAME, 'close >0'), (TARGET_COLUMN_NAME, 'close >0.05')])

def test_target_classification(self):
Expand Down
14 changes: 8 additions & 6 deletions test/z_component_tests/test__multi_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


class MultiModelTest(unittest.TestCase):
maxDiff = None

def test_invalid_multi_model(self):
"""expect"""
Expand Down Expand Up @@ -80,18 +81,19 @@ def test_multi_model_multi_class_classifications(self):
predict_df = df.predict(fit.model, tail=1)

"""then"""
print(fit_summary_df.columns.tolist())
self.assertListEqual(fit_summary_df.columns.tolist(),
[('1', 'prediction', 'is_above_1.0 #0'), ('1', 'prediction', 'is_above_1.0 #1'), ('1', 'prediction', 'is_above_1.0 #2'), ('1', 'prediction', 'is_above_1.0 #3'),
('2', 'prediction', 'is_above_1.2 #0'), ('2', 'prediction', 'is_above_1.2 #1'), ('2', 'prediction', 'is_above_1.2 #2'), ('2', 'prediction', 'is_above_1.2 #3'),
('1', 'label', 'is_above_1.0 #0'), ('1', 'label', 'is_above_1.0 #1'), ('1', 'label', 'is_above_1.0 #2'), ('1', 'label', 'is_above_1.0 #3'),
('2', 'label', 'is_above_1.2 #0'), ('2', 'label', 'is_above_1.2 #1'), ('2', 'label', 'is_above_1.2 #2'), ('2', 'label', 'is_above_1.2 #3'),
[('1', 'prediction', '(-inf, 0.95]'), ('1', 'prediction', '(0.95, 1.0]'), ('1', 'prediction', '(1.0, 1.05]'), ('1', 'prediction', '(1.05, inf]'),
('2', 'prediction', '(-inf, 1.95]'), ('2', 'prediction', '(1.95, 2.0]'), ('2', 'prediction', '(2.0, 2.05]'), ('2', 'prediction', '(2.05, inf]'),
('1', 'label', '(-inf, 0.95]'), ('1', 'label', '(0.95, 1.0]'), ('1', 'label', '(1.0, 1.05]'), ('1', 'label', '(1.05, inf]'),
('2', 'label', '(-inf, 1.95]'), ('2', 'label', '(1.95, 2.0]'), ('2', 'label', '(2.0, 2.05]'), ('2', 'label', '(2.05, inf]'),
('1', 'loss', '1'), ('2', 'loss', '2'),
('1', 'target', 'sma 1'), ('2', 'target', 'sma 2')])

self.assertListEqual(bt_summary_df.columns.tolist(), fit_summary_df.columns.tolist())

self.assertListEqual(predict_df.columns.tolist(),
[('1', 'prediction', 'is_above_1.0 #0'), ('1', 'prediction', 'is_above_1.0 #1'), ('1', 'prediction', 'is_above_1.0 #2'), ('1', 'prediction', 'is_above_1.0 #3'),
('2', 'prediction', 'is_above_1.2 #0'), ('2', 'prediction', 'is_above_1.2 #1'), ('2', 'prediction', 'is_above_1.2 #2'), ('2', 'prediction', 'is_above_1.2 #3'),
[('1', 'prediction', '(-inf, 0.95]'), ('1', 'prediction', '(0.95, 1.0]'), ('1', 'prediction', '(1.0, 1.05]'), ('1', 'prediction', '(1.05, inf]'),
('2', 'prediction', '(-inf, 1.95]'), ('2', 'prediction', '(1.95, 2.0]'), ('2', 'prediction', '(2.0, 2.05]'), ('2', 'prediction', '(2.05, inf]'),
('1', 'target', 'sma 1'), ('2', 'target', 'sma 2')])