[New Book] Click to get The Beginner's Guide to Data Science!
Use the offer code 20offearlybird to get 20% off. Hurry, sale ends soon!

Non-Linear Classification in R

In this post you will discover 8 recipes for non-linear classification in R. Each recipe is ready for you to copy and paste and modify for your own problem.

All recipes in this post use the iris flowers dataset provided with R in the datasets package. The dataset describes the measurements if iris flowers and requires classification of each observation to one of three flower species.

Kick-start your project with my new book Machine Learning Mastery With R, including step-by-step tutorials and the R source code files for all examples.

Let’s get started.

Irises

Irise Flowers
Photo by dottieg2007, some rights reserved

Mixture Discriminant Analysis

This recipe demonstrates the MDA method on the iris dataset.

Learn more about the mda function in the mda package.

Quadratic Discriminant Analysis

QDA seeks a quadratic relationship between attributes that maximizes the distance between the classes.

This recipe demonstrates the QDA method on the iris dataset.

Learn more about the qda function in the MASS package.

Need more Help with R for Machine Learning?

Take my free 14-day email course and discover how to use R on your project (with sample code).

Click to sign-up and also get a free PDF Ebook version of the course.

Regularized Discriminant Analysis

This recipe demonstrates the RDA method on the iris dataset.

Learn more about the rda function in the klaR package.

Neural Network

A Neural Network (NN) is a graph of computational units that receive inputs and transfer the result into an output that is passed on. The units are ordered into layers to connect the features of an input vector to the features of an output vector. With training, such as the Back-Propagation algorithm, neural networks can be designed and trained to model the underlying relationship in data.

This recipe demonstrates a Neural Network on the iris dataset.

Learn more about the nnet function in the nnet package.

Flexible Discriminant Analysis

This recipe demonstrates the FDA method on the iris dataset.

Learn more about the fda function in the mda package.

Support Vector Machine

Support Vector Machines (SVM) are a method that uses points in a transformed problem space that best separate classes into two groups. Classification for multiple classes is supported by a one-vs-all method. SVM also supports regression by modeling the function with a minimum amount of allowable error.

This recipe demonstrates the SVM method on the iris dataset.

Learn more about the ksvm function in the kernlab package.

k-Nearest Neighbors

The k-Nearest Neighbor (kNN) method makes predictions by locating similar cases to a given data instance (using a similarity function) and returning the average or majority of the most similar data instances.

This recipe demonstrate the kNN method on the iris dataset.

Learn more about the knn3 function in the caret package.

Naive Bayes

Naive Bayes uses Bayes Theorem to model the conditional relationship of each attribute to the class variable.

This recipe demonstrates Naive Bayes on the iris dataset.

Learn more about the naiveBayes function in the e1071 package.

Summary

In this post you discovered 8 recipes for non-linear classificaiton in R using the iris flowers dataset.

Each recipe is generic and ready for you to copy and paste and modify for your own problem.

Discover Faster Machine Learning in R!

Master Machine Learning With R

Develop Your Own Models in Minutes

...with just a few lines of R code

Discover how in my new Ebook:
Machine Learning Mastery With R

Covers self-study tutorials and end-to-end projects like:
Loading data, visualization, build models, tuning, and much more...

Finally Bring Machine Learning To Your Own Projects

Skip the Academics. Just Results.

See What's Inside

4 Responses to Non-Linear Classification in R

  1. Avatar
    Daniel Nee August 28, 2014 at 9:29 pm #

    Naive Bayes would generally be considered a linear classifier. The exception being if you are learning a Gaussian Naive Bayes (numerical feature set) and learning separate variances per class for each feature.

    Tom Mitchell has a new book chapter that covers this topic pretty well: http://www.cs.cmu.edu/~tom/mlbook/NBayesLogReg.pdf

  2. Avatar
    Chathurani September 29, 2015 at 9:40 pm #

    this example is good , but i know about more than this. as a example Neural Network different model, but it related only text data .

  3. Avatar
    Kelly April 17, 2019 at 4:42 am #

    Hi, thanks for the post, I am looking at your QDA model and when I run summary(fit), it looks like this
    Length Class Mode
    prior 3 -none- numeric
    counts 3 -none- numeric
    means 12 -none- numeric
    scaling 48 -none- numeric
    ldet 3 -none- numeric
    lev 3 -none- character
    N 1 -none- numeric
    call 3 -none- call
    terms 3 terms call
    xlevels 0 -none- list

    Can you explain this summary? I also want to look at the variable importance in my model and test on images for later usage

    • Avatar
      Jason Brownlee April 17, 2019 at 7:03 am #

      No sorry, perhaps check the documentation for the mode?

Leave a Reply