This repository contains implementations of various data analytics algorithms using R programming. The projects in this repository are part of a syllabus on data analytics and demonstrate the application of key machine learning algorithms on real-world datasets. The following algorithms are implemented:
- Decision Tree (using the Titanic dataset)
- Naive Bayes (using the Titanic dataset)
- K-Nearest Neighbors (KNN) (using the Iris dataset)
- K-Means Clustering (using the USArrests dataset)
The datasets used in these projects are:
- Titanic dataset: A dataset that contains information about passengers aboard the Titanic ship, including whether they survived.
- Iris dataset: A classic dataset used in machine learning for classification, containing measurements of different species of iris flowers.
- USArrests dataset: A dataset containing crime statistics for US states, used for clustering analysis.
- Description: A decision tree algorithm is used to predict the survival of passengers aboard the Titanic.
- Dataset:
titanic.csv - Steps:
- Preprocess the data.
- Split the data into training and testing sets.
- Train a decision tree model using the
rpartlibrary. - Evaluate the model's performance.
- Algorithm: Decision Tree (using the
rpartlibrary in R).
- Description: The Naive Bayes algorithm is used to predict the survival of passengers based on different features (e.g., age, class, etc.).
- Dataset:
titanic.csv - Steps:
- Preprocess the data.
- Split the data into training and testing sets.
- Train a Naive Bayes model using the
e1071library. - Evaluate the model's performance.
- Algorithm: Naive Bayes (using the
e1071library in R).
- Description: The K-Nearest Neighbors algorithm is used to classify the species of iris flowers based on their measurements.
- Dataset:
iris_dataset.csv - Steps:
- Load and preprocess the data.
- Split the data into training and testing sets.
- Train a KNN model using the
classlibrary. - Evaluate the model's performance using accuracy for various values of
k.
- Algorithm: K-Nearest Neighbors (using the
classlibrary in R).
- Description: K-Means clustering is performed to group US states based on their crime statistics.
- Dataset:
USArrests.csv - Steps:
- Load and scale the data (excluding the state names).
- Perform K-Means clustering for different numbers of clusters (2, 3, 4, and 5).
- Visualize the clustering results using
fviz_cluster. - Use the silhouette method to determine the optimal number of clusters.
- Algorithm: K-Means Clustering (using the
factoextraandggplot2libraries in R).
- titanic.csv: Titanic dataset used for the Decision Tree and Naive Bayes algorithms.
- iris.csv: Iris dataset used for the KNN algorithm.
- USArrests.csv: USArrests dataset used for the K-Means Clustering algorithm.
- decisionTree.R: R script for implementing the Decision Tree algorithm on the Titanic dataset.
- naivebayes.R: R script for implementing the Naive Bayes algorithm on the Titanic dataset.
- K nearest integer using iris database.R: R script for implementing the KNN algorithm on the Iris dataset.
- K-Cluster.R: R script for implementing the K-Means Clustering algorithm on the USArrests dataset.
- randomForest.R: R script for implementing the Random Forest algorithm on the Iris dataset with hyperparameter tuning.
To run the R scripts in this repository, make sure you have R installed on your system. You can download R from here.
To install the required libraries for each algorithm, you can use the following commands in R:
install.packages("dplyr")
install.packages("rpart")
install.packages("e1071")
install.packages("caTools")
install.packages("class")
install.packages("randomForest")
install.packages("caret")
install.packages("ggplot2")
install.packages("factoextra")-
Clone the repository:
git clone https://github.com/divyakanth07/Data-Analytis-using-R-programming-SRMIST-MCA-I--F-
-
Navigate to the project directory:
cd Data-Analytis-using-R-programming-SRMIST-MCA-I--F- -
Run each R script in RStudio or R console:
source("decisionTree.R") source("naivebayes.R") source("K nearest integer using iris database.R") source("randomForest.R") source("K Cluster.R")
This project demonstrates the application of four important machine learning algorithms using the R programming language:
- Decision Tree to predict Titanic survivors.
- Naive Bayes to predict Titanic survivors.
- K-Nearest Neighbors (KNN) to classify iris flower species.
- Random Forest to classify iris flower species with hyperparameter tuning.
- K-Means Clustering is performed to group US states based on their crime statistics.
Each algorithm provides a hands-on introduction to important machine learning concepts and their practical implementation in R.
This project is licensed under the MIT License - see the LICENSE file for details.