我有一个包含 21000 行(数据样本)和 102 列(特征)的数据集。我想根据当前数据集生成一个更大的合成数据集,比如 100000 行,这样我就可以将它用于机器学习目的。
我一直在参考@Prashant 在这篇文章中的回答https://stats.stackexchange.com/questions/215938/generate-synthetic-data-to-match-sample-data,但我无法让它工作为我的数据生成更大的合成数据集。
import numpy as np
from random import randrange, choice
from sklearn.neighbors import NearestNeighbors
import pandas as pd
#referring to https://stats.stackexchange.com/questions/215938/generate-synthetic-data-to-match-sample-data
df = pd.read_pickle('df_saved.pkl')
df = df.iloc[:,:-1] # this gives me df, the final Dataframe which I would like to generate a larger dataset based on. This is the smaller Dataframe with 21000x102 dimensions.
def SMOTE(T, N, k):
# """
# Returns (N/100) * n_minority_samples synthetic minority samples.
#
# …Run Code Online (Sandbox Code Playgroud) 我想考虑使用加权随机选择一个值Pandas。
df:
0 1 2 3 4 5
0 40 5 20 10 35 25
1 24 3 12 6 21 15
2 72 9 36 18 63 45
3 8 1 4 2 7 5
4 16 2 8 4 14 10
5 48 6 24 12 42 30
Run Code Online (Sandbox Code Playgroud)
我知道使用np.random.choice,例如:
x = np.random.choice(
['0-0','0-1',etc.],
1,
p=[0.4,0.24 etc.]
)
Run Code Online (Sandbox Code Playgroud)
因此,我想以类似于np.random.choicefrom的样式/替代方法来获取输出df,但使用Pandas。与如上所述手动插入值相比,我想以一种更有效的方式进行操作。
使用np.random.choice我知道所有值都必须加起来1。我不确定如何解决这个问题,也不确定使用来基于加权随机选择一个值Pandas。
当指代输出时,如果随机选择的权重例如为40,则输出将位于0-0中,因为它位于那个中column …