1234567891011121314151617181920212223242526272829303132333435363738 |
- #coding utf-8
- import json
- import math
- import time
- def load_json(filename):
- with open(filename, 'r') as fin:
- json_data = json.load(fin)
- return json_data
- def sigmoid(x):
- return 1.0 / (1.0 + math.exp(-x))
- online_w = load_json('./ad_out_v1_online_w.json')
- def get_online_score(online_features):
- score = online_w.get('bias', 0.0)
- score += sum([online_w.get('#'.join([k, v]), 0.0) for k, v in online_features.items()])
- return score
- def get_final_score(online_features, offline_score):
- online_score = get_online_score(online_features)
- final_score = online_score + offline_score
- final_score = sigmoid(final_score)
- return final_score, online_score
- if __name__ == '__main__':
- app_type = 0
- online_features = {
- 'ctx_apptype': str(app_type),
- 'ctx_week': time.strftime('%w', time.localtime()),
- 'ctx_hour': time.strftime('%H', time.localtime()),
- }
- print(get_final_score(online_features, -1.0))
- print(get_final_score(online_features, 0.0))
- print(get_final_score({}, 0.0))
|