My assigned dataset is “seeds.csv”
seeds = read.csv("seeds.csv")
seeds
The dataset named “seeds.csv” appears to contain information related to the characteristics of seeds. Each data point in the dataset is likely represented by several features, including area, perimeter, compactness, kernel length, kernel width, asymmetry coefficient, and kernel groove. The numerical values provided for these features correspond to specific measurements for each seed. Additionally, the dataset includes a column “Type” with integer values, possibly indicating different types or classes of seeds. The information within this dataset seems structured for analysis, where the goal might be to predict or understand the seed type based on its measured characteristics.
Columns 1 to 7 in my dataset contain numerical values, and these columns are considered numerical because they represent measurements or characteristics of the seeds that can take on a range of numeric values.
The last column (column 8) assigned as ‘Type’ is the categorical column in my dataset as integers (1, 2, and 3) are used to represent different types of seeds, serve as classes or categories for the seeds. Usually, categorical variables represent categories or groups, and in this case, the numerical values have a specific meaning in terms of the types of seeds.
The last column (column 8) assigned as ‘Type’ is the target variable indicating different classes or categories of seeds.
This point is not applicable for my dataset as the only categorical column in my assigned dataset is the target column. Now we will call all the numerical columns as ‘features’ and the last column as ‘target’ or ‘class’.
class_color = as.numeric(factor(seeds$Type))
plot(seeds$Kernel.Groove, seeds$Asymmetry.Coeff,
col = class_color,
pch = 20,
cex = 2,
xlim = c(4, 7),
ylim = c(0, 10),
xlab = substitute(paste(bold("Kernel Groove"))), ##substitute(paste(bold("label"))) - to bold label
ylab = substitute(paste(bold("Asymmetry Coefficient"))),
main = "Scatter plot of Kernel Groove and Asymmetry Coefficient",
col.main = 'black',
col.axis = 'black',
col.lab = 'purple',
cex.main = 1.5,
cex.axis = 1,
cex.lab = 1
)
The above scatter plot visually represents the relationship between Kernel Groove and Asymmetry Coefficient. It illustrates a correlation between Kernel Groove and Asymmetry Coefficient, suggesting that as Kernel Groove increases, so does the Asymmetry Coefficient in most of the cases but it’s not that much significant.
hist(seeds$Compactness, main = "Histogram plot of Compactness of seeds", xlab = "Compactness of seeds", col = "skyblue")
The histogram illustrates the distribution of Compactness of seeds, providing insights into the frequency and range of values. This reveals a bimodal distribution, characterized by two distinct peaks in the compactness values and both the peaks lies on the range 0.87-0.89 and this is the highest frequent range values for different types of seeds.
boxplot(seeds$Kernel.Width, ylab = 'Kernel Width' , main='Box plot of Kernel Width', col = 'coral')
The above boxplot represents the distribution of the “Kernel Width” feature in the “seeds” dataset. The box in the plot represents the interquartile range (IQR), which contains the middle 50% of the data. The bottom and top edges of the box represent the first (Q1 = 2.9) and third (Q3 = 3.6) quartiles, respectively. The line inside the box represents the median of the data and it might be 3.2. The “whiskers” extend from the edges of the box to show the range of the data. Overall, the boxplot provides a visual summary of the distribution of the “Kernel Width” feature, helping us identify the central tendency, spread, and presence of outliers in the data.
(I made 4 scatter plots of different combinations of two features)
#### Scatter plot of Area vs Asymmetry Coefficient
library(ggplot2)
ggplot(seeds, aes(x = Area, y = Asymmetry.Coeff, color = factor(Type))) +
geom_point(size = 3) +
scale_color_manual(values = c('1' = 'blue', '2' = 'red', '3' = 'purple'))+
labs(title = "Scatter plot of Area vs Asymmetry Coefficient",
x = 'Area',
y = 'Asymmetry Coefficient',
caption = "Source: Iskulghar") +
theme_minimal() +
theme(
legend.position = "top",
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each point on the above scatter plot represents a seed, and its position is determined by the values of Area and Asymmetry Coefficient. Points are colored based on the Seed Type (Type 1, Type 2, and Type 3), allowing us to visually distinguish between different seed types. X-axis illustrates the values of the seed areas and Y-axis illustrates the values of the asymmetry coefficients. We can also see in type 3 seeds, Asymmetry Coefficients are the highest while their areas are lowest in comparison to other two types.
#### Scatter plot of Kernel Length vs Kernel Width
library(ggplot2)
ggplot(seeds, aes(x = Kernel.Length, y = Kernel.Width, color = factor(Type))) +
geom_point(size = 3) +
scale_color_manual(values = c('1' = 'orange', '2' = 'yellow', '3' = 'brown'))+
labs(title = "Scatter plot of Kernel Length vs Kernel Width",
x = 'Kernel Length',
y = 'Kernel Width',
caption = "Source: Iskulghar") +
theme_minimal() +
theme(
legend.position = "top", ### top, left, right, bottom
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each point on the above scatter plot represents a seed, and its position is determined by the values of Kernel Length and Kernel Width. Points are colored based on the Seed Type (Type 1, Type 2, and Type 3), allowing us to visually distinguish between different seed types. X-axis illustrates the values of the seeds’ Kernel Lengths and Y-axis illustrates the values of the seeds’ Kernel Widths. We can see in three types of seeds, the relationship between kernel length and kernel width increases proportionally.
#### Scatter plot of Perimeter vs Kernel Groove
library(ggplot2)
ggplot(seeds, aes(x = Perimeter, y = Kernel.Groove, color = factor(Type))) +
geom_point(size = 3) +
scale_color_manual(values = c('1' = 'blue', '2' = 'purple', '3' = 'skyblue'))+
labs(title = "Scatter plot of Perimeter vs Kernel Groove",
x = 'Perimeter',
y = 'Kernel Groove',
caption = "Source: Iskulghar") +
theme_minimal() +
theme(
legend.position = "top", ### top, left, right, bottom
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each point on the above scatter plot represents a seed, and its position is determined by the values of Perimeter and Kernel Groove. Points are colored based on the Seed Type (Type 1, Type 2, and Type 3), allowing us to visually distinguish between different seed types. X-axis illustrates the values of the seeds’ Perimeters and Y-axis illustrates the values of the seeds’ Kernel Grooves. We can also see in type 2 seed,the more the Perimeter, the more the Kernel Groove of a seed.
#### Scatter plot of Area vs Compactness
library(ggplot2)
ggplot(seeds, aes(x = Area, y = Compactness, color = factor(Type))) +
geom_point(size = 3) +
scale_color_manual(values = c('1' = 'green', '2' = 'skyblue', '3' = 'purple'))+
labs(title = "Scatter plot of Area vs Compactness",
x = 'Area',
y = 'Compactness',
caption = "Source: Iskulghar") +
theme_minimal() +
theme(
legend.position = "top",
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each point on the above scatter plot represents a seed, and its position is determined by the values of Area and Compactness. Points are colored based on the Seed Type (Type 1, Type 2, and Type 3), allowing us to visually distinguish between different seed types. X-axis illustrates the values of the seeds’ Areas and Y-axis illustrates the values of the seeds’ Compactness. We can see in three types of seeds, the relationship between Area and Compactness increases and decreases proportionally in most of the cases.
## Box Plot of Areas by Different Types of Seeds
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Area, fill = factor(Type))) +
geom_boxplot() +
labs(title = "Box Plot of Areas by Different Types of Seeds",
x = "Types of Seeds",
y = "Area",
caption = "Source: Iskulghar") +
theme_classic () +
theme(
legend.position = "top",
text = element_text(colour = 'blue', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
In the above boxplot, each box represents the interquartile range (IQR) containing the central 50% of the data for the Area measurements of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 13.74 for type 1, Q1: 17.34 for type 2, and Q1: 11.2675 for type 3) and third quartile (Q3; Q3: 15.05 for type 1, Q3: 19.145 for type 2, and Q3: 12.395 for type 3). Inside each box, a line indicates the median value of the Area for the corresponding seed type, 14.36, 18.72 and 11.84 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box illustrate the minimum (i.e., 10.59 for type 3) and maximum (i.e., 13.37 for type 3) values within a certain range (usually 1.5 times the IQR). Individual data points, for instance, 21.18 and 15.38 in type 1 beyond the whiskers are considered outliers and are plotted individually.
## Box Plot of Perimeter by Different Types of Seeds
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Perimeter, fill = factor(Type))) +
geom_boxplot() +
scale_fill_manual(values = c('1' = 'bisque', '2' = 'darkgrey', '3' = 'darkolivegreen')) +
labs(title = "Box Plot of Perimeter by Different Types of Seeds",
x = "Types of Seeds",
y = "Perimeter",
caption = "Source: Iskulghar") +
theme_classic() +
theme(
legend.position = "top",
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
In the above boxplot, each box represents the interquartile range (IQR) containing the central 50% of the data for the Perimeter of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 13.94 for type 1, Q1: 15.745 for type 2, and Q1: 13.0175 for type 3) and third quartile (Q3; Q3: 14.75 for type 1, Q3: 16.58 for type 2, and Q3: 13.4825 for type 3). Inside each box, a line indicates the median value of the Perimeter for the corresponding seed type, 14.32, 16.225 and 13.27 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box represent the minimum (i.e., 14.89 for type 2) and maximum (i.e., 17.25 for type 2) values within a certain range (usually 1.5 times the IQR). Individual data points, for instance, 12.63 in type 1 beyond the whiskers are considered outliers.
## Box Plot of Compactness by Different Types of Seeds
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Compactness, fill = factor(Type))) +
geom_boxplot() +
scale_fill_manual(values = c('1' = 'coral', '2' = 'darkorange', '3' = 'darkgoldenrod')) +
labs(title = "Box Plot of Compactness by Different Types of Seeds",
x = "Types of Seeds",
y = "Compactness",
caption = "Source: Iskulghar") +
theme_classic() +
theme(
legend.position = "top",
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
The box plot illustrates the distribution of compactness among three types of seeds. Each box represents the interquartile range (IQR) containing the central 50% of the data for the Compactness of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 0.8686 for type 1, Q1: 0.87195 for type 2, and Q1: 0.83345 for type 3) and third quartile (Q3; Q3: 0.8883 for type 1, Q3: 0.8973 for type 2, and Q3: 0.861475 for type 3). Inside each box, a line indicates the median value of the Compactness for the corresponding seed type, 0.8805, 0.8823 and 0.8496 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box represent the minimum (i.e., 0.8081 for type 3) and maximum (i.e., 0.8964 for type 3) values within a certain range. Individual data points, for instance, 0.9183 in type 1 beyond the whiskers are considered outliers.
## Box Plot of Kernel Length by Different Types of Seeds
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Kernel.Length, fill = factor(Type))) +
geom_boxplot() +
scale_fill_manual(values = c('1' = 'darkkhaki', '2' = 'burlywood3', '3' = 'darksalmon')) +
labs(title = "Box Plot of Kernel Length by Different Types of Seeds",
x = "Types of Seeds",
y = "Kernel.Length",
caption = "Source: Iskulghar") +
theme_classic() +
theme(
legend.position = "top",
text = element_text(colour = 'blue', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
In this boxplot, each box represents the interquartile range (IQR) containing the central 50% of the data for the Kernel Length measurements of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 5.384 for type 1, Q1: 5.9795 for type 2, and Q1: 5.13925 for type 3) and third quartile (Q3; Q3: 5.678 for type 1, Q3: 6.328 for type 2, and Q3: 5.33725 for type 3). Inside each box, a line indicates the median value of the Kernel Length for the corresponding seed type, 5.534, 6.149 and 5.236 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box represent the minimum (i.e., 4.899 for type 3) and maximum (i.e., 5.541 for type 3) values within a certain range (usually 1.5 times the IQR). Individual data points, for instance, 4.902 in type 1 and 5.363 in type 2 beyond the whiskers are considered outliers.
## Box Plot of Kernel Width by Different Types of Seeds
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Kernel.Width, fill = factor(Type))) +
geom_boxplot() +
scale_fill_manual(values = c('1' = 'cyan', '2' = 'skyblue', '3' = 'aquamarine')) +
labs(title = "Box Plot of Kernel Width by Different Types of Seeds",
x = "Types of Seeds",
y = "Kernel Width",
caption = "Source: Iskulghar") +
theme_classic() +
theme(
legend.position = "top",
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each box represents the interquartile range (IQR) containing the central 50% of the data for the Kernel Width measurements of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 3.129 for type 1, Q1: 3.5565 for type 2, and Q1: 2.7385 for type 3) and third quartile (Q3; Q3: 3.379 for type 1, Q3: 3.8055 for type 2, and Q3: 2.967 for type 3). Inside each box, a line indicates the median value of the Kernel Width for the corresponding seed type, 3.2435, 3.6935 and 2.836 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box represent the minimum (i.e., 2.63 for type 3) and maximum (i.e., 3.232 for type 3) values within a certain range (usually 1.5 times the IQR).
## Box Plot of Asymmetry Coefficient by Different Types of Seed
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Asymmetry.Coeff, fill = factor(Type))) +
geom_boxplot() +
scale_fill_manual(values = c('1' = 'darkgreen', '2' = 'chartreuse4', '3' = 'green')) +
labs(title = "Box Plot of Asymmetry Coefficient by Different Types of Seeds",
x = "Types of Seeds",
y = "Asymmetry Coefficient",
caption = "Source: Iskulghar") +
theme_classic() +
theme(
legend.position = "top",
text = element_text(colour = 'black', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each box represents the interquartile range (IQR) containing the central 50% of the data for the Asymmetry Coefficient of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 1.791 for type 1, Q1: 2.845 for type 2, and Q1: 4.05025 for type 3) and third quartile (Q3; Q3: 3.373 for type 1, Q3: 4.4565 for type 2, and Q3: 5.46375 for type 3). Inside each box, a line indicates the median value of the Asymmetry Coefficient for the corresponding seed type, 2.5455, 3.629 and 4.853 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box represent the minimum (i.e., 1.472 for type 2) and maximum (i.e., 6.682 for type 2) values within a certain range. Individual data points, for instance, 6.685 in type 1, and 8.315, 1.661 in type 3 beyond the whiskers are considered outliers.
## Box Plot of Kernel Groove by Different Types of Seeds
library(ggplot2)
ggplot(data = seeds, aes(x= Type, y = Kernel.Groove, fill = factor(Type))) +
geom_boxplot() +
scale_fill_manual(values = c('1' = 'darkseagreen', '2' = 'skyblue', '3' = 'antiquewhite')) +
labs(title = "Box Plot of Kernel Groove by Different Types of Seeds",
x = "Types of Seeds",
y = "Kernel.Groove",
caption = "Source: Iskulghar") +
theme_classic() +
theme(
legend.position = "top",
text = element_text(colour = 'purple', size = 14),
axis.text.x = element_text(color = 'black', size = 12),
axis.text.y = element_text(color = 'black', size = 12)
)
Each box represents the interquartile range (IQR) containing the central 50% of the data for the kernel groove measurements of each seed type. The bottom and top edges of the box indicate the first quartile (Q1; Q1: 4.914 for type 1, Q1: 5.878 for type 2, and Q1: 5.00275 for type 3) and third quartile (Q3; Q3: 5.222 for type 1, Q3: 6.1875 for type 2, and Q3: 5.26475 for type 3). Inside each box, a line indicates the median value of the kernel groove for the corresponding seed type, 5.094, 5.9815 and 5.132 for type 1, 2 and 3 respectively. Lines (Whiskers) extending from the box represent the minimum (i.e., 4.519 for type 1) and maximum (i.e., 5.533 for type 1) values within a certain range (usually 1.5 times the IQR). Individual data points, for instance, 5.877 in type 1 and 5.144 in type 2 beyond the whiskers are considered outliers and are plotted individually.
# Interactive violin plot of Area
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Area, type = 'violin')
# Interactive violin plot of Perimeter
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Perimeter, type = 'violin')
# Interactive violin plot of Compactness
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Compactness, type = 'violin')
# Interactive violin plot of Kernel.Length
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Kernel.Length, type = 'violin')
# Interactive violin plot of Kernel.Width
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Kernel.Width, type = 'violin')
# Interactive violin plot of Asymmetry.Coeff
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Asymmetry.Coeff, type = 'violin')
# Interactive violin plot of Kernel.Groove
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Kernel.Groove, type = 'violin')
#Interactive boxplot of Area
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Area, type = 'box')
#Interactive boxplot of Perimeter
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Perimeter, type = 'box')
#Interactive boxplot of Compactness
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Compactness, type = 'box')
#Interactive boxplot of Kernel.Length
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Kernel.Length, type = 'box')
#Interactive boxplot of Kernel.Width
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Kernel.Width, type = 'box')
#Interactive boxplot of Asymmetry.Coeff
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Asymmetry.Coeff, type = 'box')
#Interactive boxplot of Kernel.Groove by Different Types of Seeds
library(plotly)
plot_ly(seeds, x = ~Type, y = ~Kernel.Groove, type = 'box')
cor_matrix = cor(seeds[ ,1:7])
cor_matrix
Area Perimeter Compactness Kernel.Length Kernel.Width Asymmetry.Coeff Kernel.Groove
Area 1.0000000 0.9944373 0.6098875 0.9511258 0.9709796 -0.222820450 0.862727206
Perimeter 0.9944373 1.0000000 0.5318407 0.9729442 0.9454957 -0.211034252 0.889543418
Compactness 0.6098875 0.5318407 1.0000000 0.3740113 0.7621670 -0.329400178 0.227016463
Kernel.Length 0.9511258 0.9729442 0.3740113 1.0000000 0.8626799 -0.169704426 0.932124102
Kernel.Width 0.9709796 0.9454957 0.7621670 0.8626799 1.0000000 -0.253122410 0.748227942
Asymmetry.Coeff -0.2228204 -0.2110343 -0.3294002 -0.1697044 -0.2531224 1.000000000 -0.003349395
Kernel.Groove 0.8627272 0.8895434 0.2270165 0.9321241 0.7482279 -0.003349395 1.000000000
From the above correlation matrix, we can see, there is strong correlation between Area and Perimeter (0.99), Area and Kernel Width (0.97), Perimeter and Kernel Length (0.97), Area and Kernel Length (0.95), Perimeter and Kernel Width (0.95), Kernel Length and Kernel Groove (0.93), Perimeter and Kernel Groove (0.89), Kernel Length and Kernel Width (0.86), and Area and Kernel Groove (0.86). There lies less strong correlation between Compactness and Kernel Width (0.76), Kernel Width and Kernel Groove (0.75), Area and Compactness (0.61) and Perimeter and Compactness (0.53). All other correlations (positive or negative) between any two features are weak correlations.
library(ggcorrplot)
ggcorrplot(cor_matrix,
type = "lower" ,
colors = c("purple", "white", "red"),
lab = TRUE)
library(ggplot2)
library(GGally)
seeds$Type = seeds$Type<-as.factor(seeds$Type)
ggpairs(seeds, aes(color = Type))
library(stats)
seeds_pca = prcomp(seeds[ , -8], scale = TRUE, center = TRUE)
seeds_pca
Standard deviations (1, .., p=7):
[1] 2.24310190 1.09504983 0.82232374 0.26115727 0.13715851 0.07290793 0.02850049
Rotation (n x k) = (7 x 7):
PC1 PC2 PC3 PC4 PC5 PC6 PC7
Area -0.4444453 -0.02689510 0.02541939 0.19763627 -0.19751625 -0.42905925 -0.734121454
Perimeter -0.4415674 -0.08298812 -0.06019769 0.30034829 -0.16637062 -0.47503082 0.671539178
Compactness -0.2779150 0.52535969 0.63238211 -0.34000075 0.32627308 -0.13947927 0.073104145
Kernel.Length -0.4241261 -0.20007500 -0.21443932 0.25098045 0.76832639 0.28042137 -0.046369104
Kernel.Width -0.4329366 0.11572453 0.21512380 0.20373132 -0.46870015 0.70024261 0.037006864
Asymmetry.Coeff 0.1157433 -0.72122562 0.67513087 0.09326364 0.04045161 -0.01691821 0.003839455
Kernel.Groove -0.3866993 -0.37788656 -0.21853787 -0.80120818 -0.12333864 0.03920887 0.034960897
summary(seeds_pca)
Importance of components:
PC1 PC2 PC3 PC4 PC5 PC6 PC7
Standard deviation 2.2431 1.0950 0.8223 0.26116 0.13716 0.07291 0.02850
Proportion of Variance 0.7188 0.1713 0.0966 0.00974 0.00269 0.00076 0.00012
Cumulative Proportion 0.7188 0.8901 0.9867 0.99644 0.99912 0.99988 1.00000
pc_12 = data.frame(seeds_pca$x[ , 1:2])
head(pc_12)
pc_12_class = cbind(pc_12, Type = seeds$Type)
pc_12_class
ggplot(pc_12_class, aes(PC1, PC2, color = factor(Type))) +
geom_point(size=3) +
theme_minimal()
library(factoextra)
fviz_eig(seeds_pca,addlabels = TRUE)
The above bar plot of Principal Component Analysis (PCA) illustrates the percentage of explained variance for each dimension. In this case, PCA1 accounts for the majority with 71.9%, followed by PCA2 (17.1%) and PCA3 (9.7%).The diminishing percentages for subsequent dimensions, as an elbow in this plot becomes apparent after PCA2, highlight the decreasing contribution to overall variance, emphasizing the significance of the first few components(PCA1 and PCA2).
fviz_pca_var(seeds_pca,
col.var = "contrib")
The above circular contribution plot visually represents the contribution of each variable/feature to the Principal Components (PCs) in a PCA analysis. Variables are positioned around the circle, and their color intensity corresponds to their contribution to the PCs. This plot helps identify key variables influencing each PC and provides insights into the structure of the data. Here, in PCA1, Area, Perimeter, Kernel Length, Kernel Width, Kernel.Groove and Compactness contributes most to explain 71.9% variances, while in PCA2, Compactness and Asymmetry coefficient contributes most to explain 7.1% variances.
library(corrplot)
var = get_pca_var(seeds_pca)
corrplot(var$cos2)
The above Contribution Heatmap in PCA illustrates the contribution of each variable/feature to Principal Components (PCs). Each row represents a variable, and the color intensity indicates its impact on the respective PCs. This heatmap aids in identifying influential variables across different dimensions, i.e., in PCA1, influential variables are Area, Perimeter, Kernel Width, Kernel Length, Kernel.Groove and Compactness who contributed most to explain variances.
fviz_pca_ind(seeds_pca,
geom.ind = "point",
col.ind = seeds$Type,
addEllipses = TRUE)
The above Cluster plot post-PCA visually represented data points in reduced dimensions, reflecting similarities based on Principal Components. Clusters indicate groups with comparable features, aiding in identifying patterns and structure, and assessing the effectiveness of dimensionality reduction through PCA.
library(lattice)
library(e1071)
Attaching package: ‘e1071’
The following object is masked from ‘package:raster’:
interpolate
library(caret)
train_ix = createDataPartition(seeds$Type, p = 0.8, list = FALSE)
train_data = seeds[train_ix, ]
test_data = seeds[-train_ix, ]
train_data
test_data
svm_model = svm(factor(Type) ~ Area+Perimeter+Compactness+Kernel.Length+Kernel.Width+Asymmetry.Coeff+Kernel.Groove, data = train_data, kernel = "linear")
test_data[24, ]
predict(svm_model, newdata = test_data[24, -8])
127
2
Levels: 1 2 3
# Assuming 'Type' is the variable you are predicting
predictions = predict(svm_model, newdata = test_data)
test_data$Type = as.factor(test_data$Type) # Convert 'Type' to a factor if it's not already
# Make sure the predicted values have the same levels as the actual values
predictions = factor(predictions, levels = levels(test_data$Type))
conf_max = confusionMatrix(predictions, test_data$Type)
conf_max
Confusion Matrix and Statistics
Reference
Prediction 1 2 3
1 13 1 1
2 0 12 0
3 0 0 12
Overall Statistics
Accuracy : 0.9487
95% CI : (0.8268, 0.9937)
No Information Rate : 0.3333
P-Value [Acc > NIR] : 7.509e-16
Kappa : 0.9231
Mcnemar's Test P-Value : NA
Statistics by Class:
Class: 1 Class: 2 Class: 3
Sensitivity 1.0000 0.9231 0.9231
Specificity 0.9231 1.0000 1.0000
Pos Pred Value 0.8667 1.0000 1.0000
Neg Pred Value 1.0000 0.9630 0.9630
Prevalence 0.3333 0.3333 0.3333
Detection Rate 0.3333 0.3077 0.3077
Detection Prevalence 0.3846 0.3077 0.3077
Balanced Accuracy 0.9615 0.9615 0.9615
From the above Confusion Matrix and Statistics, we can see that in case of type 1 seed, the prediction is correct for all the 13 seeds.In case of type 2 seed, the prediction is correct for 12 seed and incorrect for 1 and in case of type 3 seed, the prediction is correct for 12 seed and incorrect for rest 1. As P-Value 7.509e^(-16) < 0.05, it exhibits significance of this model.
cm = as.data.frame(conf_max$table)
ggplot(cm, aes(Prediction, Reference, fill = Freq)) +
geom_tile() +
geom_text(aes(label = Freq)) +
scale_fill_gradient(low="white", high="skyblue")
US_Admission = read.csv("US Admission.csv")
US_Admission
US_Admission_new = US_Admission [ , c(-1) ]
US_Admission_new
breaks <- c(-Inf, 0.6, 0.8, Inf) # Create breaks and factorize 'Chance.of.Admit'
US_Admission_new$Chance.of.Admit_factorized <- cut(US_Admission_new$Chance.of.Admit, breaks = breaks, labels = c("Low", "Medium", "High"))
US_Admission_new_2 <- US_Admission_new # Create a new dataframe 'US_Admission_new_2' with the updated column
library(ggplot2)
library(GGally)
ggpairs(US_Admission_new_2, aes(colour = Chance.of.Admit_factorized))
# Linear regression of GRE Score
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = GRE.Score)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue")
Linear regression of GRE Score on the Chance of Admit (x-axis) reveals the relationship between these variables. The regression line represents the best-fit prediction of GRE Score based on Chance of Admit. The slope indicates the change in GRE Score for a unit change in Chance of Admit, providing insights into their quantitative association.
# Linear regression of TOEFL Score
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = TOEFL.Score)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "purple")
Linear regression of TOEFL Score on the Chance of Admit (x-axis) reveals the relationship between these variables. The regression line represents the best-fit prediction of TOEFL Score based on Chance of Admit. The slope indicates the change in TOEFL Score for a unit change in Chance of Admit, providing insights into their quantitative association.
# Linear regression of University Rating
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = University.Rating)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue")
# Linear regression of SOP
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = SOP)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue")
# Linear regression of LOR
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = LOR)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue")
# Linear regression of CGPA
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = CGPA)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue")
# Linear regression of Research
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = Research)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "purple")
Linear regression of Research on the Chance of Admit (x-axis) reveals the relationship between these variables. The regression line represents the best-fit prediction of Research based on Chance of Admit. The slope indicates the change in Research for a unit change in Chance of Admit, providing insights into their quantitative association.
# Polynomial regression of GRE Score
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = GRE.Score, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
Polynomial regression of GRE Score on the Chance of Admit (x-axis) explores a nonlinear relationship. Unlike linear regression, it accommodates curved patterns in the data. The polynomial curve fitting captures more intricate dependencies, offering a more flexible model to predict GRE Score based on varying Chance of Admit values (‘Low’ < 0.6, ‘Medium’ 0.6-0.8, ‘High’ > 0.8).
# Polynomial regression of TOEFL Score
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = TOEFL.Score, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
# Polynomial regression of University Rating
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = University.Rating, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
# Polynomial regression of SOP
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = SOP, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
# Polynomial regression of LOR
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = LOR, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
# Polynomial regression of CGPA
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = CGPA, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
# Polynomial regression of Research
ggplot(US_Admission_new_2,
aes(x = Chance.of.Admit, y = Research, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
Polynomial regression of Research on the Chance of Admit (x-axis) explores a nonlinear relationship. Unlike linear regression, it accommodates curved patterns in the data. The polynomial curve fitting captures more intricate dependencies, offering a more flexible model to predict Research based on varying Chance of Admit values (‘Low’ < 0.6, ‘Medium’ 0.6-0.8, ‘High’ > 0.8).
ggplot(US_Admission_new_2,
aes(x = GRE.Score + TOEFL.Score + University.Rating + SOP + LOR + CGPA + Research, y = Chance.of.Admit)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue")
NA
ggplot(US_Admission_new_2,
aes(x = GRE.Score + TOEFL.Score + University.Rating + SOP + LOR + CGPA + Research, y = Chance.of.Admit, color = Chance.of.Admit_factorized)) +
geom_point() +
geom_smooth(method = "lm", formula = y~poly(x, 2), level = 0.95)
Combining all features (GRE Score, TOEFL Score, University Rating, SOP, LOR, CGPA, Research) in a regression model (linear or polynomial) creates a comprehensive analysis of their collective impact on the Chance of Admit (y). This multivariate approach captures interactions and dependencies among the variables, offering a more holistic prediction of admission chances. The model considers the joint influence of diverse factors for a more nuanced understanding of the relationship.