下取樣方法

2021-08-17 21:38:21 字數 1664 閱讀 2247

x=data.loc[:,data.columns!='class'] #loc 通過行標籤索引資料,

# print(x)

y=data.loc[:,data.columns=='class'] #取label

# print(y)

number_records_fraud=len(data[data.class==1]) #class=1的數量

# print(number_records_fraud)

fraud_indices=np.array(data[data.class==1].index) #取得其索引值

# print(fraud_indices)

normal_indices=np.array(data[data.class==0].index) # 把class為0的資料索引拿到手

# print(normal_indices)

random_normal_indices=np.random.choice(normal_indices,number_records_fraud,replace=false) # 隨機取樣,並不對原始dataframe進行替換

random_normal_indices=np.array(random_normal_indices) # 轉換成numpy的array格式轉換成矩陣

# print(random_normal_indices)

under_sample_indices=np.concatenate([fraud_indices,random_normal_indices]) # 將兩組索引資料連線成性的資料索引

# print(under_sample_indices)

under_sample_data = data.iloc[under_sample_indices,:] #定位到真正資料,iloc通過行號索引行資料

# print(under_sample_data)

x_undersample=under_sample_data.loc[:,under_sample_data.columns!='class']

y_undersample=under_sample_data.loc[:,under_sample_data.columns=='class']

print(x_undersample)

print(y_undersample)

print("percentage of normal transactions: ", len(under_sample_data[under_sample_data.class == 0])/len(under_sample_data))

print("percentage of fraud transactions: ", len(under_sample_data[under_sample_data.class == 1])/len(under_sample_data))

print("total number of transactions in resampled data: ", len(under_sample_data))

上取樣 下取樣

下取樣 定義 對於乙個樣值序列間隔幾個樣值取樣一次,這樣得到新序列就是原序列 的下取樣。取樣率變化主要是由於訊號處理的不同模組可能有不同的取樣率要求。下取樣相對於最初的連續時間 訊號而言,還是要滿足取樣定理才行,否則這樣的下取樣會引起訊號成分混疊。下取樣就是抽取,是多速率訊號處理中的基本內容之一。在...

降取樣,過取樣,欠取樣,子取樣,下取樣

這幾天看了一篇將關於降取樣,過取樣,欠取樣,子取樣,下取樣 的文章,寫的挺好的,直接給出鏈結,文章比較長不貼過來了。簡單的說 過取樣是取樣頻率大於最高頻率的兩倍 奈奎斯特取樣率 實際對低通訊號取樣也是2.5倍左右過取樣。欠取樣就是小於奈奎斯特取樣率,應該就指帶通取樣吧。上取樣和下取樣其實對數碼訊號進...

降取樣,過取樣,欠取樣,子取樣,下取樣,上取樣

取樣 2048hz對訊號來說是過取樣了,事實上只要訊號不混疊就好 滿足尼奎斯特取樣定理 所以可 以對過取樣的訊號作抽取,即是所謂的 降取樣 在現場中取樣往往受具體條件的限止,或者不存在300hz的取樣率,或除錯非常困難等等。若 r 1,則rfs 2就遠大於音訊訊號的最高頻率fm,這使得量化雜訊大部分...