How to use Gaussian Process Classifier in R

This recipe helps you use Gaussian Process Classifier in R

Recipe Objective

How to use Gaussian Process Classifier in R?

The Gaussian Process Classification (GPC) is based on Laplace approximation used for interpolating the observations. This classifier when used for classification returns probabilistic classification, where the test predictions take the form of class predictions. In this recipe, demonstrates an example of how to use a Gaussian Process Classifier.

Step 1 - Install the necessary libraries

install.packages("e1071")
install.packages("caTools")
install.packages("caret")
install.packages("kernlab") # for guassian classification model
library(e1071)
library(caTools)
library(caret)
library(kernlab)

Step 2 - Read the iris dataset and explore the data

data <- iris # use the iris dataset
head(data) # head() returns the top 6 rows of the dataframe
summary(data) # returns the statistical summary of the data columns
dim(data) # returns number of rows and columns in the dataset

Step 3 - Train and Test data

# split the data into train-test with a ratio 80:20
split <- sample.split(data, SplitRatio = 0.8)
train_data <- subset(data, split == "TRUE")
test_data <- subset(data, split == "FALSE")
X_train <- train_data[,1:4] # independent variables for train data
X_test <- test_data[,1:4] # independent variables for test data
y_train <- train_data[,5] # dependent variables for train data
y_test <- test_data[,5] # dependent variables for test data
dim(X_train)
dim(X_test)

Step 4 - Create a gaussaian model

model <- gausspr(Species~., data=iris)
summary(model)

Step 5 - Make predictions on the test dataset

# Predicting on test data
predict <- predict(model,X_test)
predict
class_prob <- predict(model,X_test, type = 'probabilities')

Step 6 - Check the accuracy of our model

# Confusion Matrix
conf_mat <- table(y_test,predict)
print(conf_mat)
# Model Evauation
confusionMatrix(conf_mat)

Setosa: correctly classified 10. Versicolor: correctly classified 10, wrongly classified 1. Virginia : correctly identified 9. And also, the model achieved an accuracy of 96.67%

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.