heart= read.csv("heart.csv")
heart
The dataset is dedicated to predicting the likelihood of heart disease in individuals based on a range of factors including age, heart rate, diet, cholesterol levels, and other relevant variables. By analyzing these predictors, the model aims to provide accurate assessments of an individual’s risk of heart disease, enabling proactive measures for prevention and early intervention. This predictive tool serves as a valuable resource in guiding healthcare professionals and individuals towards informed decision-making regarding heart health.
str(heart)
'data.frame': 918 obs. of 12 variables:
$ Age : int 40 49 37 48 54 39 45 54 37 48 ...
$ Sex : chr "M" "F" "M" "F" ...
$ ChestPainType : chr "ATA" "NAP" "ATA" "ASY" ...
$ RestingBP : int 140 160 130 138 150 120 130 110 140 120 ...
$ Cholesterol : int 289 180 283 214 195 339 237 208 207 284 ...
$ FastingBS : int 0 0 0 0 0 0 0 0 0 0 ...
$ RestingECG : chr "Normal" "Normal" "ST" "Normal" ...
$ MaxHR : int 172 156 98 108 122 170 170 142 130 120 ...
$ ExerciseAngina: chr "N" "N" "N" "Y" ...
$ Oldpeak : num 0 1 0 1.5 0 0 0 0 1.5 0 ...
$ ST_Slope : chr "Up" "Flat" "Up" "Flat" ...
$ HeartDisease : int 0 1 0 1 0 0 0 0 1 0 ...
heart= heart[ ,c(1,4,5,6,8,10,12)]
heart
heart$HeartDisease = as.character(heart$HeartDisease)
heart
library(ggplot2)
ggplot(heart, aes(x= Age,y= Cholesterol, color= HeartDisease)) +
labs(title = "Visualization of Age vs Cholesterol",caption = "Source: Iskulghar")+
geom_point() +
theme_minimal()
ggplot(heart, aes(y= Age,x= HeartDisease, fill= HeartDisease))+
labs(title = "Boxplot of age of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_boxplot()
ggplot(heart, aes(y= RestingBP,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Boxplot of Resting Blood Pressure of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_boxplot()
ggplot(heart, aes(y= Cholesterol,x=HeartDisease, fill= HeartDisease)) +
labs(title = "Boxplot of Cholesterol of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_boxplot()
ggplot(heart, aes(y= FastingBS,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Boxplot of Fasting blood sugar level of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_boxplot()
ggplot(heart, aes(y=MaxHR,x= HeartDisease, fill= HeartDisease))+
labs(title = "Boxplot of Maximum heart rate of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_boxplot()
ggplot(heart, aes(y= Oldpeak,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Boxplot of oldpeak of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_boxplot()
ggplot(heart, aes(y= Age,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Violin plot of Age of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_violin()
ggplot(heart, aes(y= RestingBP,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Violin plot of Resting Blood Pressure of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_violin()
ggplot(heart, aes(y= Cholesterol,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Violin plot of Cholesterol of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_violin()
ggplot(heart, aes(y= FastingBS,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Violin plot of Fasting blood sugar level of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_violin()
ggplot(heart, aes(y=MaxHR,x= HeartDisease, fill= HeartDisease)) +
labs(title = "Violin plot of Maximum heart rate of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_violin()
ggplot(heart, aes(y= Oldpeak,x= HeartDisease, fill= HeartDisease))+
labs(title = "Violin plot of oldpeak of individuals by Heart Disease",caption = "Source: Iskulghar")+
geom_violin()
Heart= read.csv("heart.csv")
Heart
breaks <- c(0, 0.5,1)
labels <- c("No" , "Yes")
HD <- cut(Heart$HeartDisease, breaks= breaks, labels = labels, include.lowest = TRUE )
Heart = cbind(Heart, HD)
Heart
library(plotly)
plot_ly(data= Heart, x= ~HD, y= ~Age, type="violin")
plot_ly(data= Heart, x= ~HD, y= ~Cholesterol, type="violin")
plot_ly(data= Heart, x= ~HD, y= ~MaxHR, type="violin")
plot_ly(data= Heart, x= ~HD, y= ~Age, type="box")
plot_ly(data= Heart, x= ~HD, y= ~Cholesterol, type="box")
plot_ly(data= Heart, x= ~HD, y= ~MaxHR, type="box")
cor_matrix = cor(Heart[ , c(1,4:6,8,10)])
cor_matrix
Age RestingBP Cholesterol FastingBS MaxHR Oldpeak
Age 1.00000000 0.25439936 -0.09528177 0.19803907 -0.3820447 0.25861154
RestingBP 0.25439936 1.00000000 0.10089294 0.07019334 -0.1121350 0.16480304
Cholesterol -0.09528177 0.10089294 1.00000000 -0.26097433 0.2357924 0.05014811
FastingBS 0.19803907 0.07019334 -0.26097433 1.00000000 -0.1314385 0.05269786
MaxHR -0.38204468 -0.11213500 0.23579240 -0.13143849 1.0000000 -0.16069055
Oldpeak 0.25861154 0.16480304 0.05014811 0.05269786 -0.1606906 1.00000000
library(ggcorrplot)
ggcorrplot(cor_matrix,type= "lower", colors = c("blue", "white", "green"), lab= TRUE)
library(GGally)
ggpairs(Heart, aes(color= HD))
library(stats)
heart_pca= prcomp(Heart [, c(1,4:6,8,10)], center = TRUE, scale = TRUE)
heart_pca
Standard deviations (1, .., p=6):
[1] 1.3475910 1.1289099 0.9404081 0.9021504 0.8108943 0.7441564
Rotation (n x k) = (6 x 6):
PC1 PC2 PC3 PC4 PC5 PC6
Age 0.5656877 0.1464131 -0.07815273 -0.1366972 -0.4388274 -0.66422674
RestingBP 0.3148402 0.4728384 0.53054481 -0.4127243 0.4669217 0.08639773
Cholesterol -0.2667722 0.6601164 0.08069691 0.0191716 -0.6217504 0.31563563
FastingBS 0.3546506 -0.3810066 0.64659428 0.3615982 -0.3199952 0.27896689
MaxHR -0.5112625 0.1183642 0.47179671 0.3474096 0.1083634 -0.60792465
Oldpeak 0.3500561 0.4000716 -0.25539393 0.7477689 0.2978281 0.06570776
summary(heart_pca)
Importance of components:
PC1 PC2 PC3 PC4 PC5 PC6
Standard deviation 1.3476 1.1289 0.9404 0.9022 0.8109 0.74416
Proportion of Variance 0.3027 0.2124 0.1474 0.1356 0.1096 0.09229
Cumulative Proportion 0.3027 0.5151 0.6625 0.7981 0.9077 1.00000
library(factoextra)
fviz_eig(heart_pca)
fviz_pca_var(heart_pca, col.var = "contrib", gradient.cols = c("violet", 'black', 'green'))
fviz_pca_ind(heart_pca, col.ind = Heart$HD, addEllipses = TRUE, geom.ind = "point")
Heart
library(e1071)
library(caret)
library(lattice)
train_idx = createDataPartition(Heart$HD, p=0.8, list = FALSE)
train_data = Heart[train_idx, ]
test_data = Heart[-train_idx, ]
svm_model = svm(as.factor(HD) ~ Age+ RestingBP+ Cholesterol+ FastingBS+ MaxHR+ Oldpeak, data = train_data, kernel = "linear")
pred = predict(svm_model, test_data)
pred
2 3 5 7 13 18 20 29 32 36 54 57 60 62 68 71 73 80 84 85 114 115 117 122 123 128 130 137 138
No No No No No No Yes No No No No No Yes No No No No No No Yes No No No No No Yes Yes No Yes
139 141 142 146 156 168 182 184 186 193 214 216 217 223 225 230 231 242 255 258 262 269 285 286 287 293 295 304 305
No Yes Yes No Yes No No No Yes No No No No No Yes No No Yes Yes No Yes Yes No No No No Yes Yes Yes
309 324 334 340 341 353 359 361 365 373 383 386 390 405 410 411 414 416 421 423 425 427 429 430 432 433 450 451 453
Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes
455 468 475 477 485 487 494 502 505 515 518 522 528 532 538 541 542 543 546 549 550 559 564 565 581 583 587 594 600
Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
605 609 621 622 633 635 637 639 647 651 661 663 665 672 678 680 683 691 694 700 701 703 704 705 718 719 722 724 729
No No No Yes Yes No No No Yes No No No Yes Yes No Yes No No No Yes No Yes No Yes No Yes Yes No No
731 746 747 754 760 762 768 774 775 779 784 788 793 795 797 798 809 813 817 821 831 836 844 846 853 854 857 859 868
No Yes No No No No No Yes Yes Yes No Yes Yes No No No No Yes No Yes No Yes Yes No Yes No No Yes No
871 875 876 887 896 898 902 904 915
No No No No Yes Yes Yes No Yes
Levels: No Yes
test_data
conf_mat = confusionMatrix(pred, as.factor(test_data$HD))
conf_mat
Confusion Matrix and Statistics
Reference
Prediction No Yes
No 61 25
Yes 21 76
Accuracy : 0.7486
95% CI : (0.6793, 0.8097)
No Information Rate : 0.5519
P-Value [Acc > NIR] : 2.92e-08
Kappa : 0.4941
Mcnemar's Test P-Value : 0.6583
Sensitivity : 0.7439
Specificity : 0.7525
Pos Pred Value : 0.7093
Neg Pred Value : 0.7835
Prevalence : 0.4481
Detection Rate : 0.3333
Detection Prevalence : 0.4699
Balanced Accuracy : 0.7482
'Positive' Class : No
cm = as.data.frame(conf_mat$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
The dataset aims to assist students in selecting universities by providing predictions on their likelihood of admission based on their profiles. The predicted output offers valuable insights, helping students gain a clearer understanding of their chances of acceptance at specific universities. This summary serves as a valuable tool for students navigating the university application process.
US_admission$Serial.No.<-NULL
US_admission
breaks <- c(0, 0.5, 0.85, 1)
labels <- c("Low", "Moderate", "High")
CT <- cut(US_admission$Chance.of.Admit, breaks= breaks, labels = labels, include.lowest = TRUE )
US_admission = cbind(US_admission, CT)
US_admission
ggpairs(US_admission, aes(color= CT))
ggplot(US_admission, aes(x = Chance.of.Admit, y= GRE.Score, color = CT)) +
labs(title = "Regression plot for Chance of admission and GRE Score", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= TOEFL.Score, color = CT)) +
labs(title = "Regression plot for Chance of admission and TOEFL Score", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = 'blue', level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= University.Rating, color = CT)) +
labs(title = "Regression plot for Chance of admission and University rating", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= SOP, color = CT)) +
labs(title = "Regression plot for Chance of admission and Statement of purpose", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= LOR, color = CT)) +
labs(title = "Regression plot for Chance of admission and Letter of Recommendation Strength", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= CGPA, color = CT)) +
labs(title = "Regression plot for Chance of admission and CGPA", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= Research, color = CT)) +
labs(title = "Regression plot for Chance of admission and Research expertise", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", se = TRUE, color = "blue", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= GRE.Score, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and GRE Score", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color = "purple", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= TOEFL.Score, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and TOEFL Score", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color = "purple", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= University.Rating, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and University rating", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color = "purple", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= SOP, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and Statement of purpose", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color = "purple", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= LOR, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and LOR", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color = "purple", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= CGPA, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and CGPA", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color = "purple", level=0.95)+
theme_minimal()
ggplot(US_admission, aes(x = Chance.of.Admit, y= Research, color = CT)) +
labs(title = "Polynomial Regression plot for Chance of admission and Research expertise", caption = "Source: Iskulghar")+
geom_point() +
geom_smooth(method = "lm", formula= y~poly(x,2), se = TRUE, color ="purple", level=0.95)+
theme_minimal()