Undergraduate graduation design involves using machine learning methods to train predictive models, linear regression, SVM, RF and other methods are not ideal, so we need to use a simple neural network method to do comparative experiments. Without in-depth understanding of the optimization of the NN, the interface provided by the R package is called directly, where it is briefly recorded for later reflection and improvement.
The main use of nnet, neuralnet, H2O These several packages, concrete modeling, prediction, optimization method in the manual can be found. Nnet and Neuralnet provide a simple neural network with a single hidden layer, H2O provides a DNN method.
1 Library (nnet)2Data<-read.csv ("Tomcat_done_1.csv", header=T)3 4Total_size <-3635Test_size <-906 7Train=sample (1:dim (data) [1],total_size-test_size)8 9train_set<-Data[train,]Ten OneTest<-data[-train,1:35] A -test_effort<-data[-train,36] - theCount <-0 - - -M<-nnet (effort~.,train_set,size=9,decay=0.015,maxit=10,linout=t,trace=f,maxnwts=8000) + -Preds <-predict (m,test)
1 Library (neuralnet)2Data<-read.csv ("Tomcat_done_2.csv", header=T)3 4Total_size <-3635Test_size <-906 7Train=sample (1:dim (data) [1],total_size-test_size)8 9train_set<-Data[train,]Ten OneTest<-data[-train,1:35] A -test_effort<-data[-train,36] - theCount <-0 - - -M<-neuralnet (effort~countdeclclass+countdeclclassmethod+countdeclclassvariable ++countdeclfunction+countdeclinstancemethod+countdeclinstancevariable -+countdeclmethod+countdeclmethoddefault+countdeclmethodprivate ++countdeclmethodprotected+countdeclmethodpublic+Countline A+countlineblank+countlinecode+countlinecodedecl+Countlinecodeexe at+countlinecomment+countsemicolon+countstmt+countstmtdecl+Countstmtexe -+sumcyclomatic+sumcyclomaticmodified+sumcyclomaticstrict+sumessential -+maxcyclomatic+maxcyclomaticmodified+maxcyclomaticstrict+maxessential -+maxnesting+avgcyclomatic+avgcyclomaticmodified+avgcyclomaticstrict -+avgessential+ratiocommenttocode,data = Train_set,hidden = 2) - in - toPreds <-Compute (m,test)
Data needs to be preprocessed and re-entered according to the format requirements of the model, for example, some packages require that the label information be mapped to [0,1]. Read more manuals and original papers to understand the optimization method, remember!
R packets related to "R" Neural network