Thief of Wealth

numGraphs = 3 # If multiple variables are plotted, this is how many graphs to plot per row

subWidth = 12 # Width to allocate for each row of subplots

subHeight = 6 # Height to allocate for each subplot

font = 8 # Font size for subplots



def plotCat(setType,dataset,fields):

    maxCat = 10 # Number of categories to reduce plots to showing

    sns.set(style='darkgrid')

    n = len(fields) # Number of variables to plot

    if n == 1:

        field = fields[0]

        data = dataset[field].dropna()

        plt.xticks(rotation=90)

        sns.countplot(data, order = data.value_counts().iloc[:maxCat].index).set_title("%s set %s" % (setType, field))

    else:

        size = (subWidth, subHeight * math.ceil(n/numGraphs))

        if n > numGraphs:

            fig, axes = plt.subplots(math.ceil(n/numGraphs), numGraphs, figsize=size)

        else:

            fig, axes = plt.subplots(1, n, figsize=size)

        for i in range(n):

            field = fields[i]

            data = dataset[field].dropna()

            if n > numGraphs:

                sns.countplot(data, order = data.value_counts().iloc[:maxCat].index,

                    ax=axes[i//numGraphs,i % numGraphs]).set_title("%s set %s" % (setType, field))

            else:

                sns.countplot(data, order = data.value_counts().iloc[:maxCat].index,

                    ax=axes[i]).set_title("%s set %s" % (setType, field))

        for ax in axes.flatten():

            for tick in ax.get_xticklabels():

                tick.set_rotation(90)

    plt.show()

    return None


사용법

plotCat('train', train_combined, ['ProductCD'])


train인지 test인지 (제목용), dataset, feature 배열

profile on loading

Loading...