跟特征数量没关系
Some checks are pending
Update Docker Hub Description / dockerHubDescription (push) Waiting to run

This commit is contained in:
zhangkun9038@dingtalk.com 2025-04-28 15:32:01 +08:00
parent 8535b10cea
commit 619de5cede

View File

@ -52,7 +52,9 @@ class FreqaiExampleHybridStrategy(IStrategy):
"random_state": 1
},
"model_training_parameters": {
"n_estimators": 800
"n_estimators": 200,
"max_depth": 5,
"learning_rate": 0.05
}
},
@ -199,10 +201,10 @@ class FreqaiExampleHybridStrategy(IStrategy):
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
return dataframe
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs) -> DataFrame:
"""
Redefined target variable to predict whether the price will increase or decrease in the future.
"""
logger.info(f"Setting FreqAI targets for pair: {metadata['pair']}")
logger.info(f"DataFrame shape: {dataframe.shape}")
logger.info(f"Available columns: {list(dataframe.columns)}")
logger.info(f"First few rows:\n{dataframe[['date', 'close']].head().to_string()}")
if "close" not in dataframe.columns:
logger.error("Required 'close' column missing in dataframe")
@ -213,24 +215,16 @@ class FreqaiExampleHybridStrategy(IStrategy):
raise ValueError("Insufficient data for target calculation")
try:
# 生成数值型标签1 表示上涨0 表示下跌
# Define target variable: 1 for price increase, 0 for price decrease
dataframe["&-up_or_down"] = np.where(
dataframe["close"].shift(-50) > dataframe["close"],
1.0, # 数值型标签
0.0
dataframe["close"].shift(-50) > dataframe["close"], 1, 0
)
# Reshape the target variable to be a 2D array
# Ensure target variable is a 2D array
dataframe["&-up_or_down"] = dataframe["&-up_or_down"].values.reshape(-1, 1)
except Exception as e:
logger.error(f"Failed to create &-up_or_down column: {str(e)}")
raise
logger.info(f"Target column head:\n{dataframe[['&-up_or_down']].head().to_string()}")
if "&-up_or_down" not in dataframe.columns:
logger.error("FreqAI failed to generate the &-up_or_down column")
raise KeyError("FreqAI failed to generate the &-up_or_down column")
logger.info("FreqAI targets set successfully")
return dataframe