Esempio n. 1
0
    def topics(self, axis: Subplot) -> BarContainer:
        """Plot the relative importance of the individual topics.

        Parameters
        ----------
        axis: Subplot
            The matplotlib axis to plot into.

        Returns
        -------
        BarContainer
            The container for the bars plotted into the given axis.

        """
        colors = [f'C{color}' for color in self.__topic_range]
        axis.set(xlabel='Topic', ylabel='Importance')
        axis.set_title('Topic distribution')
        return axis.bar(self.__topic_range, self.__topics, color=colors,
                        tick_label=self.__topic_range)
Esempio n. 2
0
    def convergence(self, axis: Subplot) -> List[Line2D]:
        """Plot the convergence of the PLSA run.

        The quantity to be minimized is the Kullback-Leibler divergence
        between the original document-word matrix and its approximation
        given by the (conditional) PLSA factorization.

        Parameters
        ----------
        axis: Subplot
            The matplotlib axis to plot into.

        Returns
        -------
        list of Line2D
            The line object plotted into the given axis.

        """
        axis.set(xlabel='Iteration', ylabel='Kullback-Leibler divergence')
        return axis.plot(self.__convergence)
Esempio n. 3
0
    def topics_in_doc(self, i_doc: int, axis: Subplot) -> BarContainer:
        """Plot the relative weights of topics in a given document.

        Parameters
        ----------
        i_doc: int
            Index of the document to plot. Numbering starts at 0.
        axis: Subplot
            The matplotlib axis to plot into.

        Returns
        -------
        BarContainer
            The container for the bars plotted into the given axis.

        """
        colors = [f'C{color}' for color in self.__topic_range]
        axis.set(xlabel='Topic', ylabel='Importance', title=f'Document {i_doc}')
        return axis.bar(self.__topic_range, self.__topic_given_doc[i_doc],
                        color=colors, tick_label=self.__topic_range)
Esempio n. 4
0
    def prediction(self, doc: str, axis: Subplot) -> BarContainer:
        """Plot the predicted relative weights of topics in a new document.

        Parameters
        ----------
        doc: str
            A new document given as a single string.
        axis: Subplot
            The matplotlib axis to plot into.

        Returns
        -------
        BarContainer
            The container for the bars plotted into the given axis.

        """
        colors = [f'C{color}' for color in self.__topic_range]
        prediction, n_unknown_words, _ = self.__predict(doc)
        axis.set(xlabel='Topic', ylabel='Importance')
        axis.set_title(f'Number of unknown words: {n_unknown_words}')
        return axis.bar(self.__topic_range, prediction, color=colors,
                        tick_label=self.__topic_range)