I have hightly imballanced dataset and I want to assign weights for my observations by months.
For instance, If my observation is in January 2022 I'll give it 1/5 and if it's March 2022 I'll give it 1/3and so on.
feature_1 date weights
117 2016-11-12 0.015
... ... ...
123 2022-01-01 0.2
234 2022-01-02 0.2
... ...
345 2022-05-31 1.0
I'm using CatboostClassifier and I guess I can pass list of weights for all my data to weight param. So it will look smth like this
model.fit(Pool(X_train,y_train,weight=train_weight))
Problem is I can't think of elegant solution to form weights column/list.
For now, I splitted my dataframe in Months frequency like that:
g = X_train.groupby(pd.Grouper(key='date', freq='M'))
dfs = [group for _,group in g]
and made column of weights like that:
for i, df in enumerate(dfs):
weight = []
for val in dfs[i].iterrows():
weight.append(1 / (len(dfs)+2 - i))
dfs[i]['weight'] = weight