def find_traffic_ratio(segs, traffic_df, traffic_exp=1):
    """
    Creates metric for evaluation of trip prediciton model.
    Used to determine how trafficked routes are that are produced by the model.
    
    Parameters
    ----------
    segs : list
        List of dictionaries of steps for routes
    traffic_df : GeoDataFrame
        Dataframe containing traffic for each segment
    traffic_exp : float
        Factor to give preference in weighting to heavily trafficked routes
    
    Returns
    -------
    Float containing weighted average traffic.
    """
    
    # Initialize traffic distance, traffic percentage, and total traffic.
    traffic_perc_sum = 0
    traffic_dist_sum = 0
    traffic_sum = 0
    
    # Loop through all parts of the routes to find traffic.
    for seg in segs:
        for part in seg:
            
            # Find traffic for chosen section alone.
            traffic = traffic_df.loc[(traffic_df['station'] == part['station']) & 
                                     (traffic_df['direction'] == part['direction'])].iloc[0]['traffic']
            
            # Find coords of beginning and end of traffic segment to calculate distance.
            seg1 = part['geometry'][0].coords.xy
            x1 = seg1[0][0]
            y1 = seg1[1][0]
            seg2 = part['geometry'][-1].coords.xy
            x2 = seg2[0][-1]
            y2 = seg2[1][-1]
            dist = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
            
            # Multiple traffic by distance covered and traffic percentage.
            traffic_sum += traffic * dist * part['traffic_perc'] ** traffic_exp
            traffic_dist_sum += dist
            traffic_perc_sum += part['traffic_perc'] ** traffic_exp
            
    # Calculated the average traffic weighted by distance covered and proportion of total.
    traffic_avg = traffic_sum / traffic_dist_sum / traffic_perc_sum
    return traffic_avg