人口预测模型matlab代码
时间: 2023-10-02 14:13:07 浏览: 23
以下是一个简单的基于神经网络的人口预测模型的 MATLAB 代码示例:
```matlab
% Load data
data = readtable('population_data.csv');
% Split data into training and testing sets
train_data = data(1:80,:);
test_data = data(81:end,:);
% Define input and output variables
X = train_data{:,2:end};
Y = train_data{:,1};
% Create a neural network model with 2 hidden layers
net = feedforwardnet([10,5]);
% Train the neural network
net = train(net, X', Y');
% Test the neural network on the testing data
X_test = test_data{:,2:end};
Y_test = test_data{:,1};
Y_pred = net(X_test');
% Calculate the mean squared error
mse = mean((Y_pred - Y_test').^2);
% Plot the predicted vs actual values
plot(Y_test,'b');
hold on;
plot(Y_pred,'r');
legend('Actual','Predicted');
```
请注意,此代码仅用于演示目的,实际应用需要根据数据集和需求进行修改和优化。