本次赛事要求基于智能手机传感器数据预测人体6项活动。训练集8千条、测试集2千条,含561个特征,以准确率评分。提供含数据预处理和1D卷积神经网络的Baseline,可通过残差结构、数据扩增优化。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

如今的智能机已经很智能了,如果手机可以觉察到我们在生活中的一举一动,知道我们行动的意图,你觉得会如何?智能手机不仅搭载了多种惯性传感器,这使得基于智能手机的人体行为识别研究越来越受关注。

在本次赛题由志愿者使用智能手机时,通过基本活动的行为构建而成。希望选手能够构建模型对活动行为进行预测。
实验是在 19-48 岁年龄段的 30 名志愿者中进行的。每个人在腰部佩戴智能手机(三星 Galaxy S II)进行六项活动(步行、楼上步行、楼下步行、坐、站、躺)。实验以 50Hz 的恒定速率捕获 3 轴线性加速度和 3 轴角速度。
赛题训练集案例如下:
数据总共100MB,赛题数据均为csv格式,列使用逗号分割。若使用Pandas读取数据,可参考如下代码:
import pandas as pdimport numpy as nptrain = pd.read_csv('train.csv.zip')对于数据集中的每一条记录,都提供了以下内容,来自加速度计的三轴加速度(总加速度)和估计的身体加速度、和来自陀螺仪的三轴角速度。总共是具有时域和频域变量的561个特征向量。
测试集中label字段Activity为空,需要选手预测。
Activity STANDING LAYING WALKING SITTING WALKING WALKING_DOWNSTAIRS STANDING
from sklearn.metrics import accuracy_score y_pred = [0, 2, 1, 3]y_true = [0, 1, 2, 3]accuracy_score(y_true, y_pred)
1、点击‘fork按钮’,出现‘fork项目’弹窗
2、点击‘创建按钮’ ,出现‘运行项目’弹窗
3、点击‘运行项目’,自动跳转至新页面
4、点击‘启动环境’ ,出现‘选择运行环境’弹窗
5、选择运行环境(启动项目需要时间,请耐心等待),出现‘环境启动成功’弹窗,点击确定
6、点击进入环境,即可进入notebook环境
7、鼠标移至下方每个代码块内(代码块左侧边框会变成浅蓝色),再依次点击每个代码块左上角的‘三角形运行按钮’,待一个模块运行完以后再运行下一个模块,直至全部运行完成

8、下载页面左侧submission.zip压缩包
9、在比赛页提交submission.zip压缩包,等待系统评测结束后,即可登榜!
10、点击页面左侧‘版本-生成新版本’
11、填写‘版本名称’,点击‘生成版本按钮’,即可在个人主页查看到该项目(可选择公开此项目哦)
import pandas as pdimport paddleimport numpy as np
%pylab inlineimport seaborn as sns
train_df = pd.read_csv('data/data137267/train.csv.zip')
test_df = pd.read_csv('data/data137267/test.csv.zip')/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working from collections import MutableMapping /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working from collections import Iterable, Mapping /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working from collections import Sized
Populating the interactive namespace from numpy and matplotlib
train_df.shape
(8000, 562)
train_df.columns
Index(['tBodyAcc-mean()-X', 'tBodyAcc-mean()-Y', 'tBodyAcc-mean()-Z',
'tBodyAcc-std()-X', 'tBodyAcc-std()-Y', 'tBodyAcc-std()-Z',
'tBodyAcc-mad()-X', 'tBodyAcc-mad()-Y', 'tBodyAcc-mad()-Z',
'tBodyAcc-max()-X',
...
'fBodyBodyGyroJerkMag-skewness()', 'fBodyBodyGyroJerkMag-kurtosis()',
'angle(tBodyAccMean,gravity)', 'angle(tBodyAccJerkMean),gravityMean)',
'angle(tBodyGyroMean,gravityMean)',
'angle(tBodyGyroJerkMean,gravityMean)', 'angle(X,gravityMean)',
'angle(Y,gravityMean)', 'angle(Z,gravityMean)', 'Activity'],
dtype='object', length=562)train_df['Activity'].value_counts().plot(kind='bar')
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/cbook/__init__.py:2349: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working if isinstance(obj, collections.Iterator): /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/cbook/__init__.py:2366: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working return list(data) if isinstance(data, collections.MappingView) else data
<matplotlib.axes._subplots.AxesSubplot at 0x7f39bd84b050>
<Figure size 432x288 with 1 Axes>
plt.figure(figsize=(10, 5)) sns.boxplot(y='tBodyAcc-mean()-X', x='Activity', data=train_df) plt.tight_layout()
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/seaborn/categorical.py:340: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations np.asarray(s, dtype=np.float) /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/seaborn/utils.py:538: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations np.asarray(values).astype(np.float)
<Figure size 720x360 with 1 Axes>
train_df['Activity'] = train_df['Activity'].map({ 'LAYING': 0, 'STANDING': 1, 'SITTING': 2, 'WALKING': 3, 'WALKING_UPSTAIRS': 4, 'WALKING_DOWNSTAIRS': 5})from sklearn.preprocessing import StandardScaler scaler = StandardScaler() scaler.fit(train_df.values[:, :-1]) train_df.iloc[:, :-1] = scaler.transform(train_df.values[:, :-1]) test_df.iloc[:, :] = scaler.transform(test_df.values)
class Classifier(paddle.nn.Layer):
# self代表类的实例自身
def __init__(self):
# 初始化父类中的一些参数
super(Classifier, self).__init__()
self.conv1 = paddle.nn.Conv1D(in_channels=1, out_channels=16, kernel_size=3)
self.conv2 = paddle.nn.Conv1D(in_channels=16, out_channels=32, kernel_size=3)
self.conv3 = paddle.nn.Conv1D(in_channels=32, out_channels=64, kernel_size=3)
self.flatten = paddle.nn.Flatten()
self.dropout = paddle.nn.Dropout()
self.fc = paddle.nn.Linear(in_features=128, out_features=6)
self.relu = paddle.nn.ReLU()
self.pool = paddle.nn.MaxPool1D(6)
self.softmax = paddle.nn.Softmax() # 网络的前向计算
def forward(self, inputs):
x = self.pool(self.relu(self.conv1(inputs)))
x = self.pool(self.relu(self.conv2(x)))
x = self.dropout(x)
x = self.pool(self.relu(self.conv3(x)))
x = self.dropout(x)
x = self.flatten(x)
x = self.relu(self.fc(x))
x = self.softmax(x) return xmodel = Classifier() model.train() opt = paddle.optimizer.SGD(learning_rate=0.005, parameters=model.parameters()) loss_fn = paddle.nn.CrossEntropyLoss()
EPOCH_NUM = 40 # 设置外层循环次数BATCH_SIZE = 16 # 设置batch大小training_data = train_df.iloc[:-1000].values.astype(np.float32) val_data = train_df.iloc[-1000:].values.astype(np.float32) training_data = training_data.reshape(-1, 1, 562) val_data = val_data.reshape(-1, 1, 562)
# 定义外层循环for epoch_id in range(EPOCH_NUM): # 在每轮迭代开始之前,将训练数据的顺序随机的打乱
np.random.shuffle(training_data)
# 将训练数据进行拆分,每个batch包含10条数据
mini_batches = [training_data[k:k+BATCH_SIZE] for k in range(0, len(training_data), BATCH_SIZE)]
# 定义内层循环
for iter_id, mini_batch in enumerate(mini_batches):
model.train()
x = np.array(mini_batch[:,:, :-1]) # 获得当前批次训练数据
y = np.array(mini_batch[:,:, -1:]) # 获得当前批次训练标签
# 将numpy数据转为飞桨动态图tensor的格式
features = paddle.to_tensor(x)
y = paddle.to_tensor(y)
# 前向计算
predicts = model(features)
# 计算损失
loss = loss_fn(predicts, y.flatten().astype(int))
avg_loss = paddle.mean(loss) # 反向传播,计算每层参数的梯度值
avg_loss.backward() # 更新参数,根据设置好的学习率迭代一步
opt.step() # 清空梯度变量,以备下一轮计算
opt.clear_grad() # 训练与验证
if iter_id%2000==0 and epoch_id % 10 == 0:
acc = predicts.argmax(1) == y.flatten().astype(int)
acc = acc.astype(float).mean()
model.eval()
val_predict = model(paddle.to_tensor(val_data[:, :, :-1])).argmax(1)
val_label = val_data[:, :, -1]
val_acc = np.mean(val_predict.numpy() == val_label.flatten()) print("epoch: {}, iter: {}, loss is: {}, acc is {} / {}".format(
epoch_id, iter_id, avg_loss.numpy(), acc.numpy(), val_acc))epoch: 0, iter: 0, loss is: [1.9004316], acc is [0.125] / 0.182 epoch: 10, iter: 0, loss is: [1.6665952], acc is [0.375] / 0.368 epoch: 20, iter: 0, loss is: [1.5449493], acc is [0.5] / 0.478 epoch: 30, iter: 0, loss is: [1.5502174], acc is [0.5] / 0.525
model.eval() test_data = paddle.to_tensor(test_df.values.reshape(-1, 1, 561).astype(np.float32)) test_predict = model(test_data) test_predict = test_predict.argmax(1).numpy()
test_predict = pd.DataFrame({'Activity': test_predict})
test_predict['Activity'] = test_predict['Activity'].map({ 0:'LAYING', 1:'STANDING', 2:'SITTING', 3:'WALKING', 4:'WALKING_UPSTAIRS', 5:'WALKING_DOWNSTAIRS'})test_predict.to_csv('submission.csv', index=None)
!zip submission.zip submission.csvupdating: submission.csv (deflated 94%)
<br/>
以上就是手机行为预测 Baseline的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号