[Music]
you've learned the basic ideas behind
some common classification models now
let's apply that knowledge to the taxi
data
commercial navigation apps provide a lot
of information about your trip distance
estimated travel time and tolls you may
encounter on route
can the pickup and drop-off locations
from the taxi data predict if the trip
will have a toll
let's use a binary classification model
to find out
in this video you will create
classification models using the
classification learner app
compare the performance of those models
and export your work to matlab for
further analysis
the classification learner app uses the
same workflow as the regression learner
app
once you have selected your data the app
enables you to iterate through the
process of choosing training and
assessing your model before exporting to
matlab
to get started you first need to import
and prepare your data in matlab
here the january taxi data is loaded
the add was tool paid function adds a
variable to the table indicating if a
toll was paid to each trip this will
serve as the response variable for the
classification models
with the data pre-processing done let's
open the classification learner app
in the apps tab of the tool strip choose
the classification learner app
just as you did with the regression
learner app start a new session by
clicking new session
and selecting from workspace
select was tool paid as the response
variable
classification response variables are
most often logical or categorical
variables since these naturally break
the data set into different classes
in the predictors pane unselect all of
the variables and select the four
features that will be used to build the
predictive model
the latitude and longitude of the pickup
location and the latitude and longitude
of the drop-off location
as with the regression learner app your
typical workflow will involve using
validation as part of your model
training but that topic will be covered
in a future lesson so for now select no
validation
click start session to finish loading
the data set
the classification learner app mirrors
the regression learner app
the tool strip along the top enables you
to easily choose the model type access
model options train the model and
visualize the results
the left pane shows the model history
and the details of the current model
the center pane shows model
visualizations
the default is a scatter plot of the
data
here pickup locations are displayed and
grouped according to the was toll paid
variable
the blue dots indicate that no toll was
paid
the main differences between the two
apps are in the models and
visualizations available
open the model type pane to see the
available classification models
logistic regression is a good starting
point for creating a binary
classification model
it's quick to train and provides a
simple expression to classify the data
now let's train the model
wow the model only took a few seconds to
train and it has over 95 accuracy
the group scatter plot now uses markers
to indicate where the model correctly
predicted that a toll was paid
dots represent a correct prediction and
x's represent when the model was
incorrect
more specifically blue x's indicate
where there was no toll paid but the
model predicted a toll
and orange x's indicate where a toll was
paid but the model didn't predict it
that's a bit confusing but a confusion
matrix can clear things up
this visualization shows how often a
model gets each class right
and which class is chosen when the model
misclassifies a data point
the rows represent the value of was tool
paid from the data set
the top row of the matrix shows trips
that did not have a toll and the bottom
row shows trips that did have a toll
the columns represent the model
predictions
the first column contains trips that the
model predicted would not have a tool
and the second column contains trips
that the model predicted would have a
tool
the main diagonal elements are the trips
where the model correctly predicted the
response either true negatives where
there was no toll and the model
predicted no toll
or true positives where there was a tool
and the model predicted a tool
the off diagonal entries show where the
model made an incorrect
prediction the top right corner shows
the false positives the model predicted
a toll that wasn't there
the bottom corner shows the false
negatives
here the model incorrectly predicted a
toll-free trip
in this situation a false positive could
be a pleasant surprise you expected a
toll and didn't have to pay one
but a false negative means a surprise
toll
too many of those would be annoying
but what if instead of tolls you were
testing for a disease
here a false positive could be scary and
lead to extra testing but a false
negative could lead to serious illness
going undiagnosed delaying possible
treatments
your domain knowledge will guide you in
deciding when false positives and false
negatives are acceptable
minimizing one or the other could be
very important
in this model only about 10 of the
actual tolls are correctly predicted by
the model
this is because of the imbalance in the
class sizes
out of the over 230 000 trips fewer than
10 000 had a toll
since only about four percent of the
trips have tolls a model that always
predicts no toll would have 96 accuracy
it just wouldn't be very useful
models like logistic regression and svm
often have trouble dealing with data
sets with imbalanced classes like this
let's try a k-nearest neighbor or k n
model instead
the app has several options for nearest
neighbor classifiers
the fine medium and coarse models use
euclidean distance while cosine cubic
and weighted use more complex distance
measures
choose medium k n as a starting point
this model has tuning options available
via the advanced button
a medium k n model uses the 10 nearest
data points to make a prediction
a course model looks at the 100 closest
points
and a fine model uses the single closest
point to make its prediction
let's train the model
99 accuracy
remember though always predicting no
toll was 96 accurate
the scatter plot has significantly fewer
visible x's
this model looks promising but
let's check the confusion matrix
there are many more true positives with
this model
it looks like the k n model could be a
good choice for this prediction
to determine how good we'll need more
performance measurements
the following lessons will cover these
in detail for now let's save your work
by exporting the model to matlab
like the regression learner app the
classification learner app has the
option to save the algorithm used to
train the model or to export the train
model directly into the matlab workspace
click export model and choose export
model from the list
name the exported model knn model
the model is now available in the matlab
workspace
you can access it in the same way you
access the regression models
in this lesson you learned how to use
the classification learner app to select
train and assess some simple
classification models
you've found a promising candidate to
predict if a trip will have a toll based
on the pickup and drop-off locations
in the following lessons you'll learn
more about metrics used to quantify
classification model performance
[Music]