이 포스팅은 두 편을 걸쳐 진행됩니다. ( 1편 : 오픈소스 데이터셋 전처리, 2편 : 논문 기반 네트워크를 통해 학습 )
Doctor Klemen Bregar providingthe UWB NLOS/LOS open source data를 딥러닝을 위해 전처리 과정이 필요합니다.
오픈소스는 csv, 데이터를 불러오는 모듈로 구성되어 있습니다.
4년 전 데이터이므로 pandas 버전 오류 해결을 위해 uwb_dataset.py를 약간 변경했습니다.
uwb_dataset.py
"""
Created on Feb 6, 2017
@author: Klemen Bregar
"""
import os
import pandas as pd
from numpy import vstack
def import_from_files():
"""
Read .csv files and store data into an array
format: |LOS|NLOS|data...|
"""
rootdir = '../dataset/'
output_arr = []
first = 1
for dirpath, dirnames, filenames in os.walk(rootdir):
for file in filenames:
filename = os.path.join(dirpath, file)
print(filename)
output_data = []
# read data from file
df = pd.read_csv(filename, sep=',', header=0)
# ------------------------ update Mar 3, 2021 ----------------------------- #
columns_name = df.columns.values
# ------------------------ update Mar 3, 2021 ----------------------------- #
# ------------------------ update Mar 3, 2021 ----------------------------- #
# input_data = df.as_matrix()
# df.as_matrix() was depriciated after the version 0.23.0 use df.values()
input_data = df.values
# ------------------------ update Mar 3, 2021 ----------------------------- #
# append to array
if first > 0:
first = 0
output_arr = input_data
else:
output_arr = vstack((output_arr, input_data))
return columns_name, output_arr
if __name__ == '__main__':
# import raw data from folder with dataset
print("Importing dataset to numpy array")
print("-------------------------------")
data = import_from_files()
print("-------------------------------")
# print dimensions and data
print("Number of samples in dataset: %d" % len(data))
print("Length of one sample: %d" % len(data[0]))
print("-------------------------------")
print("Dataset:")
print(data)
1. Load UWB data
import numpy as np
import pandas as pd
import uwb_dataset
# import raw data
data = uwb_dataset.import_from_files()
# divide CIR by RX preable count (get CIR of single preamble pulse)
# item[2] represents number of acquired preamble symbols
for item in data:
item[15:] = item[15:]/float(item[2])
print("\nColumns :", columns.shape, sep=" ")
print("Data :", data.shape, sep=" ")
print(type(data))
# LOS/NLOS Count
los_count = df_uwb.query("NLOS == 0")["NLOS"].count()
nlos_count = df_uwb.query("NLOS == 1")["NLOS"].count()
print("Line of Sight Count :", los_count)
print("Non Line of Sight Count :", nlos_count)
# Columns CIR Extract
df_uwb_data = df_uwb[["CIR"+str(i) for i in range(cir_n)]]
print("UWB DataFrame X for Trainndarray shape : ",df_uwb_data.values.shape)
df_uwb_data.head(5)
Columns : Sampling 1016 CIR
LOS : 21000, NLOS : 21000 Pandas Dataframe
다음 글은 생선된 위 데이터 프레임을 이용해 논문에 제시된 CNN+LSTM 모델을 Pytorch로 구현하겠습니다.
pandas_datareader을 이용해서 데이터 처리를 하기 위해 아래 문구처럼 에러문이 뜨는 경우가 있습니다.
FutureWarning: pandas.util.testing is deprecated. Use the functions in the public
API at pandas.testing instead. from pandas.util.testing import assert_frame_equal
아래 에러문이 뜨더라도 실제 코딩하는데는 아무 문제 없습니다.
위 에러문은 pandas.util.testing 에서 더 이상 사용되지 않기 때문에 뜹니다.
대신, pandas.testing에서 사용할 수 있으니 수정하라는 권고문 같은 정도입니다.
실행될 때마다 에러문이 발생하면 기분이 별로 좋지 않으니 에러문이 뜨지 않도록 수정해주겠습니다.
에러문 옆을 보면 pandas_datareader/compat/__init__.py에서 7번 째 줄에서 해당 에러문이 발생하는 것을 알 수 있습니다.