examples/feat_import.py
def plot_featimport_confint():
    """Plot feature importances and 95% confidence intervals"""
    fig, ax = plt.subplots(nrows=4, ncols=5, figsize=(25, 20))

    plt.suptitle("Feature Importances", y=0.93, va="baseline")

    for i, row in enumerate(ax):
        for j, col in enumerate(row):

            # get the panel location and simulation name
            count = 5 * i + j
            sim_name = list(SIMULATIONS.keys())[count]

            # extract data from the CSV file and store the data in an array
            all_impt = np.zeros((REPS, DIM))
            for rep in range(REPS):
                forest_impt = np.genfromtxt(
                    "../examples/data/{}_{}.csv".format(sim_name, rep), delimiter=","
                )
                all_impt[rep, :] = forest_impt

            # get the mean importances for the simulation, also calculate 95% CI
            # interval
            mean_impt = np.mean(all_impt, axis=0)
            mean_impt -= np.min(mean_impt)
            mean_impt /= np.max(mean_impt)
            low, high = norm.interval(
                0.95, loc=mean_impt, scale=np.std(mean_impt, axis=0) / np.sqrt(REPS)
            )

            # plot the figure lines, and the 95% CI
            col.plot(
                range(1, DIM + 1),
                mean_impt,
                color="#525252",
                lw=5,
                label="Averaged Data",
            )
            col.fill_between(range(1, DIM + 1), low, high, color="#d9d9d9")

            # make the data look pretty for each pannel
            col.set_xticks([])
            if i == 3:
                col.set_xticks([1, 5])
            col.set_xlim([1, 5])
            col.set_ylim([0, 1])
            col.set_yticks([])
            if j == 0:
                col.set_yticks([0, 1])
            col.set_ylabel("")
            col.set_xlabel("")
            col.set_title(SIM_TITLES[count])

    # misc entire plot
    fig.text(0.5, 0.04, "Dimension", ha="center")
    fig.text(0.08, 0.5, "Feature Importance", va="center", rotation="vertical")
    plt.subplots_adjust(hspace=0.50, wspace=0.40)
Plot feature importances and 95% confidence intervals
Plot feature importances and 95% confidence intervals
Plot feature importances and 95% confidence intervals
def plot_featimport_confint():
    fig, ax = plt.subplots(nrows=4, ncols=5, figsize=(25, 20))
    plt.suptitle("Feature Importances", y=0.93, va="baseline")
    for i, row in enumerate(ax):
        for j, col in enumerate(row):
            count = 5 * i + j
            sim_name = list(SIMULATIONS.keys())[count]
            all_impt = np.zeros((REPS, DIM))
            for rep in range(REPS):
                forest_impt = np.genfromtxt(
                    "../examples/data/{}_{}.csv".format(sim_name, rep), delimiter=","
                )
                all_impt[rep, :] = forest_impt
            mean_impt = np.mean(all_impt, axis=0)
            mean_impt -= np.min(mean_impt)
            mean_impt /= np.max(mean_impt)
            low, high = norm.interval(
                0.95, loc=mean_impt, scale=np.std(mean_impt, axis=0) / np.sqrt(REPS)
            )
            col.plot(
                range(1, DIM + 1),
                mean_impt,
                color="#525252",
                lw=5,
                label="Averaged Data",
            )
            col.fill_between(range(1, DIM + 1), low, high, color="#d9d9d9")
            col.set_xticks([])
            if i == 3:
                col.set_xticks([1, 5])
            col.set_xlim([1, 5])
            col.set_ylim([0, 1])
            col.set_yticks([])
            if j == 0:
                col.set_yticks([0, 1])
            col.set_ylabel("")
            col.set_xlabel("")
            col.set_title(SIM_TITLES[count])
    fig.text(0.5, 0.04, "Dimension", ha="center")
    fig.text(0.08, 0.5, "Feature Importance", va="center", rotation="vertical")
    plt.subplots_adjust(hspace=0.50, wspace=0.40)
def plot_featimport_confint ( ) : fig , ax = plt . subplots ( nrows = 4 , ncols = 5 , figsize = ( 25 , 20 ) ) plt . suptitle ( "Feature Importances" , y = 0.93 , va = "baseline" ) for i , row in enumerate ( ax ) : for j , col in enumerate ( row ) : count = 5 * i + j sim_name = list ( SIMULATIONS . keys ( ) ) [ count ] all_impt = np . zeros ( ( REPS , DIM ) ) for rep in range ( REPS ) : forest_impt = np . genfromtxt ( "../examples/data/{}_{}.csv" . format ( sim_name , rep ) , delimiter = "," ) all_impt [ rep , : ] = forest_impt mean_impt = np . mean ( all_impt , axis = 0 ) mean_impt -= np . min ( mean_impt ) mean_impt /= np . max ( mean_impt ) low , high = norm . interval ( 0.95 , loc = mean_impt , scale = np . std ( mean_impt , axis = 0 ) / np . sqrt ( REPS ) ) col . plot ( range ( 1 , DIM + 1 ) , mean_impt , color = "#525252" , lw = 5 , label = "Averaged Data" , ) col . fill_between ( range ( 1 , DIM + 1 ) , low , high , color = "#d9d9d9" ) col . set_xticks ( [ ] ) if i == 3 : col . set_xticks ( [ 1 , 5 ] ) col . set_xlim ( [ 1 , 5 ] ) col . set_ylim ( [ 0 , 1 ] ) col . set_yticks ( [ ] ) if j == 0 : col . set_yticks ( [ 0 , 1 ] ) col . set_ylabel ( "" ) col . set_xlabel ( "" ) col . set_title ( SIM_TITLES [ count ] ) fig . text ( 0.5 , 0.04 , "Dimension" , ha = "center" ) fig . text ( 0.08 , 0.5 , "Feature Importance" , va = "center" , rotation = "vertical" ) plt . subplots_adjust ( hspace = 0.50 , wspace = 0.40 )
Plot feature importances and 95% confidence intervals
Plot feature importances and 95% confidence intervals
"""Plot feature importances and 95% confidence intervals""" # get the panel location and simulation name # extract data from the CSV file and store the data in an array # get the mean importances for the simulation, also calculate 95% CI # interval # plot the figure lines, and the 95% CI # make the data look pretty for each pannel # misc entire plot