guesser.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:guesslang 作者: yoeo 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号