Data mining is the process of discovering patterns and relationships in large datasets. It involves using techniques from a range of fields, including machine learning, statistics and database systems, to extract valuable insights and information from data.
In this article, we will provide an overview of data mining in the R Programming Language, including some of the most commonly used techniques and tools. We will begin by introducing the basics of data mining and R and then move to more advanced topics such as machine learning and text mining.
Getting Started with Data Mining in R
To begin working with data mining in R:
1. Install R and an IDE
Install R and a development environment such as RStudio, which provides an intuitive interface for coding, visualization and package management.
2. Install Key Packages
Install commonly used packages using install.packages()
and load them with library()
. We will install caret
,dplyr
and ggplot2
.
R
install.packages("caret")
install.packages("dplyr")
install.packages("ggplot2")
library(dplyr)
library(caret)
library(ggplot2)
Data Mining Techniques
We will explore some commonly used data mining techniques and there implementation.
1. Clustering
Clustering can be used for a variety of purposes, including discovering hidden patterns in the data, summarizing data and generating new features. This involves partitioning a dataset into groups (called clusters) such that the observations within each cluster are more similar to each other than they are to observations in other clusters.
R
install.packages("factoextra")
library(factoextra)
df <- mtcars
df <- na.omit(df)
df <- scale(df)
# With 4 Centers
km <- kmeans(df, centers = 4, nstart = 25)
fviz_cluster(km, data = df)
# With 5 Centers
km <- kmeans(df, centers = 5, nstart = 25)
fviz_cluster(km, data = df)
Output:
Clusters formed using 4 cluster centers
Clusters formed using 5 cluster centers2. Association Rule
Association Rule is used to identify patterns or relationships within large datasets, such as products frequently bought together in retail. Rules are expressed as if-then statements, where the presence of one item suggests the presence of another. The strength of these associations is measured by support, confidence and lift, helping businesses optimise product placement, promotions and recommendations. It is widely applied in market basket analysis and recommendation systems.
R
install.packages("arules")
install.packages("arulesViz")
library(arules)
library(arulesViz)
data("Groceries")
rules <- apriori(Groceries, parameter = list(support = 0.01, confidence = 0.5))
inspect(head(rules, 5))
plot(rules, method = "grouped")
Output:
Table
Plot3. Regression
Linear Regression is one of the most widely used regression techniques to model the relationship between two variables. It uses a linear relationship to model the regression line. There are 2 variables used in the linear relationship equation i.e., the predictor variable and the response variable.
Linear Regression Equation:
y = a x + b
where,
- x indicates predictor or independent variable
- y indicates response or dependent variable
- a and b are coefficients
R
x <- c(153, 169, 140, 186, 128, 136, 178, 163, 152, 133)
y <- c(64, 81, 58, 91, 47, 57, 75, 72, 62, 49)
model <- lm(y ~ x)
print(model)
df <- data.frame(x = 182)
res <- predict(model, df)
cat("\nPredicted value of a person with height = 182\n")
print(res)
plot(x, y, main = "Height vs Weight Regression Model")
abline(model)
Output:
Model and Prediction
Regression line with the points on a 2D plot4. Classification
Classification is a supervised learning technique used to categorize data into predefined classes based on input features. It is widely used in applications such as spam detection, disease diagnosis and image recognition.
R
install.packages("randomForest")
library(randomForest)
data(iris)
set.seed(123)
model <- randomForest(Species ~ ., data = iris, ntree = 100)
pred <- predict(model, iris)
# Confusion matrix
table(Predicted = pred, Actual = iris$Species)
Output:
RF CLassfication
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are
10 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read