Home > other >  [for] r language code changes (should be a few places need to add the content I don't quite und
[for] r language code changes (should be a few places need to add the content I don't quite und

Time:12-06

[code=text# Data
Setwd (" C:/Users/thinkpad/Desktop/homework ")
Getwd ()
The data & lt; - read. CSV (" binary. CSV, "header=TRUE)
STR (data)

# Min - Max Normalization
Data $gre & lt; - (data $gre - min (data) $gre)/(Max) (data $gre - min (data $gre))
Data $gpa & lt; - (data $gpa - min (data $gpa))/(Max (data $gpa) - min (data $gpa))
Data $rank & lt; - (data $rank - min (data $rank))/(Max (data $rank) - min (data $rank))

# Data Partition
Set. The seed (222)
Ind & lt; - the sample (2, nrow (data), the replace=TRUE, prob=c ())
Training & lt; - data/ind==,
Testing & lt; - data/ind==,

# Neural Networks
The library (neuralnet)
Set. The seed (333)
N & lt; - neuralnet (admit ~ + gpa, gre rank,
Data=https://bbs.csdn.net/topics/training,
Hidden=,
# hidden=c (2, 1),
Err, FCT has grown="ce",
Linear output=FALSE)
The plot (n)

# Prediction
The output & lt; To compute (n, training)
The head (the output $net. The result)
The head (training [1])

# Node Output Calculations with Sigmoid Activation Function
In4 & lt; (0.0455 + 0.82344 * 0.7586206897) + (1.35186 * 0.8103448276) + (0.87435 * 0.6666666667)
Out4 & lt; 1/(1 + exp (- in4))
In5 & lt; - 7.06125 + (8.5741 * out4)
Out5 & lt; 1/(1 + exp (- in5))

# Confusion Matrix & amp; Misclassification Error - training data
The output & lt; To compute (n, training)
P1 & lt; - the output $.net. Result
Pred1 & lt; Ifelse (p1 & gt; 0.5, 1, 0)
Tab1 & lt; - the table (pred1, training $admit)
Tab1
1 - the sum (diag (tab1))/sum (tab1)

# Confusion Matrix & amp; Misclassification Error - testing data
The output & lt; To compute (n, testing)
The p2 & lt; - the output $.net. Result
Pred2 & lt; Ifelse (p2 & gt; 0.5, 1, 0)
Tab2 & lt; - the table (pred2, testing $admit)
Tab2
1 - the sum (diag (tab2))/sum (tab2)
] [/code]
  • Related