Wednesday, March 4, 2020

Creating 3D Surface Plots in R -- Examples Using Iris Data


I downloaded the Iris data set from the UCI Machine Learning Repository and pre-processed it as follows: I just took the first two classes (I wanted a binary classification dataset) which had 100 instances and changed the class labels to 0/1. I retained all four of the attributes -- Sepal Length, Sepal Width, Petal Length and Petal Width.

Next, I took two attributes at a time, built a linear model (lm) in R and fitted the data. I wanted to visualize the surface of the loss functions using Absolute Loss and Squared Loss. Here is the code I used to generate my plots.


I present below a summary of my results:

Model 1a. Absolute Loss – Sepal Length, Sepal Width



Model 1b. Absolute Loss – Sepal Length, Petal Length



Model 1c. Absolute Loss – Sepal Length, Petall Width



Model 1d. Absolute Loss – Sepal Width, Petal Length



Model 1e. Absolute Loss – Sepal Width, Petal Width



Width

Model 1f. Absolute Loss Petal Length, Petall Width





I found that the model with Sepal Width and Petal Length has the highest Adjusted R Squared (0.9574).

What did you discover? Please do let me know! Also, if you want to play around with colors in R -- here is a nice reference. Enjoy coding in R!

No comments:

Post a Comment