注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
直接把题粘过来了,挺简单的, 重点是code要run没bug,所以他当时说不用最优解
求大米,谢谢!!!
'''
Write a function that takes the logs as input, builds the transition graph and returns it as an adjacency list with probabilities. Add __START__ and __END__ states.
Specifically, for each resource, we want to compute a list of every possible next step taken by any user, together with the corresponding probabilities. The list of resources should include __START__ but not __END__, since by definition __END__ is a terminal state.
Expected output for logs1:
transition_graph(logs1) # =>
{
'_START_': {'resource_1': 0.6, 'resource_2': 0.2, 'resource_6': 0.2},
'resource_1': {'_END_': 0.71, 'resource_3': 0.14, 'resource_5': 0.14},
'resource_2': {'resource_1': 0.5, 'resource_2': 0.5},
'resource_3': {'resource_1': 1.0},
'resource_5': {'resource_1': 1.0},
'resource_6': {'resource_1': 1.0}
}
For example, of 5 total users, 3 users have resource_1 as a first visit (user_1, user_9, user_22), 1 user has resource_6 as a first visit (user_3), and 1 user has resource_2 as a first visit (user_6), so the ser", "resource_3"],
["1090", "user", "resource_3"],
]
logs3 = [
["300", "user_10", "resource_5"],
]
logs4 = [
["1", "user_96", "resource_5"],
["1", "user_10", "resource_5"],
["301", "user_11", "resource_5"],
["301", "user_12", "resource_5"],
["603", "user_12", "resource_5"],
["1603", "user_12", "resource_7"],
]
求大米,谢谢!!! |