def __init__(self,
                 corpus,
                 scorer=RankDifference(),
                 ranker=AbsoluteFrequencyRanker,
                 use_non_text_features=False,
                 color_palette=QUALITATIVE_COLORS):
        '''
        Assigns scores to colors for categories

        :param corpus: TermDocMatrix
        :param scorer: scorer
        :param color_palette: list of colors [[red, green, blue], ...]
        '''
        self.corpus = corpus
        self.scorer = scorer
        self.color_palette = color_palette
        my_ranker = ranker(corpus)
        if use_non_text_features:
            my_ranker.use_non_text_features()
        tdf = my_ranker.get_ranks()
        tdf_sum = tdf.sum(axis=1)
        term_scores = {}
        for cat in tdf.columns:
            term_scores[cat[:-5]] = pd.Series(self.scorer.get_scores(tdf[cat], tdf_sum - tdf[cat]), index=tdf.index)
        self.term_cat = pd.DataFrame(term_scores).idxmax(axis=1)
        ranked_list_categories = pd.Series(corpus.get_category_names_by_row()).value_counts().index
        self.category_colors = pd.Series(self.color_palette[:len(ranked_list_categories)],
                                         index=ranked_list_categories)
def __init__ ( self , corpus , scorer = RankDifference ( ) , ranker = AbsoluteFrequencyRanker , use_non_text_features = False , color_palette = QUALITATIVE_COLORS ) : self . corpus = corpus self . scorer = scorer self . color_palette = color_palette my_ranker = ranker ( corpus ) if use_non_text_features : my_ranker . use_non_text_features ( ) tdf = my_ranker . get_ranks ( ) tdf_sum = tdf . sum ( axis = 1 ) term_scores = { } for cat in tdf . columns : term_scores [ cat [ : - 5 ] ] = pd . Series ( self . scorer . get_scores ( tdf [ cat ] , tdf_sum - tdf [ cat ] ) , index = tdf . index ) self . term_cat = pd . DataFrame ( term_scores ) . idxmax ( axis = 1 ) ranked_list_categories = pd . Series ( corpus . get_category_names_by_row ( ) ) . value_counts ( ) . index self . category_colors = pd . Series ( self . color_palette [ : len ( ranked_list_categories ) ] , index = ranked_list_categories )
Assigns scores to colors for categories

        :param corpus: TermDocMatrix
        :param scorer: scorer
        :param color_palette: list of colors [[red, green, blue], ...]