본문 바로가기
728x90
반응형
SMALL

Python Library186

[Pandas] 폴더 안에 있는 여러 개의 csv 파일 합치기 폴더 안에 있는 여러 개의 csv 파일 합치기 import pandas as pd from glob import glob # 폴더 내의 모든 csv파일 목록 불러오기 file_names = glob("/data/*.csv") # 빈 데이터프레임 하나 생성 total = pd.DataFrame() #빈 데이터프레임 하나를 생성 for file_name in file_names: # csv파일을 하나씩 열어 임시 데이터프레임으로 생성 temp = pd.read_csv(file_name, sep = ',', encoding = 'utf-8') #전체 데이터프레임에 추가하여 넣음 total = pd.concat([total, temp]) total.to_csv("/data/total.csv") df = pd.r.. 2022. 10. 20.
[Pandas] shuffle shuffle pandas에서 데이터를 섞어주는 함수가 존재한다. df # row 전체 shuffle df = df.sample(frac = 1) df # shuffling하고 index reset df = df.sample(frac = 1).reset_index(drop = True) df 2022. 10. 17.
[PyTorch] 활성화 함수 : Non-linear Activations (weighted sum, nonlinearity) Sigmoid (0 ~ 1) import torchimport matplotlib.pyplot as pltx = torch.linspace(-10, 10, 100)y = torch.sigmoid(x)print(x)print(y)tensor([-10.0000, -9.7980, -9.5960, -9.3939, -9.1919, -8.9899, -8.7879, -8.5859, -8.3838, -8.1818, -7.9798, -7.7778, -7.5758, -7.3737, -7.1717, -6.9697, -6.7677, -6.5657, -6.3636, -6.1616, -5.9596, -5.7576, -5.5556, -5.3535, -.. 2022. 9. 24.
[HeartPy] Colorblind mode (2) Colorblind mode # Now let's do colorblind protanopia friendly palettes hp.config.colorblind = True hp.config.colorblind_type = 'tritanopia' for palette in palettes: hp.config.color_style = palette hp.plot_poincare(wd, m, title='color palette: %s' %palette) import matplotlib.pyplot as plt data, timer = hp.load_exampledata(1) fs = hp.get_samplerate_mstimer(timer) wd, m = hp.process(data, 100.0, cl.. 2022. 8. 25.
[HeartPy] Colorblind mode (1) Colorblind mode 1.2.4 이후로 HeartPy는 colorbilnd 모드가 플롯 API에 구현되어 있다. 여러 가지 다른 스타일을 사용할 수 있으며, deuteranopia (제2 색맹), protanopia (제 1색맹), tritanopia (제 3색맹)에 대한 지원이 가능하다. heartpy.config를 통해 쉽게 사용할 수 있다. heartpy.config.colorblind_type 지원하려는 colorbilnd 유형으로 설정한다. deuteranopia (default) protanopia tritanopia heartpy.config.color_style 원하는 색깔을 지정한다. default (default) retro elegant corporate zesty # load.. 2022. 8. 25.
[HeartPy] Noisy ECG 신호 분석 (2) Noisy ECG 신호 분석 작동은 정상이지만, 일부 거부에는 하면 안 되는 부분이 있다 (올바른 피크가 잘못된 것으로 표시됨). 심전도에는 일반적으로 매우 좁은 피크가 있다. 필터링은 일반적으로 최대값을 같은 위치에 유지하지만 파형을 더 좁혀 문제를 일으킬 수 있다. HeartPy는 훨씬 더 넓은 PPG 파형을 위해 설계되었기 때문에 업샘플링은 일반적으로 피크당 더 많은 데이터 포인트를 제공하기 때문에 트릭을 수행한다. 상대 피크 위치를 이동하거나 변경하지 않는다. from scipy.signal import resample resampled_signal = resample(filtered, len(filtered) * 4) wd, m = hp.process(hp.scale_data(resampled_.. 2022. 8. 25.
[HeartPy] Noisy ECG 신호 분석 (1) Noisy ECG 신호 분석 HeartPy를 사용하여 특히 노이즈가 많은 심전도 신호를 분석하는 방법이 있다. 심전도 분석에서 전처리 단계는 피크 형태에 차이가 있기 때문에 PPG 신호와 약간 다르지만 일반적인 분석은 동일한 방식으로 처리된다. MIT-BIH Noise 스트레스 테스트 데이터 세트의 데이터를 사용한다. 이 데이터는 wfdb 패키지와 함께 로드되어야 하지만, 사용하기 쉽도록 4개의 파일을 .csv 데이터로 변환했다. 모든 파일이 360Hz로 기록된다. SNR (Signal-to-Noise) 비율이 다양한 다음 파일을 사용한다. 118e24 : SNR : 24dB 118e12 : SNR = 12dB 118e06 : SNR = 6dB 118e00 : SNR = 0dB 이 파일에는 잡음 섹션과 .. 2022. 8. 25.
[HeartPy] 스마트 링 PPG 신호 분석 스마트 링 PPG 신호 분석 최근 시장을 강타한 다양한 스마트 반지가 있다. 무엇보다도 그들은 손가락에 PPG 신호를 기록하기 때문에, HeartPy로 이것들을 분석하는 방법이 있다. 예제 파일에는 파일 크기를 낮게 유지하기 위해 PPG 신호만 포함되어 있다. 많은 스마트 링은 또한 피부 반응, acceleration 및 gyroscopic 데이터를 기록한다. 32Hz로 기록되었다. # Let's import some packages first import numpy as np import matplotlib.pyplot as plt import heartpy as hp sample_rate = 32 # load the example file data = hp.get_data('ring_data.csv'.. 2022. 8. 24.
[HeartPy] 스마트 워치 PPG 신호 분석 (2) 스마트 워치 PPG 신호 분석 # let's resample to ~100Hz as well # 10Hz is low for the adaptive threshold analysis HeartPy uses from scipy.signal import resample resampled = resample(filtered, len(filtered) * 10) # don't forget to compute the new sampling rate new_sample_rate = sample_rate * 10 # run HeartPy over a few segments, fingers crossed, and plot results of each for s in [[0, 10000], [10000, 20000], .. 2022. 8. 24.
[HeartPy] 스마트 워치 PPG 신호 분석 (1) 스마트 워치 PPG 신호 분석 삼성 스마트 워치 장치에서 가져온 원시 PPG 데이터 분석에 HeartPy를 사용하는 방법이다. 측정된 신호는 손목보다 관류 측정이 훨씬 쉬운 손가락 끝이나 귓불의 일반적인 PPG 센서와 비교할 때 훨씬 더 많은 소음을 포함한다. 이러한 신호를 분석하려면 몇 가지 추가 단계가 필요하다. import numpy as np import heartpy as hp import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('raw_ppg.csv') df.keys() Index(['ppg', 'timer'], dtype='object') plt.figure(figsize=(12,6)) plt.plot(df['ppg']... 2022. 8. 24.
728x90
반응형
LIST