Skip to content

Instantly share code, notes, and snippets.

@JhonatanHern
Last active October 10, 2019 21:49
Show Gist options
  • Save JhonatanHern/9e2b99322159745896d5b56adbc810c1 to your computer and use it in GitHub Desktop.
Save JhonatanHern/9e2b99322159745896d5b56adbc810c1 to your computer and use it in GitHub Desktop.
#https://archive.ics.uci.edu/ml/datasets/Post-Operative+Patient
library(neuralnet)
library(dplyr)
read.table('post-operative.data',sep=',') -> po
randomized_data <- sample_frac(po,1)
training <- randomized_data[1:79,]
testd <- randomized_data[80:90,]
training <- mutate(training,
A = V9 == "A",
S = V9 == "S",
I = V9 == "I",
highCore = V1 == "high",
midCore = V1 == "mid",
lowCore = V1 == "low",
highSurf = V2 == "high",
midSurf = V2 == "mid",
lowSurf = V2 == "low",
excellent = V3 == "excellent",
good = V3 == "good",
fair = V3 == "poor",
poor = V3 == "poor",
highBp = V4 == "high",
midBp = V4 == "mid",
lowBp = V4 == "low",
stableSurf = V5 == "stable",
modStableSurf = V5 == "mod-stable",
unstableSurf = V5 == "unstable",
stableCore = V6 == "stable",
modStableCore = V6 == "mod-stable",
unstableCore = V6 == "unstable",
stableBp = V7 == "stable",
modStableBp = V7 == "mod-stable",
unstableBp = V7 == "unstable"
)
nn <- neuralnet(
A + S + I ~ highCore + midCore + lowCore + highSurf + midSurf + lowSurf + excellent + good + fair + poor + highBp + midBp + lowBp + stableSurf + modStableSurf + unstableSurf + stableCore + modStableCore + unstableCore + stableBp + modStableBp + unstableBp,
data = training,
hidden = c(10,10),
act.fct = "logistic",
linear.output = FALSE
)
plot(nn)
Predict=compute(nn,testd)
res = Predict$net.result
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment