我有一个相当大的数据集(大约 500 万行),其中有几个计算列,如滞后(1 和 7)和滚动窗口(7、30、90,每个都有几个值,如平均值、标准差、最小值、最大值等)。现在我需要向df添加一行或多行,我想知道(重新)计算这些特征的最有效方法。重新计算整个df会花费太多时间,但我不能简单地将函数应用于新添加的行。
对于滞后这不是一个大问题,我可以简单地,例如对于滞后 1,
df.iloc[-1, -2] = df.iloc[-2, -2]
Run Code Online (Sandbox Code Playgroud)
这应该可以解决问题(与滞后 7 相同),但是滚动窗口呢?同样的方法行不通,我无法在整个数据帧上(重新)运行滚动窗口。我要手工计算吗?还有其他办法吗?
Python 3.7.7 和 pandas 1.0.3
有没有办法用 CatBoost 和 Optuna 进行修剪(在 LightGBM 中很容易,但在 Catboost 中我找不到任何提示)。我的代码是这样的
def objective(trial):
param = {
'iterations':trial.suggest_int('iterations', 100,1500, step=100),
'learning_rate':trial.suggest_uniform("learning_rate", 0.001, 0.3),
'random_strength':trial.suggest_int("random_strength", 1,10),
'max_bin':trial.suggest_categorical('max_bin', [2,3,4,5,6,8,10,20,30]),
'grow_policy':trial.suggest_categorical('grow_policy', ['SymmetricTree', 'Depthwise', 'Lossguide']),
"colsample_bylevel": trial.suggest_uniform("colsample_bylevel", 0.1, 1),
'od_type' : "Iter",
'od_wait' : 30,
"depth": trial.suggest_int("max_depth", 1,12),
"l2_leaf_reg": trial.suggest_loguniform("l2_leaf_reg", 1e-8, 100),
'custom_metric' : ['AUC'],
"loss_function": "Logloss",
}
if param['grow_policy'] == "SymmetricTree":
param["boosting_type"]= trial.suggest_categorical("boosting_type", ["Ordered", "Plain"])
else:
param["boosting_type"] = "Plain"
# Added subsample manually
param["subsample"] = trial.suggest_float("subsample", 0.1, 1)
### CV ###
# How to add a …Run Code Online (Sandbox Code Playgroud)