Skip to content

Commit

Permalink
Update Artificial_neural_network.R
Browse files Browse the repository at this point in the history
  • Loading branch information
faizan8201 authored Feb 23, 2021
1 parent 1acc613 commit e555b1b
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"
NOTE: First Column is treated as 1 in the Selection of Data:
1- Please select the dataset provided with the name 'German_state_results_New') or any numeric data available.
Column(Variable) 1 Column(Variable) 2 . . . . Column(Classification) n
Column(Instance) 1 Column(Instance) 2 . . . . Column(Instance) n
Row(Instance) 1 (Value) (Value) . . . . (Value)
Row(Variable) 1 (Value) (Value) . . . . (Value)
Row(Instance) 2 (Value) (Value) . . . . (Value)
Row(Variable) 2 (Value) (Value) . . . . (Value)
. . . .
. . . .
. . . .
. . . .
Row(Instance) n (Value) (Value) . . . . (Value)
Row(Classification) n (Value) (Value) . . . . (Value)
2- To run the code, select the whole code and run as source (top right in this window) & enter parameters
Expand Down Expand Up @@ -62,7 +64,23 @@ fname <- file.choose() #choose German_State_Results_New.csv
#type of separator used in input data
ask_sep <- as.character(readline(prompt = "ENTER the SEPARATOR for file(',' or ';') : "))

matrix<- read.csv(fname, sep= ask_sep)
matrix1<- read.csv(fname, sep= ask_sep, row.names = 1)

#Make data in normal form by taking Transpose
df_t <- as.data.frame(t(matrix1))


#Convert the data type back to numeric
for (newa in 1:ncol(df_t)){
chk <- as.numeric(df_t[1,newa])
if (!is.na(chk)){

df_t[ , newa] <- apply(df_t[ , newa, drop= F], 2, function(x) as.numeric(as.character(x)))
}

}
#matrix to be used
matrix <- df_t

#dummify the data
dmy <- dummyVars(" ~ .", data = matrix, sep = NULL)
Expand All @@ -85,7 +103,7 @@ actfct <- as.character(readline(prompt = "Enter either of the activation functio

#normalizing our data
normalize <- function(x) {
return ((x - min(x)) / (max(x) - min(x)))
return ((x - min(x)) / (max(x) - min(x)))
}

nor_matrix <- as.data.frame(lapply(matrix, normalize))
Expand Down Expand Up @@ -162,5 +180,5 @@ print(res)
Conf_Matrix <- confusionMatrix(table(res$rounded_nn, res$classification_col))
print(Conf_Matrix)


options(warn = -1)
print(paste("FINISHED"), quote = FALSE)

0 comments on commit e555b1b

Please sign in to comment.