March, 17

This is Your Captain Speaking (58)

Key vocabulary

1.       turbulence: sudden, strong movement of air especially that causes a plane to move up and down in the air

2.       rough=having or causing sudden violent movements

3.       patch=small area小块地

4.       bumpyhaving sudden up and down movements颠簸的,崎岖不平的

5.       cabin baggage=suitcases and luggage that travels inside the plane with the passengers

6.       stow=装载

7.       suspend=悬挂,终止

8.       refrain=避免,制止

9.       lavatoryroom with a sink and toilet, chiefly on an airplane or train

A: And the next thing you know, we’re running towards the…oh…did you feel that?

B: Yeah, don’t worry about it; we’re going through a bit of turbulence.

C: Ladies and gentlemen, this is your captain speaking. It looks like we’ve hit a patch of rough air, so we’re going to have a bit of a bumpy ride for the next several minutes, and…

A: This why I hate flying ..oh!

C: At this time, I’d like to remind all of our passengers to fasten their seat belt sign is turned off. Please ensure that all cabin baggage is carefully stowed under the seat in front of you. I’ll be back to update you in a minute.

A: Did you hear that? Brent!

B: Don’t worry about it. This is totally normal. It happens all the

C: Ah, ladies and gentlemen, this is your captain again. We’ve got quite a large patch of rough air ahead of us, so for your safety, we will be suspending in-flight service. I would ask all in-flight crew to return to their seats at this time. I would also like to ask that all our passengers refrain from using the lavatory until the seat belt sign has been switched off we can expect…

 

% 读取Excel文件 data = readtable('C:\Users\lenovo\Desktop\zuixin_winsorized_data.xlsx', 'Sheet', 'Sheet1'); % 提取PM2.5数据 pm25 = data.PM2_5; % 提取时间列(假设时间列是 'year', 'month', 'day', 'hour') time = datetime(data.year, data.month, data.day, data.hour, 0, 0); % 创建timetable pm25_tt = timetable(time, pm25); % 将时间序列转换为每日数据(按天求平均值) pm25_daily = retime(pm25_tt, 'daily', 'mean'); % 提取前两周的数据(3月1日到3月14日) startDate = datetime('2013-03-01'); endDate = datetime('2013-03-14'); pm25_train = pm25_daily(startDate:endDate, :); % 提取3月17日的数据作为目标 targetDate = datetime('2013-03-17'); pm25_target = pm25_daily(targetDate, :); % 准备训练数据 XTrain = pm25_train.pm25; % 前两周的 PM2.5 数据 YTrain = pm25_target.pm25; % 3月17日的 PM2.5 数据 % 检查数据长度 if length(XTrain) ~= 14 || length(YTrain) ~= 1 error('数据长度不匹配:XTrain 应为 14 天,YTrain 应为 1 天'); end % 将 XTrain 转换为适合 LSTM 的格式 XTrain = XTrain'; % 转置为 1×14 的序列 XTrain = num2cell(XTrain, 1); % 转换为 cell 数组,每个元素是一个时间步的数据 % 将 YTrain 转换为适合 LSTM 的格式 YTrain = YTrain'; % 转置为 1×1 的目标值 YTrain = num2cell(YTrain, 1); % 转换为 cell 数组 % 定义LSTM模型 numFeatures = 1; % 输入特征的数量(PM2.5) numHiddenUnits = 100; % LSTM隐藏单元的数量 numResponses = 1; % 输出响应的数量(PM2.5) layers = [ ... sequenceInputLayer(numFeatures) lstmLayer(numHiddenUnits) fullyConnectedLayer(numResponses) regressionLayer]; % 定义训练选项 options = trainingOptions('adam', ... 'MaxEpochs', 200, ... 'GradientThreshold', 1, ... 'InitialLearnRate', 0.005, ... 'LearnRateSchedule', 'piecewise', ... 'LearnRateDropPeriod', 125, ... 'LearnRateDropFactor', 0.2, ... 'Verbose', 0, ... 'Plots', 'training-progress'); % 训练模型 net = trainNetwork(XTrain, YTrain, layers, options); % 准备测试数据(前两周的数据) XTest = pm25_train.pm25'; XTest = num2cell(XTest, 1); % 转换为 cell 数组 % 进行预测 YPred = predict(net, XTest); % 显示预测结果 disp('Predicted PM2.5 for March 17:'); disp(YPred{end}); % 预测的最后一天是3月17日; 我在运行这段代码出现报错,报错信息为无效的训练数据。预测变量和响应必须有相同的观测值数目。 出错 untitled14 (第 65 行) net = trainNetwork(XTrain, YTrain, layers, options);
03-27
% 读取Excel文件 data = readtable('C:\Users\lenovo\Desktop\zuixin_winsorized_data.xlsx', 'Sheet', 'Sheet1'); % 提取PM2.5数据 pm25 = data.PM2_5; % 提取时间列(假设时间列是 'year', 'month', 'day', 'hour') time = datetime(data.year, data.month, data.day, data.hour, 0, 0); % 创建timetable pm25_tt = timetable(time, pm25); % 将时间序列转换为每日数据(按天求平均值) pm25_daily = retime(pm25_tt, 'daily', 'mean'); % 提取前两周的数据(3月1日到3月14日) startDate = datetime('2013-03-01'); endDate = datetime('2013-03-14'); pm25_train = pm25_daily(startDate:endDate, :); % 提取3月17日的数据作为目标 targetDate = datetime('2013-03-17'); pm25_target = pm25_daily(targetDate, :); % 准备训练数据 % ...(前面的数据读取代码保持不变) % 准备训练数据(关键修改部分) XTrain = pm25_train.pm25'; % 转置为行向量(1×14) XTrain = {XTrain}; % 包裹成cell数组,表示1个样本的14个时间步 YTrain = pm25_target.pm25; % 获取目标值 YTrain = {YTrain}; % 包裹成cell数组 % ...(后续模型定义和训练代码保持不变) % 定义LSTM模型 numFeatures = 1; % 输入特征的数量(PM2.5) numHiddenUnits = 100; % LSTM隐藏单元的数量 numResponses = 1; % 输出响应的数量(PM2.5) layers = [ ... sequenceInputLayer(numFeatures) lstmLayer(numHiddenUnits) fullyConnectedLayer(numResponses) regressionLayer]; % 定义训练选项 options = trainingOptions('adam', ... 'MaxEpochs', 200, ... 'GradientThreshold', 1, ... 'InitialLearnRate', 0.005, ... 'LearnRateSchedule', 'piecewise', ... 'LearnRateDropPeriod', 125, ... 'LearnRateDropFactor', 0.2, ... 'Verbose', 0, ... 'Plots', 'training-progress'); % 训练模型 net = trainNetwork(XTrain, YTrain, layers, options); % 准备测试数据(前两周的数据) XTest = pm25_train.pm25'; XTest = num2cell(XTest, 1); % 转换为 cell 数组 % 进行预测 YPred = predict(net, XTest); % 显示预测结果 disp('Predicted PM2.5 for March 17:'); disp(YPred{end}); % 预测的最后一天是3月17日 这段代码运行时出现报错,报错信息为无效的训练数据。序列响应必须与对应的预测变量具有相同的序列长度。 出错 untitled14 (第 60 行) net = trainNetwork(XTrain, YTrain, layers, options);
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值