mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-16 09:11:00 +08:00
make the integration simpler
This commit is contained in:
@@ -133,7 +133,10 @@ class Estimator(object):
|
||||
TimeInspector.set_time_mark()
|
||||
# 1. Get pred and prediction score of model(s).
|
||||
pred = self.trainer.get_test_score()
|
||||
performance = self.trainer.get_test_performance()
|
||||
try:
|
||||
performance = self.trainer.get_test_performance()
|
||||
except NotImplementedError:
|
||||
performance = None
|
||||
# 2. Normal Backtest.
|
||||
report_normal, positions_normal = self._normal_backtest(pred)
|
||||
# 3. Long-Short Backtest.
|
||||
|
||||
@@ -61,12 +61,11 @@ class BaseTrainer(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_test_performance(self):
|
||||
"""
|
||||
Implement this method indicating how to get the performance of the model.
|
||||
"""
|
||||
pass
|
||||
raise NotImplementedError(f"Please implement `get_test_performance`")
|
||||
|
||||
def get_test_score(self):
|
||||
"""
|
||||
@@ -164,7 +163,10 @@ class StaticTrainer(BaseTrainer):
|
||||
return pred
|
||||
|
||||
def get_test_performance(self):
|
||||
model_score = self.model.score(self.x_test, self.y_test)
|
||||
try:
|
||||
model_score = self.model.score(self.x_test, self.y_test)
|
||||
except NotImplementedError:
|
||||
model_score = None
|
||||
# Remove rows from x, y and w, which contain Nan in any columns in y_test.
|
||||
x_test, y_test, __ = drop_nan_by_y_index(self.x_test, self.y_test)
|
||||
pred_test = self.model.predict(x_test)
|
||||
|
||||
Reference in New Issue
Block a user