suneku/classifier.py
def test(self,data):
        """ DataFrame: Compare predictions to known results. """
        target = self.target

        data = DataFrame(data)
        modeled = self(data)
        reality = data[target].astype('category')
        correct = modeled['class'] == reality

        # Calculate self-information in bits.
        surprise = modeled['p_class'].copy()
        surprise[~correct] = 1 - surprise[~correct]
        surprise = -log2(surprise)

        # Show percent correct and confusion matrix.
        print("{:.1%} correct".format(correct.mean()))
        print("\n{}\n".format(crosstab(reality,modeled['class'])))

        return ( modeled
                .assign(correct=correct)
                .assign(reality=reality)
                .assign(surprise=surprise)
                .sort_index(axis=1) )
 DataFrame: Compare predictions to known results. 
Compare predictions to known results.
Compare predictions to known results .
def test(self,data):
        target = self.target
        data = DataFrame(data)
        modeled = self(data)
        reality = data[target].astype('category')
        correct = modeled['class'] == reality
        surprise = modeled['p_class'].copy()
        surprise[~correct] = 1 - surprise[~correct]
        surprise = -log2(surprise)
        print("{:.1%} correct".format(correct.mean()))
        print("\n{}\n".format(crosstab(reality,modeled['class'])))
        return ( modeled
                .assign(correct=correct)
                .assign(reality=reality)
                .assign(surprise=surprise)
                .sort_index(axis=1) )
def test ( self , data ) : target = self . target data = DataFrame ( data ) modeled = self ( data ) reality = data [ target ] . astype ( 'category' ) correct = modeled [ 'class' ] == reality surprise = modeled [ 'p_class' ] . copy ( ) surprise [ ~ correct ] = 1 - surprise [ ~ correct ] surprise = - log2 ( surprise ) print ( "{:.1%} correct" . format ( correct . mean ( ) ) ) print ( "\n{}\n" . format ( crosstab ( reality , modeled [ 'class' ] ) ) ) return ( modeled . assign ( correct = correct ) . assign ( reality = reality ) . assign ( surprise = surprise ) . sort_index ( axis = 1 ) )
DataFrame: Compare predictions to known results.
DataFrame : Compare predictions to known results .
""" DataFrame: Compare predictions to known results. """ # Calculate self-information in bits. # Show percent correct and confusion matrix.
self
data