-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_preprocessing.py
156 lines (55 loc) · 1.71 KB
/
data_preprocessing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 23 15:03:05 2019
@author: MSI
"""
# basic moudle
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import math as mt
import random
import time
# seaborn moudle
import seaborn as sns
# os moudle
import os
# sklearn moudle
from sklearn.metrics import r2_score
from sklearn import preprocessing
# 数据读取
data1 = pd.read_csv('./data/raw_data/data2.csv', encoding='gbk', header=None)
se1 = pd.read_csv('./data/raw_data/se2.csv', encoding='gbk', header=None)
data1 = np.array(data1)
se1 = np.array(se1)
# 运动片段截取
sport = []
mlen1 = []
mlen2 = []
mlen3 = []
for i in range(se1.shape[0]):
batch = data1[int(se1[i, 0]): int(se1[i, 1]), 1]
mlen1.append([i, len(batch)])
if len(batch) <= 601.0:
sport.append(batch)
mlen2.append([i, len(batch)])
else:
mlen3.append([i, len(batch)])
mlen1 = np.array(mlen1)
mlen2 = np.array(mlen2)
mlen3 = np.array(mlen3)
np.save('./data/sport_data/data_batch2.npy', sport)
# 运动片段补全
data11 = np.zeros([len(sport), 600])
for i in range(len(sport)):
data11[i, 0: len(sport[i])] = sport[i]
# 保存文件
data11_name = './data/sport_data/data2.npy'
mlen1_name = './data/sport_data/all_rank2.npy'
mlen2_name = './data/sport_data/xuan_rank2.npy'
mlen3_name = './data/sport_data/luo_rank2.npy'
np.save(data11_name, data11)
np.save(mlen1_name, mlen1)
np.save(mlen2_name, mlen2)
np.save(mlen3_name, mlen3)