Skip to content

Commit cb2fd8d

Browse files
add
1 parent 72c5f4a commit cb2fd8d

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed
64.2 KB
Loading
15.2 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

序列预测/PCA去趋势化/pre_porcess.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,31 @@ def transfer(data):
8686
arr[i,j]=data[i].iloc[j,vol_col_index]
8787
return arr
8888

89+
# 将dfs聚合
90+
def merge_dfs(dfs,merge_step=3):
91+
begin = 0
92+
end = int(dfs[0].shape[0]/3)
93+
ret_dfs=[]
94+
for df in dfs:
95+
ret_df = pd.DataFrame(columns=['road','vol','speed','last-update-time'])
96+
for step in range(begin,end):
97+
vol_item = df.iloc[step*merge_step:(step+1)*merge_step]['vol'].mean()
98+
speed_item = df.iloc[step*merge_step:(step+1)*merge_step]['speed'].mean()
99+
name = df.iloc[step*merge_step]['road']
100+
time = df.iloc[step*merge_step]['last-update-time']
101+
ret_df.loc[ret_df.shape[0]]=[name,vol_item,speed_item,time]
102+
ret_dfs.append(ret_df)
103+
print ("ori dfs shape is : ",dfs[0].shape)
104+
print ("ret dfs shape is : ",ret_dfs[0].shape)
105+
return ret_dfs
106+
107+
89108
def pre_process():
90109
abspath='C:/Users/wwwa8/Documents/GitHub/Machine-Learning/序列预测/PCA去趋势化/7.xls'
91110
#filepath='7.xls'
92111
df = read_excel(abspath)
93112
# 起始日期
94-
days=range(9,17)
113+
days=range(9,13)
95114
# 每一天每一分钟对应一个点的格式
96115
dfs=[]
97116
begin_hour = 0
@@ -107,6 +126,8 @@ def pre_process():
107126
dfs = default_fill(dfs)
108127
#过滤异常值,特别大的,特别小的
109128
df_filter(dfs)
129+
# 按分钟聚合
130+
dfs = merge_dfs(dfs,merge_step=3)
110131
arr = transfer(dfs)
111132
return arr
112133

@@ -124,10 +145,6 @@ def mypickle(filepath,data):
124145
#print (pca_obj.main_x.shape)
125146
#print (pca_obj.rest_x.shape)
126147

127-
mypickle('dump_arr.txt',arr)
128-
mypickle('dump_main_x.txt',pca_obj.main_x)
129-
mypickle('dump_rest_x.txt',pca_obj.rest_x)
130-
131-
132-
133-
148+
mypickle('dump_arr_9-13.txt',arr)
149+
mypickle('dump_main_x_9-13.txt',pca_obj.main_x)
150+
mypickle('dump_rest_x_9-13.txt',pca_obj.rest_x)

序列预测/PCA去趋势化/show.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ def myload(filename):
1414
f.close()
1515
return data
1616

17+
def show1(arr):
18+
for item in arr:
19+
plt.plot(item)
20+
plt.show()
1721

18-
def show(main_x,rest_x):
19-
#for item in main_x:
20-
# plt.plot(item)
22+
def show2(main_x,rest_x):
23+
for item in main_x:
24+
plt.plot(item)
2125
for item in rest_x:
2226
plt.plot(item)
2327
plt.show()
2428

25-
2629
if __name__=="__main__":
27-
arr = myload("dump_arr.txt")
28-
main_x = myload("dump_main_x.txt")
29-
rest_x = myload("dump_rest_x.txt")
30-
show(arr,arr)
31-
32-
30+
arr = myload("dump_arr_9-13.txt")
31+
main_x = myload("dump_main_x_9-13.txt")
32+
rest_x = myload("dump_rest_x_9-13.txt")
33+
show1(arr)
34+
show2(main_x,rest_x)

0 commit comments

Comments
 (0)