library(caTools) library(ggplot2)

Φορτωση Database

heart_dp <- read.csv(“Heart_Disease_Prediction.csv”) str(heart_dp) summary(heart_dp)

View(heart_dp)

Ενδεικτικα Plots

ggplot(heart_dp, aes(x= ST.depression, y= Age)) + geom_point()

ggplot(heart_dp, aes(x= Age, y= Cholesterol)) + geom_boxplot()

ggplot(heart_dp, aes(Cholesterol)) + geom_histogram()

ggplot(heart_dp, aes(Cholesterol)) + geom_bar()

Γραμμικη Παλινδρομιση Με 1 Μεταβλητη : Age VS Cholesterol

m <- lm(Age ~ Cholesterol, data = heart_dp) summary(m)

ggplot(heart_dp, aes(Cholesterol, Age)) + geom_point() + geom_abline(aes(intercept=coef(m)[1], slope=coef(m)[2]), colour=“purple”)

Πολλαπλη Γραμμικη Παλινδρομιση Με Μεταβλητες > 1

m2 = lm(Age ~ Chest.pain.type + BP + Cholesterol + Max.HR + ST.depression, data=heart_dp) summary(m2)

D1 <- ggplot(heart_dp, aes(Chest.pain.type, Age)) + geom_point() + geom_abline(aes(intercept=coef(m2)[1], slope=coef(m2)[2]), colour=“green”)

D1

D2 <-ggplot(heart_dp, aes(BP, Age)) + geom_point() + geom_abline(aes(intercept=coef(m2)[1], slope=coef(m2)[2]), colour=“blue”)

D2

D3 <-ggplot(heart_dp, aes(Cholesterol, Age)) + geom_point() + geom_abline(aes(intercept=coef(m2)[1], slope=coef(m2)[2]), colour=“red”)

D3

D4 <-ggplot(heart_dp, aes(Max.HR, Age)) + geom_point() + geom_abline(aes(intercept=coef(m2)[1], slope=coef(m2)[2]), colour=“yellow”)

D4

D5<-ggplot(heart_dp, aes(ST.depression, Age)) + geom_point() + geom_abline(aes(intercept=coef(m2)[1], slope=coef(m2)[2]), colour=“pink”)

D5

Αξιολογηση Μοντελου Παλινδρομισης - Sum of Squared Errors (SSE)

SSE <- sum(m2$residuals^2) SSE

Αξιολογηση Μοντελου Παλινδρομισης - Root-Mean-Square Error (RMSE)

RMSE <- sqrt(SSE/nrow(heart_dp)) RMSE