【发布时间】:2021-10-04 21:18:33
【问题描述】:
我有一个用于不同来源(标记器)的数据库,我想为每个来源分配权重。
# source 1
df1 = pd.DataFrame({
'feature': ['a', 'b', 'c'],
'label': [1, 0, 0]
})
# source 2
df2 = pd.DataFrame({
'feature': ['d', 'e', 'f'],
'label': [1, 0, 1]
})
df = pd.concat([df1, df2]) # Here I want to assign distic weigths to df1 and df2
这样,当我训练模型时,模型会考虑特征的权重,即特征是否为 df1 与在 df2 中的特征在某种程度上不同(或多或少“重要”)。
clf = model()
X = df['feature']
y = df['label']
clf.fit(X, y, weight) # But here the weight is not the class_weight
# but a weight in the feature
【问题讨论】:
-
预期输出是什么?
-
pd.concat([df.assign(weight=i) for i,df in enumerate([df1,df2])] )?
标签: python pandas scikit-learn