def probable_languages(self, text):
"""List of most probable programming languages,
the list is ordered from the most probable to the less probable.
:param str text: source code.
:return: languages list
:rtype: list
"""
values = extract(text)
input_fn = _to_func([[values], []])
proba = next(self._classifier.predict_proba(input_fn=input_fn))
proba = proba.tolist()
threshold = max(proba) - _K_STDEV * stdev(proba)
items = sorted(enumerate(proba), key=itemgetter(1), reverse=True)
LOGGER.debug("Threshold: %f, probabilities: %s", threshold, items)
positions = [pos for pos, value in items if value > threshold]
LOGGER.debug("Predicted languages positions %s", positions)
names = sorted(self.languages)
return [names[pos] for pos in positions]
评论列表
文章目录