In [29]:
import h2o
import pandas
import pprint
import operator
import matplotlib
from tabulate import tabulate

In [30]:
# Connect to a cluster
h2o.init()


H2O cluster uptime: 31 seconds 66 milliseconds
H2O cluster version: 3.1.0.99999
H2O cluster name: spIdea
H2O cluster total nodes: 1
H2O cluster total memory: 12.44 GB
H2O cluster total cores: 8
H2O cluster allowed cores: 8
H2O cluster healthy: True
H2O Connection ip: 127.0.0.1
H2O Connection port: 54321

In [31]:
# set this to True if interactive (matplotlib) plots are desired
interactive = False
if not interactive: matplotlib.use('Agg', warn=False)
import matplotlib.pyplot as plt

In [32]:
# air_path = [h2o.locate("bigdata/laptop/airlines_all.05p.csv")]
# air_path = [h2o.locate("bigdata/laptop/flights-nyc/flights14.csv.zip")]
air_path = [h2o.locate("smalldata/airlines/allyears2k_headers.zip")]

# ----------

# 1- Load data - 1 row per flight.  Has columns showing the origin,
# destination, departure and arrival time, carrier information, and
# whether the flight was delayed.
print "Import and Parse airlines data"
data = h2o.import_file(path=air_path)
data.describe()


Import and Parse airlines data

Parse Progress: [##################################################] 100%

Parsed 43,978 rows and 31 cols:

File1 /Users/spencer/0xdata/h2o-3/smalldata/airlines/allyears2k_headers.zip
Rows: 43,978 Cols: 31
  chunk_type                 chunk_name  count  count_percentage        size  \
0        C0L          Constant Integers     10          5.376344      800  B   
1        C0D             Constant Reals     23         12.365591      1.8 KB   
2        CBS                       Bits      2          1.075269      2.0 KB   
3        CX0                Sparse Bits     10          5.376344      1.9 KB   
4         C1            1-Byte Integers     40         21.505377    287.8 KB   
5        C1N  1-Byte Integers (w/o NAs)     19         10.215054    133.1 KB   
6        C1S           1-Byte Fractions      6          3.225807     43.4 KB   
7         C2            2-Byte Integers     76         40.860214      1.1 MB   

   size_percentage  
0         0.050402  
1         0.115925  
2         0.127203  
3         0.124746  
4        18.564957  
5         8.586170  
6         2.802498  
7        69.628105  
                            size  number_of_rows  number_of_chunks_per_column  \
0  172.16.2.82:54321      1.5 MB           43978                            6   
1               mean      1.5 MB           43978                            6   
2                min      1.5 MB           43978                            6   
3                max      1.5 MB           43978                            6   
4             stddev        0  B               0                            0   
5              total      1.5 MB           43978                            6   

   number_of_chunks  
0               186  
1               186  
2               186  
3               186  
4                 0  
5               186  

Column-by-Column Summary:

Year Month DayofMonth DayOfWeek DepTime CRSDepTime ArrTime CRSArrTime UniqueCarrier FlightNum TailNum ActualElapsedTime CRSElapsedTime AirTime ArrDelay DepDelay Origin Dest Distance TaxiIn TaxiOut Cancelled CancellationCode Diverted CarrierDelay WeatherDelay NASDelay SecurityDelay LateAircraftDelay IsArrDelayed IsDepDelayed
type int int int int int int int int enum int enum int int int int int enum enum int int int int enum int int int int int int enum enum
mins 1987.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 0.0 1.0 0.0 16.0 17.0 14.0 -63.0 -16.0 0.0 0.0 11.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
maxs 2008.0 10.0 31.0 7.0 2400.0 2359.0 2400.0 2359.0 9.0 3949.0 3500.0 475.0 437.0 402.0 475.0 473.0 131.0 133.0 3365.0 128.0 254.0 1.0 3.0 1.0 369.0 201.0 323.0 14.0 373.0 1.0 1.0
sigma 6.34436090171 1.87471137134 9.17579042586 1.90501311913 465.340899124 476.251139993 484.347487904 492.750434123 NaN 777.404369164 NaN 73.9744416606 73.40159463 69.6363295151 29.8402219624 26.4388090429 NaN NaN 578.43800823 4.20197993986 9.9050857472 0.155193141358 NaN 0.0497234872189 16.2057299045 4.41677989873 18.6197762215 0.403940182102 23.4875658741 NaN NaN
zero_count 0 0 0 0 0 569 0 569 724 0 2 0 0 0 1514 6393 59 172 0 623 557 42892 81 43869 7344 8840 7388 8914 7140 19537 20887
missing_count 0 0 0 0 1086 0 1195 0 0 0 32 1195 13 16649 1195 1086 0 0 35 16026 16024 0 9774 0 35045 35045 35045 35045 35045 0 0

In [33]:
# ----------

# 2- Data exploration and munging. Generate scatter plots 
# of various columns and plot fitted GLM model.

# Function to fit a GLM model and plot the fitted (x,y) values
def scatter_plot(data, x, y, max_points = 1000, fit = True):
    if(fit):
        lr = h2o.glm(x = data[[x]], y = data[y], family = "gaussian")
        coeff = lr.coef()
    df = data[[x,y]]
    runif = df[y].runif()
    df_subset = df[runif < float(max_points)/data.nrow]
    df_py = h2o.as_list(df_subset)
    
    if(fit): h2o.remove(lr._id)

    # If x variable is string, generate box-and-whisker plot
    if(df_py[x].dtype == "object"):
        if interactive: df_py.boxplot(column = y, by = x)
    # Otherwise, generate a scatter plot
    else:
        if interactive: df_py.plot(x = x, y = y, kind = "scatter")
    
    if(fit):
        x_min = min(df_py[x])
        x_max = max(df_py[x])
        y_min = coeff["Intercept"] + coeff[x]*x_min
        y_max = coeff["Intercept"] + coeff[x]*x_max
        plt.plot([x_min, x_max], [y_min, y_max], "k-")
    if interactive: plt.show()

scatter_plot(data, "Distance", "AirTime", fit = True)
scatter_plot(data, "UniqueCarrier", "ArrDelay", max_points = 5000, fit = False)


glm Model Build Progress: [##################################################] 100%

In [34]:
# Group flights by month
grouped = data.group_by("Month")
bpd = grouped.count().sum("Cancelled").frame
bpd.show()
bpd.describe()
bpd.dim

# Convert columns to factors
data["Year"]      = data["Year"]     .asfactor()
data["Month"]     = data["Month"]    .asfactor()
data["DayOfWeek"] = data["DayOfWeek"].asfactor()
data["Cancelled"] = data["Cancelled"].asfactor()


H2OFrame with 2 rows and 3 columns: 
   Month  sum_Cancelled  nrow_Year
0      1           1067      41979
1     10             19       1999
Rows: 2 Cols: 3
  chunk_type                 chunk_name  count  count_percentage        size  \
0        C1N  1-Byte Integers (w/o NAs)      1         33.333336       70  B   
1         C2            2-Byte Integers      1         33.333336       72  B   
2        C2S           2-Byte Fractions      1         33.333336       88  B   

   size_percentage  
0        30.434782  
1        31.304348  
2        38.260868  
                            size  number_of_rows  number_of_chunks_per_column  \
0  172.16.2.82:54321      230  B               2                            1   
1               mean      230  B               2                            1   
2                min      230  B               2                            1   
3                max      230  B               2                            1   
4             stddev        0  B               0                            0   
5              total      230  B               2                            1   

   number_of_chunks  
0                 3  
1                 3  
2                 3  
3                 3  
4                 0  
5                 3  

Column-by-Column Summary:

Month sum_Cancelled nrow_Year
type int int int
mins 1.0 19.0 1999.0
maxs 10.0 1067.0 41979.0
sigma 6.36396103068 741.047906684 28270.1291118
zero_count 0 0 0
missing_count 0 0 0

In [35]:
# Calculate and plot travel time
hour1 = data["CRSArrTime"] / 100
mins1 = data["CRSArrTime"] % 100
arrTime = hour1*60 + mins1

hour2 = data["CRSDepTime"] / 100
mins2 = data["CRSDepTime"] % 100
depTime = hour2*60 + mins2

# TODO: Replace this once list comprehension is supported. See PUBDEV-1286.
# data["TravelTime"] = [x if x > 0 else None for x in (arrTime - depTime)]
data["TravelTime"] = h2o.ifelse((arrTime-depTime) > 0, (arrTime-depTime), h2o.H2OFrame(python_obj=[[None] for r in range(data.nrow)]))[0]
scatter_plot(data, "Distance", "TravelTime")


Parse Progress: [##################################################] 100%
Uploaded pye2fccd5b-2d5f-4c5c-8ea8-d8d0fbd6c556 into cluster with 43,978 rows and 1 cols

glm Model Build Progress: [##################################################] 100%

In [36]:
# Impute missing travel times and re-plot
data.impute(column = "Distance", by = ["Origin", "Dest"])
scatter_plot(data, "Distance", "TravelTime")


glm Model Build Progress: [##################################################] 100%

In [37]:
# ----------
# 3- Fit a model on train; using test as validation

# Create test/train split
s = data["Year"].runif()
train = data[s <= 0.75]
test  = data[s > 0.75]

# Set predictor and response variables
myY = "IsDepDelayed"
myX = ["Origin", "Dest", "Year", "UniqueCarrier", "DayOfWeek", "Month", "Distance", "FlightNum"]

# Simple GLM - Predict Delays
data_glm = h2o.glm(x           =train[myX],
                   y           =train[myY],
                   validation_x=test [myX],
                   validation_y=test [myY],
                   family      ="binomial",
                   standardize =True)

# Simple GBM
data_gbm = h2o.gbm(x              =train[myX],
                   y              =train[myY],
                   validation_x   =test [myX],
                   validation_y   =test [myY],
                   balance_classes=True,
                   ntrees         =3,
                   max_depth      =1,
                   distribution   ="bernoulli",
                   learn_rate     =0.1,
                   min_rows       =2)

# Complex GBM
data_gbm2 = h2o.gbm(x              =train[myX],
                    y              =train[myY],
                    validation_x   =test [myX],
                    validation_y   =test [myY],
                    balance_classes=True,
                    ntrees         =50,
                    max_depth      =5,
                    distribution   ="bernoulli",
                    learn_rate     =0.1,
                    min_rows       =2)

# Simple Random Forest
data_rf = h2o.random_forest(x              =train[myX],
                            y              =train[myY],
                            validation_x   =test [myX],
                            validation_y   =test [myY],
                            ntrees         =5,
                            max_depth      =2,
                            balance_classes=True)

# Complex Random Forest
data_rf2 = h2o.random_forest(x              =train[myX], 
                             y              =train[myY],
                             validation_x   =test [myX],
                             validation_y   =test [myY],
                             ntrees         =10,
                             max_depth      =5,
                             balance_classes=True)

# Deep Learning with 5 epochs
data_dl = h2o.deeplearning(x                   =train[myX],
                           y                   =train[myY],
                           validation_x        =test [myX],
                           validation_y        =test [myY],
                           hidden              =[10,10],
                           epochs              =5,
                           variable_importances=True,
                           balance_classes     =True,
                           loss                ="Automatic")


glm Model Build Progress: [##################################################] 100%

gbm Model Build Progress: [##################################################] 100%

gbm Model Build Progress: [##################################################] 100%

drf Model Build Progress: [##################################################] 100%

drf Model Build Progress: [##################################################] 100%

deeplearning Model Build Progress: [##################################################] 100%

In [38]:
# Variable importances from each algorithm
# Calculate magnitude of normalized GLM coefficients
glm_varimp = data_glm.coef_norm()
for k,v in glm_varimp.iteritems():
    glm_varimp[k] = abs(glm_varimp[k])
    
# Sort in descending order by magnitude
glm_sorted = sorted(glm_varimp.items(), key = operator.itemgetter(1), reverse = True)
table = tabulate(glm_sorted, headers = ["Predictor", "Normalized Coefficient"], tablefmt = "orgtbl")
print "Variable Importances:\n\n" + table

data_gbm.varimp()
data_rf.varimp()


Variable Importances:

| Predictor        |   Normalized Coefficient |
|------------------+--------------------------|
| Year.2008        |               2.24728    |
| Origin.MDW       |               1.59547    |
| Year.2003        |               1.57759    |
| Dest.HTS         |               1.46753    |
| Year.2007        |               1.4584     |
| Dest.LYH         |               1.42202    |
| Origin.HPN       |               1.41025    |
| Origin.LIH       |               1.40548    |
| Origin.LEX       |               1.27632    |
| UniqueCarrier.HP |               1.21406    |
| Origin.TLH       |               1.21254    |
| Origin.CAE       |               1.21213    |
| Origin.TRI       |               1.20846    |
| Year.2001        |               1.03136    |
| Origin.HNL       |               1.03046    |
| Origin.LBB       |               0.989776   |
| UniqueCarrier.TW |               0.982729   |
| Origin.BOI       |               0.967928   |
| Origin.BTV       |               0.967659   |
| Origin.ERI       |               0.96174    |
| Year.2002        |               0.960649   |
| Origin.CHO       |               0.942571   |
| Origin.ATL       |               0.916034   |
| Year.2004        |               0.881325   |
| Dest.UCA         |               0.875624   |
| Origin.PSP       |               0.873495   |
| Origin.OGG       |               0.872372   |
| Year.2006        |               0.864406   |
| Origin.PBI       |               0.863117   |
| Origin.STX       |               0.854991   |
| Dest.PSP         |               0.840601   |
| Origin.CRP       |               0.81258    |
| Origin.OKC       |               0.797135   |
| Dest.DAY         |               0.795684   |
| Dest.ICT         |               0.767982   |
| Dest.EYW         |               0.767268   |
| Origin.MYR       |               0.765509   |
| Origin.ORD       |               0.744525   |
| Dest.FLL         |               0.73777    |
| Origin.ICT       |               0.731529   |
| Origin.MSY       |               0.719711   |
| Origin.IAH       |               0.71042    |
| Origin.SAV       |               0.707789   |
| Origin.GRR       |               0.703089   |
| Year.1994        |               0.688751   |
| Origin.STL       |               0.686094   |
| Dest.TOL         |               0.679993   |
| Origin.JAX       |               0.663329   |
| Origin.ALB       |               0.661864   |
| Year.1996        |               0.658646   |
| Origin.CMH       |               0.644983   |
| Dest.FAY         |               0.6344     |
| Origin.ACY       |               0.632654   |
| Dest.KOA         |               0.625544   |
| Dest.IAH         |               0.624915   |
| Origin.SDF       |               0.609572   |
| Origin.PIT       |               0.607766   |
| Origin.MIA       |               0.600463   |
| Origin.LYH       |               0.597044   |
| Dest.CHO         |               0.597044   |
| Origin.GSO       |               0.591429   |
| Origin.AUS       |               0.57908    |
| Dest.LBB         |               0.578694   |
| Origin.SYR       |               0.561345   |
| Dest.CAK         |               0.56108    |
| Dest.ISP         |               0.55752    |
| Origin.FLL       |               0.54255    |
| Year.1997        |               0.540022   |
| UniqueCarrier.WN |               0.539566   |
| Dest.OAJ         |               0.536364   |
| Origin.ROA       |               0.520452   |
| Dest.IND         |               0.514779   |
| Year.1990        |               0.511814   |
| Dest.PNS         |               0.509169   |
| Origin.SLC       |               0.505784   |
| Origin.BDL       |               0.503187   |
| Origin.GEG       |               0.489823   |
| Dest.PBI         |               0.489803   |
| Dest.GRR         |               0.484824   |
| Origin.MRY       |               0.484161   |
| Dest.TPA         |               0.483592   |
| Origin.ABE       |               0.47344    |
| Origin.PWM       |               0.468946   |
| Dest.HRL         |               0.465021   |
| Dest.GEG         |               0.458675   |
| Dest.CVG         |               0.455877   |
| Dest.SFO         |               0.452515   |
| Origin.DAY       |               0.450969   |
| Year.2005        |               0.447775   |
| Origin.LAX       |               0.447015   |
| Origin.PHL       |               0.430459   |
| UniqueCarrier.CO |               0.420043   |
| Origin.IND       |               0.418681   |
| Origin.MLB       |               0.407967   |
| Origin.MCO       |               0.405488   |
| Dest.CAE         |               0.403574   |
| Origin.BUF       |               0.402803   |
| Dest.SEA         |               0.402281   |
| Origin.LGA       |               0.401911   |
| Dest.SWF         |               0.39869    |
| Dest.JAX         |               0.396652   |
| Origin.TUS       |               0.385616   |
| Origin.DFW       |               0.383559   |
| Origin.DSM       |               0.371667   |
| Dest.SBN         |               0.371571   |
| Origin.TUL       |               0.367658   |
| Dest.MCO         |               0.367261   |
| Dest.CRP         |               0.366593   |
| Year.1991        |               0.362482   |
| Dest.STL         |               0.362455   |
| Dest.SLC         |               0.361739   |
| Origin.CRW       |               0.360815   |
| Origin.RNO       |               0.360273   |
| Origin.OAK       |               0.359456   |
| Dest.ALB         |               0.356297   |
| Dest.CLE         |               0.353011   |
| Origin.MAF       |               0.338313   |
| Dest.BDL         |               0.334801   |
| Origin.SAN       |               0.329569   |
| UniqueCarrier.PI |               0.329279   |
| Dest.BUF         |               0.327111   |
| Dest.BTV         |               0.325156   |
| Dest.GSO         |               0.319204   |
| Origin.BOS       |               0.318607   |
| Dest.CHS         |               0.317406   |
| Dest.ELP         |               0.315479   |
| Origin.BWI       |               0.315088   |
| Year.1992        |               0.314022   |
| Dest.SAT         |               0.31367    |
| Origin.EYW       |               0.312034   |
| Year.1995        |               0.302042   |
| Origin.SRQ       |               0.299641   |
| Dest.BUR         |               0.299104   |
| Origin.ROC       |               0.290754   |
| Origin.MCI       |               0.287265   |
| Origin.CLE       |               0.286617   |
| Origin.BUR       |               0.283287   |
| UniqueCarrier.AA |               0.281278   |
| Dest.OGG         |               0.280422   |
| Dest.SDF         |               0.277877   |
| UniqueCarrier.US |               0.27431    |
| Origin.ELP       |               0.274259   |
| Dest.EUG         |               0.272207   |
| Origin.TPA       |               0.271724   |
| Dest.ABQ         |               0.271383   |
| Origin.IAD       |               0.270573   |
| DayOfWeek.5      |               0.269789   |
| Dest.HOU         |               0.268797   |
| Dest.ILM         |               0.268149   |
| Dest.MDT         |               0.266715   |
| Dest.BNA         |               0.26163    |
| Dest.STT         |               0.261447   |
| Origin.OMA       |               0.253576   |
| Origin.CLT       |               0.25261    |
| Dest.CLT         |               0.250311   |
| Origin.JFK       |               0.249345   |
| Dest.FAT         |               0.24554    |
| Dest.CMH         |               0.241114   |
| Origin.MSP       |               0.239473   |
| Dest.TUL         |               0.224285   |
| Origin.COS       |               0.219504   |
| Dest.DTW         |               0.217497   |
| Dest.AVL         |               0.213387   |
| Dest.MCI         |               0.20977    |
| Origin.MFR       |               0.207391   |
| Dest.PWM         |               0.207242   |
| Origin.DAL       |               0.205059   |
| Origin.HOU       |               0.203394   |
| Dest.BHM         |               0.197903   |
| Dest.ORF         |               0.19294    |
| Month.10         |               0.187222   |
| Year.1987        |               0.187222   |
| Origin.EGE       |               0.180792   |
| Origin.DEN       |               0.179952   |
| Origin.ISP       |               0.174243   |
| Year.1993        |               0.173293   |
| Dest.LIH         |               0.170721   |
| DayOfWeek.2      |               0.169883   |
| Dest.MHT         |               0.167742   |
| Dest.IAD         |               0.165001   |
| Origin.BGM       |               0.163643   |
| Dest.EWR         |               0.162917   |
| Origin.MKE       |               0.162378   |
| Dest.OAK         |               0.157643   |
| Dest.BWI         |               0.15603    |
| Origin.MEM       |               0.153869   |
| Origin.PHX       |               0.153674   |
| Year.2000        |               0.152418   |
| Dest.BGM         |               0.151851   |
| Dest.RIC         |               0.149916   |
| Origin.ONT       |               0.146539   |
| Dest.LAX         |               0.144316   |
| Distance         |               0.144267   |
| Dest.RDU         |               0.143991   |
| Dest.PHL         |               0.138917   |
| DayOfWeek.6      |               0.133428   |
| Origin.BHM       |               0.132968   |
| Dest.ROA         |               0.132521   |
| Dest.SMF         |               0.132232   |
| Dest.LAS         |               0.127781   |
| Origin.DTW       |               0.127768   |
| Origin.MDT       |               0.124059   |
| DayOfWeek.4      |               0.122907   |
| Dest.SAN         |               0.122874   |
| Origin.SAT       |               0.119602   |
| Dest.PDX         |               0.115125   |
| Origin.SFO       |               0.113358   |
| Origin.SJC       |               0.111984   |
| Origin.TYS       |               0.111277   |
| Origin.SWF       |               0.105881   |
| Dest.BOS         |               0.103609   |
| Year.1989        |               0.0965433  |
| Dest.MIA         |               0.0960485  |
| Dest.MDW         |               0.0956308  |
| Dest.ABE         |               0.0952436  |
| Dest.COS         |               0.0952059  |
| Dest.BOI         |               0.0885131  |
| Origin.ORF       |               0.0878982  |
| Month.1          |               0.0857064  |
| Dest.MSP         |               0.082894   |
| Year.1999        |               0.0817179  |
| Dest.TUS         |               0.0793073  |
| Dest.PHX         |               0.0791952  |
| Dest.ORD         |               0.0779564  |
| Dest.HPN         |               0.0717389  |
| Dest.RSW         |               0.0697825  |
| Dest.ONT         |               0.0672819  |
| Dest.ATL         |               0.0671189  |
| UniqueCarrier.UA |               0.0668843  |
| Dest.DCA         |               0.0660187  |
| Origin.SMF       |               0.0610132  |
| Origin.EWR       |               0.0609084  |
| Dest.SNA         |               0.0601334  |
| Origin.SJU       |               0.0597758  |
| Dest.PVD         |               0.0564552  |
| Dest.ROC         |               0.0546891  |
| Origin.MHT       |               0.0514589  |
| DayOfWeek.7      |               0.0510175  |
| Year.1998        |               0.0494702  |
| Dest.MSY         |               0.049311   |
| Origin.LIT       |               0.0441837  |
| Dest.GSP         |               0.043447   |
| FlightNum        |               0.0403853  |
| UniqueCarrier.PS |               0.0377268  |
| Origin.BNA       |               0.0366448  |
| Origin.HRL       |               0.0358735  |
| Dest.SYR         |               0.0350688  |
| Dest.ELM         |               0.0346979  |
| Origin.DCA       |               0.0317794  |
| Origin.ABQ       |               0.0309305  |
| Dest.PIT         |               0.0306693  |
| Year.1988        |               0.0292573  |
| Origin.UCA       |               0.0292527  |
| Dest.SJC         |               0.0285497  |
| Dest.RNO         |               0.0285102  |
| Origin.SEA       |               0.0269592  |
| Origin.PHF       |               0.0261973  |
| Dest.LGA         |               0.0229975  |
| Origin.RDU       |               0.0219074  |
| Origin.SNA       |               0.0176885  |
| DayOfWeek.3      |               0.0126008  |
| Origin.CHS       |               0.00999654 |
| Dest.AMA         |               0.00952433 |
| Origin.AVP       |               0.00620583 |
| Intercept        |               0.00490342 |
| Dest.DEN         |               0.00415732 |
| Dest.LIT         |               0          |
| Dest.OKC         |               0          |
| Origin.PDX       |               0          |
| Dest.ORH         |               0          |
| Origin.ANC       |               0          |
| Dest.SRQ         |               0          |
| Dest.MRY         |               0          |
| Dest.SJU         |               0          |
| UniqueCarrier.DL |               0          |
| Origin.RSW       |               0          |
| Dest.DSM         |               0          |
| Origin.CVG       |               0          |
| Dest.MKE         |               0          |
| Dest.HNL         |               0          |
| Origin.LAS       |               0          |
| Origin.SCK       |               0          |
| Origin.RIC       |               0          |
| Origin.LAN       |               0          |
| Dest.AUS         |               0          |
| Origin.KOA       |               0          |
| Dest.DAL         |               0          |
| Dest.JFK         |               0          |
| Origin.AMA       |               0          |
| Dest.DFW         |               0          |
| Dest.ERI         |               0          |
| Dest.ACY         |               0          |
| Dest.FNT         |               0          |
| Dest.JAN         |               0          |
| Origin.STT       |               0          |
| Dest.CHA         |               0          |
| Origin.PVD       |               0          |
| Origin.SBN       |               0          |
| Origin.GNV       |               0          |
| Dest.LEX         |               0          |
| Origin.JAN       |               0          |
| Dest.MAF         |               0          |
| Dest.PHF         |               0          |
| Dest.ANC         |               0          |
| Dest.OMA         |               0          |
| Dest.AVP         |               0          |
| DayOfWeek.1      |               0          |
| Dest.MYR         |               0          |
| Dest.SCK         |               0          |
| Origin.BIL       |               0          |
        variable  relative_importance  scaled_importance  percentage
0           Year          1192.057617                  1           1
1         Origin             0.000000                  0           0
2           Dest             0.000000                  0           0
3  UniqueCarrier             0.000000                  0           0
4      DayOfWeek             0.000000                  0           0
5          Month             0.000000                  0           0
6       Distance             0.000000                  0           0
7      FlightNum             0.000000                  0           0
        variable  relative_importance  scaled_importance  percentage
0           Year          1292.531738           1.000000    0.634876
1         Origin           396.547455           0.306799    0.194779
2  UniqueCarrier           188.634476           0.145942    0.092655
3      DayOfWeek            77.516624           0.059973    0.038075
4      FlightNum            55.407917           0.042868    0.027216
5       Distance            25.240950           0.019528    0.012398
6           Dest             0.000000           0.000000    0.000000
7          Month             0.000000           0.000000    0.000000

In [ ]:
# Model performance of GBM model on test data
data_gbm2.model_performance(test)