如何按年计算菠菜价值?

how to compute the spinach value by years?

提问人:Harika 提问时间:11/17/2023 最后编辑:Harika 更新时间:11/17/2023 访问量:42

问:

我正在使用R.但是我找到了每个项目的mse值,但我找不到如何预测每个项目的消费量。 structure(list(Year = 2016:2021, GDP = c(9544.25, 9969.5, 11086.11, 11231.54, 10361.28, 11407.68), 菠菜 = c(6.1, 7.7, 7.7, 8.4, 7.6, 8.2),

# Calculate the means and standard deviations for columns 2 and 4
mean_data <- c(mean(mydata[, 2]), mean(mydata[, 3]))
sd_data <- c(sd(mydata[, 2]), sd(mydata[, 3]))

# Scale only columns 2 and 4 using the specific means and standard deviations
data_scaled <- mydata
data_scaled[, c(2, 3)] <- scale(data_scaled[, c(2, 3)], center = mean_data, scale = sd_data)


# Create an index for splitting the data
index <- sample(1:nrow(data_scaled), round(0.50 * nrow(data_scaled)))

# Create the training and testing datasets
train_data <- as.data.frame(data_scaled[index, ])
test_data <- as.data.frame(data_scaled[-index, ])

# Get the column names of the scaled data
n = names(data_scaled)
n

# Build a neural network model to predict 'Rice' based on 'Inflation.Rate.' using the training data
net = neuralnet(Spinach ~ GDP, data=train_data, hidden=c(5,5), 
                linear.output=TRUE)
plot(net)


# Compute predictions on the testing data
# Calculate Mean Squared Error (MSE) for the predictions
predict_net_test <- compute(net, test_data[,c("GDP", "Spinach")])
# Calculate Mean Squared Error (MSE) for "Spinach" predictions
actual_spinach_values <- test_data$Spinach
predict_net_test <- predict_net_test$net.result
MSE.net <- mean((actual_spinach_values - predict_net_test)^2)

cat("Mean Squared Error (MSE) for 'Spinach' predictions:",MSE.net, "\n")

r

评论


答: 暂无答案