Example #1
0
def _bars(series, xticks, section_number, sub_section, display_name):
    sub_section = util.header(section_number, sub_section,
                              "{} Bars Graph".format(display_name))

    bars(series, sort_labels=True, xticks=xticks)

    return sub_section
def get_features_importance(model, feature_names, top=10):
    # graph
    terminal.markdown_h2("Top {} Feature Importances".format(top))
    print()

    feature_importances = model.feature_importances_
    df_feature_importances = pd.DataFrame({"importance": feature_importances}, index=feature_names) \
        .sort_values('importance', ascending=False)

    top_df = df_feature_importances.head(top)
    graphs.bars(top_df["importance"],
                percentage_on_top=False,
                title='Feature Importances',
                ylabel="Importance",
                xlabel="Feature",
                data_processed=True)

    # break line
    print("\n")

    # table
    terminal.markdown_h2("Feature Importances")
    print()

    table = [["Feature", "Importance"]]
    content = []
    for i, x in enumerate(feature_importances):
        content.append([feature_names[i], round(x, 3)])

    content.sort(key=lambda x: x[1], reverse=True)

    table += content

    terminal.markdown_table(table)
def _bars(series, section_number, sub_section, display_name):
    sub_section = util.header(section_number, sub_section,
                              "{}  Bars Graph".format(display_name))

    dskc_graphs.bars(series,
                     title="{} Bars Graph".format(display_name),
                     xlabel=display_name)

    return sub_section
Example #4
0
def _top_words(words_series, top_words, section_number, sub_section,
               display_name):
    sub_section = util.header(
        section_number, sub_section,
        "{} Top {} Words".format(display_name, top_words))

    graphs.bars(words_series,
                title="Top {} words".format(top_words),
                xlabel="Word",
                percentage_on_top=True,
                max_values=top_words)

    return sub_section
Example #5
0
def time_graphs(df,
                column,
                ylabel="",
                year=True,
                month=True,
                day=True,
                weekday=True):
    '''
    Display graphs by year, month, day and weekday

    :param df: pandas dataframe
    :param column: column name
    :param ylabel:
    :param year:
    :param month:
    :param day:
    :param weekday:
    :return:
    '''
    ylabel = ylabel.capitalize()

    if year:
        series = df[column + "_YEAR"]
        title = "over the Years"
        if ylabel:
            title = ylabel + " " + title

        title = title.capitalize()

        bars(series,
             sort_labels=True,
             title=title,
             xlabel="Year",
             ylabel=ylabel)

    if month:
        series = df[column + "_MONTH"]
        title = "over the Months"
        if ylabel:
            title = ylabel + " " + title

        title = title.capitalize()

        bars(series,
             sort_labels=True,
             title=title,
             xlabel="Month",
             ylabel=ylabel)

    if day:
        title = "over the Days"
        if ylabel:
            title = ylabel + " " + title

        title = title.capitalize()
        bars(df[column + "_DAY"],
             title=title,
             sort_labels=True,
             xlabel="Day",
             ylabel=ylabel)

    if weekday:
        series = df[column + "_WEEKDAY"]
        title = "over the Weeks"
        if ylabel:
            title = ylabel + " " + title

        title = title.capitalize()
        days = [
            'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday'
        ]

        bars(series,
             sort_labels=True,
             title=title,
             xlabel="Day of the Week",
             xticks=days,
             ylabel=ylabel)