分类: 大数据
2020-04-20 10:35:47
本文以访客到店视频,解析AI预测顾客收入、年龄、婚姻状态这三项,构建访客视频用户挖掘-精准产品组合推荐系统的PART1。
from keras import layers
from keras import Input
from keras.models import Model
vocabulary_size = 50000
num_income_groups = 10
posts_input = Input(shape=(None,), dtype=‘int32’, name=‘posts’)
embedded_posts = layers.Embedding(256, vocabulary_size)(posts_input)
x = layers.Conv1D(128, 5, activation=‘relu’)(embedded_posts)
x = layers.MaxPooling1D(5)(x)
x = layers.Conv1D(256, 5, activation=‘relu’)(x)
x = layers.Conv1D(256, 5, activation=‘relu’)(x)
x = layers.MaxPooling1D(5)(x)
x = layers.Conv1D(256, 5, activation=‘relu’)(x)
x = layers.Conv1D(256, 5, activation=‘relu’)(x)
x = layers.GlobalMaxPooling1D()(x)
x = layers.Dense(128, activation=‘relu’)(x)
age_prediction = layers.Dense(1, name=‘age’)(x)
income_prediction = layers.Dense(num_income_groups,
activation=‘softmax’,
name=‘income’)(x)
marriage_prediction = layers.Dense(1, activation=‘sigmoid’, name=‘marriage’)(x)
model = Model(posts_input,
[age_prediction, income_prediction, marriage_prediction])
model.compile(optimizer=‘rmsprop’,
loss=[‘mse’, ‘categorical_crossentropy’, ‘binary_crossentropy’])
model.compile(optimizer=‘rmsprop’,
loss=[‘mse’, ‘categorical_crossentropy’, ‘binary_crossentropy’])
严重不平衡的损失贡献会导致模型表示针对单个预测项损失值最大的任务优先进行优化,
而不考虑其他任务的优化。所以我们要对<收入><年龄><婚姻>三个预测项的损失进行缩放归一化,以新的统一单位来表示。
另外,我们可以根据门店销售任务关联的因素进行权重平衡,在顾客收入、年龄、婚姻的预测准确性上取中值,达到任务效果最大化即可。分配权重,指定重点训练的预测项,提高关键因子的预测重要性。譬如国美电器空调门店,<婚姻状况>在空调的购买决策和产品中占据关键,所以可以放大门店顾客婚姻预测项目的损失权重。
model.compile(optimizer=‘rmsprop’,
loss=[‘mse’, ‘categorical_crossentropy’, ‘binary_crossentropy’],
loss_weights=[0.25, 1., 10.])
model.fit(posts, [age_targets, income_targets, gender_targets],
epochs=10, batch_size=64)