def find_avg_distance(segs, traffic_exp=1):
    """
    Creates metric for evaluation of trip prediciton model.
    Used to determine average distance from beginning coordinate for each segment travelled.
    
    Parameters
    ----------
    segs : list
        List of dictionaries of steps for routes
    traffic_exp : float
        Factor to give preference in weighting to heavily trafficked routes
        Default is 1
        
    Return
    ------
    Float containing weighted average distance.
    """
    
    # Initialize distance and traffic percentage.
    total_dist_traffic = 0
    total_traffic_perc = 0
    
    # Get coords of initial point.
    coords1 = segs[0][0]['geometry'][0].coords.xy
    x1 = coords1[0][0]
    y1 = coords1[1][0]
    
    # Loop through all parts of all routed to obtain distances
    for seg in segs:
        for part in seg:
            
            # Extract coords of end of each segment.
            coords2 = part['geometry'][-1].coords.xy
            x2 = coords2[0][-1]
            y2 = coords2[1][-1]
            
            # Calculate distance between end of segment and start of routes
            dist = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
            
            # Weight distance by traffic percentage
            dist_traffic = dist * part['traffic_perc'] ** traffic_exp
            total_traffic_perc += part['traffic_perc'] ** traffic_exp
            total_dist_traffic += dist_traffic
    
    # Calculated weighted average of travel distance.
    avg_distance = total_dist_traffic / total_traffic_perc
    return avg_distance