df_extensions/space.py
def label_review(
        self,
        label: Optional[int] = 1,
        sort: Optional[str] = None,
        include_data: bool = True,
    ):
        """
        Review labeled data for a cluster
        """

        k = self.k

        def to_count_pivot(df):
            mdf = df.drop(columns=["label"]).melt()
            mdf["Count"] = mdf["variable"] + mdf["value"]
            return mdf.pivot_table(
                "Count", index=["variable", "value"], aggfunc="count"
            )

        df = self.label_df
        if include_data is False:
            df = df[[x for x in df.columns if x not in self.cols]]
        df["label"] = self.get_cluster_labels()
        opt = to_count_pivot(df).rename(columns={"Count": "overall_count"})
        df = df.loc[df["label"] == label]
        pt = to_count_pivot(df).join(opt)
        pt = pt.rename(columns={"Count": "cluster_count"})
        pt["% of cluster"] = (pt["cluster_count"] / len(df)).round(3) * 100
        pt["% of label"] = (pt["cluster_count"] / pt["overall_count"]).round(3) * 100
        if sort:
            pt = pt.sort_values(sort, ascending=False)
        return pt

        Review labeled data for a cluster
        
Review labeled data for a cluster
Review labeled data for a cluster
def label_review(
        self,
        label: Optional[int] = 1,
        sort: Optional[str] = None,
        include_data: bool = True,
    ):
        k = self.k
        def to_count_pivot(df):
            mdf = df.drop(columns=["label"]).melt()
            mdf["Count"] = mdf["variable"] + mdf["value"]
            return mdf.pivot_table(
                "Count", index=["variable", "value"], aggfunc="count"
            )
        df = self.label_df
        if include_data is False:
            df = df[[x for x in df.columns if x not in self.cols]]
        df["label"] = self.get_cluster_labels()
        opt = to_count_pivot(df).rename(columns={"Count": "overall_count"})
        df = df.loc[df["label"] == label]
        pt = to_count_pivot(df).join(opt)
        pt = pt.rename(columns={"Count": "cluster_count"})
        pt["% of cluster"] = (pt["cluster_count"] / len(df)).round(3) * 100
        pt["% of label"] = (pt["cluster_count"] / pt["overall_count"]).round(3) * 100
        if sort:
            pt = pt.sort_values(sort, ascending=False)
        return pt
def label_review ( self , label : Optional [ int ] = 1 , sort : Optional [ str ] = None , include_data : bool = True , ) : k = self . k def to_count_pivot ( df ) : mdf = df . drop ( columns = [ "label" ] ) . melt ( ) mdf [ "Count" ] = mdf [ "variable" ] + mdf [ "value" ] return mdf . pivot_table ( "Count" , index = [ "variable" , "value" ] , aggfunc = "count" ) df = self . label_df if include_data is False : df = df [ [ x for x in df . columns if x not in self . cols ] ] df [ "label" ] = self . get_cluster_labels ( ) opt = to_count_pivot ( df ) . rename ( columns = { "Count" : "overall_count" } ) df = df . loc [ df [ "label" ] == label ] pt = to_count_pivot ( df ) . join ( opt ) pt = pt . rename ( columns = { "Count" : "cluster_count" } ) pt [ "% of cluster" ] = ( pt [ "cluster_count" ] / len ( df ) ) . round ( 3 ) * 100 pt [ "% of label" ] = ( pt [ "cluster_count" ] / pt [ "overall_count" ] ) . round ( 3 ) * 100 if sort : pt = pt . sort_values ( sort , ascending = False ) return pt
Review labeled data for a cluster
Review labeled data for a cluster
"""
        Review labeled data for a cluster
        """
self
label
Optional[int]
sort
Optional[str]
include_data
bool