多类别分类问题中的失衡-四个目标级别

我的数据不平衡,如下所示,每当我尝试使用ADASYN时,它都会显示错误,是否需要为同一参数提供任何参数输入?它会运行很长时间,但是即使运行40分钟的代码也没有响应。

                     counts  percentage
Enquiry Assigned      91284   75.902382
Test Drive Provided   25274   21.015258
Test Drive Arranged    3434    2.855361
Booked                  266    0.221178
Test Ride Provided        7    0.005820

请建议我们如何继续使用python代码解决问题。从其他人的推荐中,我听到像

  1. 可以一次在两个级别之间进行采样,然后可以在同一级别上进行迭代
  2. 对75%的人进行下采样可能会有所帮助吗?
  3. 或使用skmultilearn的任何解决方案?

'''

def makeOverSamplesADASYN(X,y):

    #X →Independent Variable in DataFrame\
     #y →dependent Variable in Pandas DataFrame format
     from imblearn.over_sampling import ADASYN 
     sm = ADASYN(sampling_strategy='all',random_state=None,n_neighbors=5,n_jobs=1,ratio=None)

     X_adassin,y_adassin = sm.fit_resample(X,y)

 makeOverSamplesADASYN(X,data_dummyvar['Sales Stage'])

 print(X_adassin.shape)
 print(y_adassin.shape)'''   

o / p ===>这会运行很长时间,此后没有结果,请建议

eblisjiang 回答:多类别分类问题中的失衡-四个目标级别

我使用下面的代码对排名靠前的条目进行了下采样。

### " data_dummyvar " is my dataframe with the shape of (120265,894)

df_majority=data_dummyvar[data_dummyvar['Sales Stage']=='Enquiry Assigned']
df_majority.shape
from sklearn.utils import resample

# Downsample majority class
df_majority_downsampled = resample(df_majority,replace=False,n_samples=25289,random_state=123)                                   
#replace: sample without replacement
# n_samples: to match minority class
#random_state: reproducible results
df_majority_downsampled.shape
df_minority=data_dummyvar[data_dummyvar['Sales Stage'] !='Enquiry Assigned']
df_minority['Sales Stage'].value_counts()
df_first_scaling = pd.concat([df_majority_downsampled,df_minority],ignore_index=True)
g = df_first_scaling['Sales Stage']
df = pd.concat([g.value_counts(),g.value_counts(normalize=True).mul(100)],axis=1,keys=('counts','percentage'))
print (df)

上面的代码将给出如下结果:o / p === >>

                        counts  percentage
Enquiry Assigned      25289   46.598489
Test Drive Provided   25281   46.583748
Test Drive Arranged    3434    6.327621
Booked                  266    0.490142

“已分配的查询”条目现在在此处向下采样。

现在我们需要对数据“ df_first_scaling”运行两次SMOTE / ADASYN算法,因为我们还有以下三个条目

def makeOverSamplesADASYN(X,y):
   #input DataFrame
   #X →Independent Variable in DataFrame\
   #y →dependent Variable in Pandas DataFrame format
   from imblearn.over_sampling import ADASYN 
   sm = ADASYN(sampling_strategy='minority',random_state=None,n_neighbors=5,n_jobs=1,ratio=None)
   global X_adassin_1
   global y_adassin_1
   X_adassin_1,y_adassin_1 = sm.fit_resample(X,y)

makeOverSamplesADASYN(X,df_first_scaling['Sales Stage']) # function call

print(X_adassin_1.shape)
print(y_adassin_1.shape)

这给出o / p,其形状为==>

(79334,893)
(79334,) 

在更新后的数据集上再次运行它之后,我们可以得到形状为(101229,893)&(101229,)的样本df

本文链接:https://www.f2er.com/3162379.html

大家都在问