Mercurial > repos > bgruening > create_tool_recommendation_model
comparison predict_tool_usage.py @ 2:50753817983a draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/recommendation_training/tools/tool_recommendation_model commit c635df659fe1835679438589ded43136b0e515c6"
| author | bgruening |
|---|---|
| date | Sat, 09 May 2020 09:38:04 +0000 |
| parents | 22ebbac136c7 |
| children | f0da532be419 |
comparison
equal
deleted
inserted
replaced
| 1:275e98795e99 | 2:50753817983a |
|---|---|
| 19 main_path = os.getcwd() | 19 main_path = os.getcwd() |
| 20 | 20 |
| 21 | 21 |
| 22 class ToolPopularity: | 22 class ToolPopularity: |
| 23 | 23 |
| 24 @classmethod | |
| 25 def __init__(self): | 24 def __init__(self): |
| 26 """ Init method. """ | 25 """ Init method. """ |
| 27 | 26 |
| 28 @classmethod | |
| 29 def extract_tool_usage(self, tool_usage_file, cutoff_date, dictionary): | 27 def extract_tool_usage(self, tool_usage_file, cutoff_date, dictionary): |
| 30 """ | 28 """ |
| 31 Extract the tool usage over time for each tool | 29 Extract the tool usage over time for each tool |
| 32 """ | 30 """ |
| 33 tool_usage_dict = dict() | 31 tool_usage_dict = dict() |
| 61 tool_usage_dict[tool][dt] = 0 | 59 tool_usage_dict[tool][dt] = 0 |
| 62 # sort the usage list by date | 60 # sort the usage list by date |
| 63 tool_usage_dict[tool] = collections.OrderedDict(sorted(usage.items())) | 61 tool_usage_dict[tool] = collections.OrderedDict(sorted(usage.items())) |
| 64 return tool_usage_dict | 62 return tool_usage_dict |
| 65 | 63 |
| 66 @classmethod | |
| 67 def learn_tool_popularity(self, x_reshaped, y_reshaped): | 64 def learn_tool_popularity(self, x_reshaped, y_reshaped): |
| 68 """ | 65 """ |
| 69 Fit a curve for the tool usage over time to predict future tool usage | 66 Fit a curve for the tool usage over time to predict future tool usage |
| 70 """ | 67 """ |
| 71 epsilon = 0.0 | 68 epsilon = 0.0 |
| 91 prediction = [epsilon] | 88 prediction = [epsilon] |
| 92 return prediction[0] | 89 return prediction[0] |
| 93 except Exception: | 90 except Exception: |
| 94 return epsilon | 91 return epsilon |
| 95 | 92 |
| 96 @classmethod | |
| 97 def get_pupularity_prediction(self, tools_usage): | 93 def get_pupularity_prediction(self, tools_usage): |
| 98 """ | 94 """ |
| 99 Get the popularity prediction for each tool | 95 Get the popularity prediction for each tool |
| 100 """ | 96 """ |
| 101 usage_prediction = dict() | 97 usage_prediction = dict() |
