Пример #1
0
def trip_duration_stats(df):
    """Displays statistics on the total and average trip duration."""

    print_section("Calculating Trip Duration...")
    start_time = time.time()

    # display total travel time
    total_travel = df["Trip Duration"].sum()
    print_result("Total travel time -> ", total_travel)

    # display mean travel time
    mean_travel = df["Trip Duration"].mean()
    print_result("Mean travel time -> ", mean_travel)

    # display max travel time
    max_travel = df["Trip Duration"].max()
    print_result("Max travel time -> ", max_travel)

    # display the total trip duration for each user type
    print_section("Travel time for each user type:")
    total_trip_duration = df.groupby(["User Type"]).sum()["Trip Duration"]
    for index, user_trip in enumerate(total_trip_duration):
        temp = "  - " + total_trip_duration.index[index] + " : "
        print_result(temp, user_trip)

    print("\nThis took %s seconds." % (time.time() - start_time))
    print('-' * 40)
Пример #2
0
def station_stats(df):
    """Displays statistics on the most popular stations and trip."""

    print_section("Calculating The Most Popular Stations and Trip...")
    start_time = time.time()

    # display most commonly used start station
    start_station = df["Start Station"].value_counts().idxmax()
    # station_message =
    print_result("Most commonly used start station -> ", start_station)

    # display most commonly used end station
    most_common_end_station = df["End Station"].value_counts().idxmax()
    print_result("Most commonly used end station -> ", most_common_end_station)

    # display most frequent combination of start station and end station trip
    most_common_start_end_station = df[["Start Station",
                                        "End Station"]].mode().loc[0]
    print_result("Most commonly used start station is ",
                 most_common_start_end_station[0])
    print_result("And the most commonly used end station is  ",
                 most_common_start_end_station[1])

    print("\nThis took %s seconds." % (time.time() - start_time))
    print('-' * 40)
Пример #3
0
def gender_stats(df):
    """Displays statistics of analysis based on the gender of bikeshare users."""

    # Display counts of gender
    print_section("Counts of gender :")
    gender_counts = df["Gender"].value_counts()

    # print out the total of each genders
    for index, gender_count in enumerate(gender_counts):
        temp = "  - " + gender_counts.index[index] + " : "
        print_result(temp, gender_count)
Пример #4
0
def birth_stats(df):
    """Displays statistics of analysis based on the birth years of bikeshare users."""

    print_section("Birthday stats :")

    # Display earliest, most recent, and most common year of birth
    birth_year = df["Birth Year"]

    # the most common birth year
    most_common_year = birth_year.value_counts().idxmax()
    print_result("The most common birth year -> ", most_common_year)

    # the most recent birth year
    most_recent = birth_year.max()
    print_result("The most recent birth year -> ", most_recent)

    # the most earliest birth year
    earliest_year = birth_year.min()
    print_result("The most earliest birth year -> ", earliest_year)
Пример #5
0
def time_stats(df):
    """Displays statistics on the most frequent times of travel."""

    print_section("Calculating The Most Frequent Times of Travel...")
    start_time = time.time()

    # display the most common month
    common_month = df["month"].value_counts().idxmax()
    print_result("Most common month -> ", common_month)

    # display the most common day of week
    day_of_week = df["day_of_week"].value_counts().idxmax()
    print_result("Most common day of week -> ", day_of_week)

    # display the most common start hour
    start_hour = df["hour"].value_counts().idxmax()
    print_result("Most common start hour is -> ", start_hour)

    print("\nThis took %s seconds." % (time.time() - start_time))
    print('-' * 40)
Пример #6
0
def user_stats(df):
    """Displays statistics on bikeshare users."""

    print_section("Calculating User Stats...")
    start_time = time.time()

    # Display counts of user types
    print_section("Counts of user types :")
    value_counts = df["User Type"].value_counts()

    # print out the total numbers of each user types
    for index, user_count in enumerate(value_counts):
        temp = "  - " + value_counts.index[index] + " : "
        print_result(temp, user_count)

    if "Gender" in df.columns:
        gender_stats(df)

    if "Birth Year" in df.columns:
        birth_stats(df)

    print("\nThis took %s seconds." % (time.time() - start_time))
    print('-' * 40)
    print('-' * 40)
Пример #7
0
def create_config(**options):
    config = OrderedDict()
    config['arch'] = options['arch']
    config['lr'] = options['lr']
    config['momentum'] = options['momentum'] if 'momentum' in options else 0.0
    config[
        'nesterov'] = options['nesterov'] if 'nesterov' in options else False
    config['weight_decay'] = options[
        'weight_decay'] if 'weight_decay' in options else 0.0
    config['lr_decay'] = options['lr_decay'] if 'lr_decay' in options else 1.0
    if config['lr_decay'] < 0:
        config['lr_decay'] = -1.0 / config['lr_decay']
    config['lr_decay_step'] = options[
        'lr_decay_step'] if 'lr_decay_step' in options else -1.0
    if isinstance(config['lr_decay_step'], str):
        lr_decay_step = config['lr_decay_step'].split(',')
        if len(lr_decay_step) == 1:
            lr_decay_step = int(lr_decay_step[0])
        else:
            if not lr_decay_step[-1]:
                lr_decay_step = lr_decay_step[:-1]
            lr_decay_step = [int(x) for x in lr_decay_step]
        config['lr_decay_step'] = lr_decay_step

    config['method'] = options['method'] if 'method' in options else 'dft'
    if 'fixed' not in config['arch']:
        if config['method'] == 'flr':
            config['method'] = 'lru'
        elif config['method'] == 'fmx':
            config['method'] = 'max'
        elif config['method'] == 'fsm':
            config['method'] = 'sum'
    config['conv_balanced_row_num'] = options['conv_balanced_row_num'] \
                                        if 'conv_balanced_row_num' in options else 1
    config['fc_balanced_row_num'] = options['fc_balanced_row_num'] \
                                        if 'fc_balanced_row_num' in options else 1
    config['conv_balanced_freq'] = options['conv_balanced_freq'] \
                                        if 'conv_balanced_freq' in options else 1024
    config['fc_balanced_freq'] = options['fc_balanced_freq'] \
                                        if 'fc_balanced_freq' in options else 1024
    config[
        'rram_size'] = options['rram_size'] if 'rram_size' in options else 512
    config['small_rram_size'] = options['small_rram_size'] \
                                        if 'small_rram_size' in options else 128
    config['is_small_by_pos'] = options['is_small_by_pos'] \
                                        if 'is_small_by_pos' in options else False
    config[
        'input_bits'] = options['input_bits'] if 'input_bits' in options else 8
    config['output_bits'] = options[
        'output_bits'] if 'output_bits' in options else 8
    config['weight_bits'] = options[
        'weight_bits'] if 'weight_bits' in options else 8

    config_str = 'Training Config:\n'
    for key, val in config.items():
        config_str += '{}: {}\n'.format(key, val)

    print_section(config_str, up=89, down=False)

    alg_id = config['arch'] + '_' + config['method'] + \
             '_c_' + str(config['conv_balanced_row_num']) + \
             '_t_' + str(config['fc_balanced_row_num']) + \
             '_b_' + str(config['conv_balanced_freq']) + \
             '_f_' + str(config['fc_balanced_freq']) + \
             '_r_' + str(config['rram_size']) + \
             '_p_' + str(1 if config['is_small_by_pos'] else 0) + \
             '_h_' + str(config['small_rram_size']) + '_' + \
             datetime.datetime.now().strftime('%m%d_%H%M')

    print_section('saving to %s' % alg_id, up=False, down=89)

    config['checkpoint_dir'] = os.path.join('checkpoints', alg_id)
    config['log_dir'] = os.path.join('logs', alg_id)
    config['experiment_id'] = alg_id
    config['config_str'] = config_str

    return config