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

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


H2O cluster uptime: 6 minutes 1 seconds 983 milliseconds
H2O cluster version: 3.1.0.99999
H2O cluster name: ece
H2O cluster total nodes: 1
H2O cluster total memory: 3.56 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 [17]:
# 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 [18]:
# 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/ece/0xdata/h2o-dev/smalldata/airlines/allyears2k_headers.zip
Rows: 43,978 Cols: 31

Chunk compression summary:

chunk_type chunk_name count count_percentage size size_percentage
C0L Constant Integers 10 5.376344 800 B 0.05040237
C0D Constant Reals 23 12.365591 1.8 KB 0.115925446
CBS Bits 2 1.0752689 2.0 KB 0.12720299
CX0 Sparse Bits 10 5.376344 1.9 KB 0.12474586
C1 1-Byte Integers 40 21.505377 287.8 KB 18.564957
C1N 1-Byte Integers (w/o NAs) 19 10.215054 133.1 KB 8.58617
C1S 1-Byte Fractions 6 3.2258065 43.4 KB 2.8024976
C2 2-Byte Integers 76 40.860214 1.1 MB 69.628105
Frame distribution summary:

size number_of_rows number_of_chunks_per_column number_of_chunks
172.16.2.17:54321 1.5 MB 43978.0 6.0 186.0
mean 1.5 MB 43978.0 6.0 186.0
min 1.5 MB 43978.0 6.0 186.0
max 1.5 MB 43978.0 6.0 186.0
stddev 0 B 0.0 0.0 0.0
total 1.5 MB 43978.0 6.0 186.0
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 2.05121227084 777.404369164 1168.75931155 73.9744416606 73.40159463 69.6363295151 29.8402219624 26.4388090429 37.64411521 33.930070329 578.43800823 4.20197993986 9.9050857472 0.155193141358 0.182676305421 0.0497234872189 16.2057299045 4.41677989873 18.6197762215 0.403940182102 23.4875658741 0.496887288343 0.499377380318
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 [19]:
# ----------

# 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 [20]:
# Group flights by month
grouped = data.group_by("Month")
bpd = grouped.count("Month").sum("Cancelled").get_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()


First 2 rows and first 3 columns: 
Month Cancelled Month
10 19990 1999
1 41979 41979
Rows: 2 Cols: 3

Chunk compression summary:

chunk_type chunk_name count count_percentage size size_percentage
C1N 1-Byte Integers (w/o NAs) 1 33.333336 70 B 28.455284
C2S 2-Byte Fractions 2 66.66667 176 B 71.544716
Frame distribution summary:

size number_of_rows number_of_chunks_per_column number_of_chunks
172.16.2.17:54321 246 B 2.0 1.0 3.0
mean 246 B 2.0 1.0 3.0
min 246 B 2.0 1.0 3.0
max 246 B 2.0 1.0 3.0
stddev 0 B 0.0 0.0 0.0
total 246 B 2.0 1.0 3.0
Column-by-Column Summary:

Month Cancelled Month
type int int int
mins 1.0 19990.0 1999.0
maxs 10.0 41979.0 41979.0
sigma 6.36396103068 15548.5710115 28270.1291118
zero_count 0 0 0
missing_count 0 0 0

In [21]:
# 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 py6c3155a4-db83-48e2-a484-689af0060304 into cluster with 43,978 rows and 1 cols

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

In [22]:
# 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 [23]:
# ----------
# 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 [24]:
# 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.28585    |
| Origin.HPN       |               1.69543    |
| Origin.LIH       |               1.638      |
| Year.2003        |               1.60594    |
| Origin.MDW       |               1.47263    |
| Year.2007        |               1.47175    |
| Dest.LYH         |               1.46167    |
| Dest.HTS         |               1.28846    |
| Origin.ERI       |               1.278      |
| UniqueCarrier.HP |               1.14024    |
| Origin.TLH       |               1.09897    |
| Origin.HNL       |               1.08373    |
| Origin.TRI       |               1.06732    |
| Origin.LEX       |               0.997993   |
| Origin.CHO       |               0.983148   |
| Year.2001        |               0.970752   |
| Year.2002        |               0.933122   |
| Origin.CAE       |               0.902027   |
| Origin.ATL       |               0.894547   |
| Origin.BTV       |               0.893457   |
| UniqueCarrier.TW |               0.889156   |
| Year.2004        |               0.886399   |
| Origin.GRR       |               0.871216   |
| Dest.HRL         |               0.867962   |
| Dest.PSP         |               0.840745   |
| Origin.CRP       |               0.822434   |
| Origin.LBB       |               0.817352   |
| Origin.IAH       |               0.808256   |
| Origin.MYR       |               0.802024   |
| Year.2006        |               0.798849   |
| Origin.ORD       |               0.79383    |
| Origin.PBI       |               0.788992   |
| Origin.ALB       |               0.784671   |
| Year.1994        |               0.763265   |
| Dest.CRP         |               0.762099   |
| Origin.MIA       |               0.752895   |
| Dest.FLL         |               0.749217   |
| Origin.MAF       |               0.728962   |
| Origin.MLB       |               0.713006   |
| Origin.SAV       |               0.71218    |
| Origin.JAX       |               0.692974   |
| Origin.SRQ       |               0.687874   |
| Origin.LYH       |               0.684658   |
| Dest.CHO         |               0.684658   |
| Origin.TYS       |               0.683076   |
| Dest.OGG         |               0.676616   |
| Origin.CMH       |               0.673951   |
| Origin.ROA       |               0.666507   |
| Dest.LBB         |               0.662483   |
| Origin.SDF       |               0.641484   |
| Origin.AUS       |               0.63652    |
| Origin.MRY       |               0.625337   |
| Year.1990        |               0.624939   |
| Year.1996        |               0.618682   |
| Dest.ICT         |               0.616668   |
| Dest.ISP         |               0.611902   |
| Dest.ELM         |               0.609561   |
| Dest.EUG         |               0.591384   |
| Origin.OGG       |               0.586688   |
| Dest.EYW         |               0.5865     |
| Origin.SYR       |               0.582702   |
| Dest.TOL         |               0.581877   |
| Dest.GEG         |               0.565753   |
| Year.1997        |               0.560108   |
| Origin.LAX       |               0.559894   |
| Dest.PWM         |               0.559299   |
| Origin.STL       |               0.546315   |
| Origin.PIT       |               0.543209   |
| Dest.IAH         |               0.540819   |
| Origin.OMA       |               0.538106   |
| Origin.PWM       |               0.537704   |
| Dest.PBI         |               0.534746   |
| Year.2005        |               0.534319   |
| Origin.GSO       |               0.525335   |
| Dest.IND         |               0.52243    |
| Dest.SFO         |               0.515403   |
| Origin.PSP       |               0.511714   |
| Dest.DAY         |               0.511048   |
| Origin.ACY       |               0.510181   |
| Dest.LIH         |               0.505466   |
| Dest.CAK         |               0.505063   |
| UniqueCarrier.WN |               0.498225   |
| Origin.IND       |               0.482325   |
| Origin.MSY       |               0.480748   |
| Origin.DFW       |               0.469985   |
| Origin.PHL       |               0.464258   |
| Dest.CLE         |               0.462228   |
| Origin.LGA       |               0.455195   |
| Origin.TUL       |               0.453434   |
| Origin.BOI       |               0.447635   |
| Dest.SAT         |               0.447196   |
| Origin.FLL       |               0.445939   |
| Origin.BDL       |               0.439833   |
| Origin.SWF       |               0.437605   |
| UniqueCarrier.PI |               0.433718   |
| Origin.SLC       |               0.426539   |
| Origin.MCI       |               0.424545   |
| Origin.TUS       |               0.417783   |
| Dest.HPN         |               0.411631   |
| Origin.DSM       |               0.411606   |
| Origin.RNO       |               0.411522   |
| Dest.JAX         |               0.408934   |
| Dest.GSO         |               0.408902   |
| Dest.BDL         |               0.404167   |
| Dest.OMA         |               0.394134   |
| Origin.JFK       |               0.390293   |
| Dest.BTV         |               0.380099   |
| Dest.RSW         |               0.379812   |
| Dest.FAY         |               0.377839   |
| Dest.CAE         |               0.376909   |
| Year.1995        |               0.367422   |
| Origin.MCO       |               0.361513   |
| Dest.CMH         |               0.354512   |
| Dest.ROC         |               0.349751   |
| Dest.ABQ         |               0.349527   |
| Origin.SBN       |               0.347592   |
| Dest.SBN         |               0.347142   |
| Dest.SEA         |               0.344818   |
| Dest.BUR         |               0.34096    |
| Origin.DAY       |               0.338753   |
| Origin.ABE       |               0.336332   |
| Origin.EYW       |               0.336039   |
| Dest.CHS         |               0.334728   |
| UniqueCarrier.CO |               0.334387   |
| Dest.TPA         |               0.331029   |
| Origin.ROC       |               0.325753   |
| Origin.EGE       |               0.319721   |
| Dest.ORF         |               0.317641   |
| Origin.OAK       |               0.308584   |
| Dest.SMF         |               0.305322   |
| Dest.COS         |               0.30247    |
| Origin.BUF       |               0.299938   |
| Dest.MIA         |               0.298249   |
| Dest.MCO         |               0.297899   |
| Dest.BUF         |               0.295137   |
| Origin.BWI       |               0.294905   |
| Dest.ONT         |               0.292885   |
| Dest.FNT         |               0.28822    |
| Origin.BUR       |               0.281797   |
| Year.1992        |               0.280546   |
| Origin.IAD       |               0.27936    |
| Dest.FAT         |               0.273401   |
| Dest.JFK         |               0.269927   |
| Dest.STT         |               0.268764   |
| UniqueCarrier.US |               0.266601   |
| Origin.STX       |               0.263423   |
| UniqueCarrier.AA |               0.262845   |
| Origin.SFO       |               0.250746   |
| Origin.BOS       |               0.248806   |
| Year.1991        |               0.248019   |
| Origin.MDT       |               0.247859   |
| Origin.SAN       |               0.242567   |
| Origin.CRW       |               0.242378   |
| Origin.CLE       |               0.241045   |
| Origin.TPA       |               0.240183   |
| DayOfWeek.5      |               0.240084   |
| Dest.GRR         |               0.238805   |
| Origin.CLT       |               0.234494   |
| Dest.PVD         |               0.23327    |
| Origin.ISP       |               0.227559   |
| Origin.BHM       |               0.223795   |
| Dest.LAX         |               0.223084   |
| Dest.AUS         |               0.221357   |
| Dest.STL         |               0.216283   |
| Month.10         |               0.215756   |
| Year.1987        |               0.215756   |
| Origin.DEN       |               0.207292   |
| Dest.HOU         |               0.197121   |
| DayOfWeek.2      |               0.196145   |
| Origin.COS       |               0.19495    |
| Origin.PHF       |               0.192259   |
| Year.1999        |               0.184897   |
| Dest.SLC         |               0.183123   |
| Dest.IAD         |               0.18098    |
| Year.1993        |               0.179029   |
| Dest.CLT         |               0.17834    |
| Dest.MKE         |               0.175025   |
| Year.1989        |               0.170732   |
| Year.2000        |               0.168468   |
| Origin.OKC       |               0.168022   |
| Dest.PNS         |               0.167044   |
| Origin.SJC       |               0.166982   |
| Dest.ABE         |               0.161995   |
| Dest.ALB         |               0.155992   |
| Dest.KOA         |               0.153826   |
| Origin.MKE       |               0.152076   |
| Origin.MEM       |               0.150336   |
| Dest.ROA         |               0.149467   |
| Dest.MSY         |               0.149433   |
| Dest.OAJ         |               0.14703    |
| Dest.UCA         |               0.146961   |
| Origin.ORF       |               0.146924   |
| DayOfWeek.6      |               0.144938   |
| Dest.OAK         |               0.143941   |
| Dest.DFW         |               0.143417   |
| Origin.LIT       |               0.142983   |
| Origin.ICT       |               0.142473   |
| Dest.MSP         |               0.133873   |
| Distance         |               0.131822   |
| Dest.EWR         |               0.130674   |
| Dest.ORD         |               0.127552   |
| Dest.DTW         |               0.125984   |
| UniqueCarrier.UA |               0.124704   |
| Dest.SAN         |               0.123502   |
| Dest.PHX         |               0.121518   |
| Origin.HRL       |               0.11843    |
| Dest.BGM         |               0.115701   |
| DayOfWeek.4      |               0.114728   |
| Dest.SNA         |               0.110722   |
| Dest.LIT         |               0.106559   |
| Dest.AVL         |               0.105538   |
| Dest.PDX         |               0.100889   |
| Origin.AVP       |               0.0999959  |
| Origin.DTW       |               0.0987268  |
| Month.1          |               0.0971013  |
| Dest.BOI         |               0.0957132  |
| Dest.PHL         |               0.0861169  |
| Origin.KOA       |               0.0846479  |
| Dest.TUS         |               0.0833103  |
| Origin.ELP       |               0.0815918  |
| UniqueCarrier.DL |               0.0797336  |
| Dest.MDW         |               0.0783464  |
| Dest.MCI         |               0.0773476  |
| Dest.SYR         |               0.0771775  |
| Origin.BGM       |               0.0750723  |
| Dest.SDF         |               0.0728507  |
| Origin.PVD       |               0.072424   |
| Origin.RDU       |               0.071411   |
| Dest.BWI         |               0.0706066  |
| Origin.PHX       |               0.0701844  |
| Dest.BHM         |               0.0701488  |
| Dest.RIC         |               0.0692202  |
| Origin.ABQ       |               0.055422   |
| Dest.ILM         |               0.0543805  |
| Intercept        |               0.0519814  |
| Dest.LAS         |               0.0487192  |
| Origin.SAT       |               0.0480328  |
| DayOfWeek.7      |               0.0460972  |
| Dest.DEN         |               0.0459439  |
| Dest.AVP         |               0.0450818  |
| Dest.ELP         |               0.0445682  |
| Dest.BNA         |               0.0420472  |
| Dest.DSM         |               0.0419726  |
| Origin.HOU       |               0.0393885  |
| Origin.PDX       |               0.0363553  |
| Origin.SNA       |               0.0354122  |
| Origin.SEA       |               0.0344875  |
| Dest.ACY         |               0.0340972  |
| Origin.CVG       |               0.0328146  |
| Year.1998        |               0.0318468  |
| Origin.SCK       |               0.031524   |
| Origin.GEG       |               0.0312209  |
| Dest.RDU         |               0.0310516  |
| Origin.LAS       |               0.03026    |
| Dest.MYR         |               0.0302372  |
| Dest.RNO         |               0.0291863  |
| Dest.DCA         |               0.0284603  |
| Origin.BNA       |               0.0282776  |
| Origin.SJU       |               0.027342   |
| Origin.AMA       |               0.0262528  |
| DayOfWeek.3      |               0.0247432  |
| Dest.SJC         |               0.023634   |
| Dest.CVG         |               0.0235706  |
| FlightNum        |               0.0230809  |
| Origin.RSW       |               0.0229344  |
| Origin.SMF       |               0.0190434  |
| Dest.PIT         |               0.0188431  |
| Dest.TUL         |               0.0187144  |
| Origin.EWR       |               0.018464   |
| Dest.MHT         |               0.01552    |
| Dest.LGA         |               0.0145985  |
| Origin.MFR       |               0.0138638  |
| Origin.DAL       |               0.0127005  |
| Origin.DCA       |               0.00678773 |
| Dest.BOS         |               0.00302899 |
| Dest.ATL         |               0.00172438 |
| Dest.OKC         |               0          |
| Dest.ORH         |               0          |
| Origin.ANC       |               0          |
| Dest.SRQ         |               0          |
| Dest.MRY         |               0          |
| Dest.SJU         |               0          |
| Year.1988        |               0          |
| Dest.HNL         |               0          |
| Origin.RIC       |               0          |
| Origin.LAN       |               0          |
| Dest.SWF         |               0          |
| Dest.DAL         |               0          |
| Origin.UCA       |               0          |
| Dest.ERI         |               0          |
| Dest.GSP         |               0          |
| Origin.CHS       |               0          |
| Origin.ONT       |               0          |
| Origin.MHT       |               0          |
| Dest.JAN         |               0          |
| Origin.STT       |               0          |
| Dest.CHA         |               0          |
| Dest.MDT         |               0          |
| Origin.GNV       |               0          |
| Dest.AMA         |               0          |
| Dest.LEX         |               0          |
| Origin.JAN       |               0          |
| UniqueCarrier.PS |               0          |
| Dest.MAF         |               0          |
| Dest.PHF         |               0          |
| Dest.ANC         |               0          |
| DayOfWeek.1      |               0          |
| Dest.SCK         |               0          |
| Origin.BIL       |               0          |
| Origin.MSP       |               0          |

Variable Importances:

variable relative_importance scaled_importance percentage
Year 1232.10693359 1.0 1.0
Month 0.0 0.0 0.0
DayOfWeek 0.0 0.0 0.0
UniqueCarrier 0.0 0.0 0.0
FlightNum 0.0 0.0 0.0
Origin 0.0 0.0 0.0
Dest 0.0 0.0 0.0
Distance 0.0 0.0 0.0
Variable Importances:

variable relative_importance scaled_importance percentage
Year 958.766235352 1.0 0.464951857621
UniqueCarrier 421.378601074 0.439500876791 0.20434674909
Origin 326.425598145 0.340464219649 0.158299471379
Dest 215.331390381 0.224592171106 0.104424547163
DayOfWeek 63.3812866211 0.0661071325669 0.030736634089
Distance 49.1944389343 0.0513101495656 0.0238567493553
FlightNum 27.5988121033 0.0287857572426 0.013383991303
Month 0.0 0.0 0.0

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


ModelMetricsBinomial: gbm
** Reported on test data. **

MSE: 0.206699881626
R^2: 0.170097556169
LogLoss: 0.600060926768
AUC: 0.738659969845
Gini: 0.477319939689

Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.363358307534:

NO YES Error Rate
NO 2089.0 3070.0 0.5951 (3070.0/5159.0)
YES 722.0 5109.0 0.1238 (722.0/5831.0)
Total 2811.0 8179.0 0.345 (3792.0/10990.0)
Maximum Metrics:

metric threshold value idx
max f1 0.363358307534 0.729336188437 286.0
max f2 0.203942289596 0.85126451689 366.0
max f0point5 0.536019190093 0.698500394633 193.0
max accuracy 0.469497349455 0.677434030937 226.0
max precision 0.957183699314 1.0 0.0
max absolute_MCC 0.500239647442 0.351861408571 211.0
max min_per_class_accuracy 0.507579143879 0.675712347354 208.0
Out[25]: