神经网络模型无法运行

时间:2019-04-19 20:17:44

标签: r

由于某种原因,我的模型未运行。我创建了一个模型矩阵,使用包Neuronet运行一个简单的模型。我知道调试其他人的代码可能很困难,尤其是在没有数据的情况下,但是如果您认为可以为我提供帮助,则可以使用以下代码:

library(tidyverse)
library(neuralnet)

#Activity 1 Load Data


featchannels <-read.csv("features_channel.csv")
trainTargets <-read.table("traintargets.txt")


#Activity 2 Normalize every column of the features dataset using min-max 
normalization to range [0-1].

normalized <- function(x) {
return((x-min(x)) /(max(x) -min(x)))
}

featchannels <- normalized(featchannels)


#Activity 3 Add a target feature named response to the features dataset 
with 0-1 values read from trainTargets.txt, with 1 indicating P300 
response and 0 otherwise. 

colnames(trainTargets)[1] <- "State"
featchannels <- cbind(featchannels, trainTargets)
# Changing rows to P300 and others. 
featchannels <- within(featchannels, State <- factor(State, labels = 
c("Other", "P300")))
featchannels$State <- as.factor(featchannels$State)
#4. Take the first 3840 rows of the dataset as the training data set, and 
the remaining 960 rows as the testing data set. 

training <- featchannels[1:3840,]
testing <- featchannels[3841:4800,]
enter code here
#Activitry 6
#Creating model matrix before runing the model
df_comb_training <- training
y <- model.matrix(~ df_comb_training$State + 0, data = df_comb_training[, 
c('State'), drop=FALSE])
# fix up names for as.formula
y_feats <- gsub("^[^ ]+\\$", "", colnames(y))
colnames(y) <- y_feats

df_comb_training <- df_comb_training[, !(colnames(df_comb_training) == 
"State")]
feats <- colnames(df_comb_training)
df_comb_training <- cbind(y, df_comb_training)

# Concatenate strings
f <- paste(feats, collapse=' + ')
y_f <- paste(y_feats, collapse=' + ')
f <- paste(y_f, '~', f)

# Convert to formula
f <- as.formula(f)
model_h5 <- neuralnet(f, df_comb_training, stepmax = 1e+08, hidden = 5)

0 个答案:

没有答案