Created
September 9, 2018 11:18
-
-
Save AdityaSoni19031997/e9e8147c0d08bc40f4e5745329cc5d02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing dataset | |
| dataset <- read.csv('ASD.csv') | |
| # Taking care of missing data | |
| # Fixing ethnicity | |
| dataset[dataset == "?"] <- NA | |
| summary(dataset) | |
| #install.packages('DescTools') | |
| library(DescTools) | |
| DetermineEthnicity = function(x){ | |
| eth = Mode(dataset[dataset$contry_of_res == x, ]$ethnicity) | |
| if (length(eth) == 1){ | |
| return (eth) | |
| }else if(length(eth) == 12){ | |
| return(Mode(dataset$ethnicity)) | |
| }else{ | |
| return(eth[1]) | |
| } | |
| } | |
| for(r in 1:nrow(dataset)){ | |
| if(is.na(dataset[r, ]$ethnicity)){ | |
| dataset[r, ]$ethnicity = DetermineEthnicity(dataset[r, ]$contry_of_res) | |
| } | |
| } | |
| # Fixing relations | |
| self = dataset[1, "relation"] | |
| for(r in 1:nrow(dataset)){ | |
| if(is.na(dataset[r, ]$relation)){ | |
| dataset[r, ]$relation = self | |
| } | |
| } | |
| # Converting Age to numeric type | |
| dataset$age = as.numeric(as.character(dataset$age)) | |
| # Dividing into training and test set | |
| #install.packages('caTools') | |
| library(caTools) | |
| split = sample.split(dataset$Class.ASD, SplitRatio = 7/10) | |
| training_set = subset(dataset, split == TRUE) | |
| test_set = subset(dataset, split == FALSE) | |
| X_test = test_set[, 1:21] | |
| y_test = test_set[, 22] | |
| # Fitting decision tree regression to the dataset | |
| #install.packages('rpart') | |
| library(rpart) | |
| regressor = rpart(formula = Class.ASD ~ ., | |
| data = training_set) | |
| # Predicting result and checking accuracy | |
| y_pred = predict(regressor, newdata = X_test, type = "class") | |
| print(mean(y_test == y_pred)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment