Пример #1
0
def encodeNumericalData(interp_params, keyday, bkd, auth, avail, cap):
    start, stop, num_points = interp_params
    keyday, bkd, auth, avail = Utils.sortByIndex(keyday, bkd, auth, avail)
    keyday, bkd, auth, avail, cap = filterDataForKeyDay(
        start, keyday, bkd, auth, avail, cap)
    keyday, bkd, auth, avail, cap = interpolateFlight(
        interp_params, keyday, bkd, auth, avail, cap)

    # Create any other features
    delta_bkd = np.diff(bkd)

    # Stack the numerical data into a feature matrix
    nums = [each[:-1] for each in [keyday, bkd, auth, avail, cap]]
    nums = np.column_stack(nums)

    return delta_bkd, nums
Пример #2
0
def bookingClassTicketFrequencies(f, data, cabin):
    print "Grouping into unique flight/booking class combinations"
    flight_data = f.getUniqueFlightsAndBookings(data)

    bcs = Utils.mapCabinToBookingClasses(cabin)
    bcs = {bc: 0 for (bc, r) in bcs}

    print "Iterating through all booking classes"
    for flight, flight_df in flight_data:
        bc = flight[-1]
        keyday = -1 * flight_df["KEYDAY"]
        bkd = flight_df["BKD"]

        keyday, bkd = Utils.sortByIndex(keyday, bkd)

        bcs[bc] += bkd[-1]

    total_bkd = 0.0
    for bc, num_bkd in bcs.items():
        total_bkd += num_bkd

    for bc in bcs:
        bcs[bc] /= total_bkd

    ks, vs = zip(*bcs.items())
    ks, vs = zip(*sorted(zip(ks, vs), key=lambda tup: Utils.compareBCs(tup[0])))
    indices = np.arange(len(ks))
    width = 0.75

    fig, ax = plt.subplots()
    rects = ax.bar(indices, vs, width)
    ax.set_ylabel("Percent of Total Booked")
    ax.set_title("Booking Class Ticketing Distribution - Economy Cabin")
    ax.set_xticks(indices + width / 2.0)
    ax.set_xticklabels(ks)

    plt.grid()
    plt.show()