0

SMOTENC を使用して、不均衡な分類の問題を解決しています。

df_train, df_test = train_test_split(input_table_1_df, test_size=0.25, stratify=input_table_1_df["Target_Variable_SX_FASCIA_1"])
    
                  ###### SMOTE ######
    # Create features table and target table
    df_x = df_train.loc[ : , df_train.columns != "Target_Variable_SX_FASCIA_1"] 
    df_y = df_train.drop(["Target_Variable_SX_FASCIA_1"], axis=1)
    
    # From pandas to numpy arrays
    from imblearn.over_sampling import SMOTENC
    
    df_X=df_x.to_numpy()
    df_Y=df_y.to_numpy()
    
    column_name_x=list(df_x.columns) 
    column_name_y=list(df_y.columns) 
    
    # Resampling
    smote_nc = SMOTENC(categorical_features=[0,1,2,3,4,5], random_state=0,sampling_strategy=.2)
    X_resampled, Y_resampled = smote_nc.fit_resample(df_X, df_Y)
    X_resampled_df= pd.DataFrame(X_resampled,columns=column_name_x)
    Y_resampled_df= pd.DataFrame(Y_resampled,columns=column_name_y)
    Training_set_Passivi_Fascia_1 = pd.concat([X_resampled_df, Y_resampled_df], axis=1)

行で次のエラーが発生しました。

X_resampled, Y_resampled = smote_nc.fit_resample(df_X, df_Y)

TypeError: 'int' と 'str' のインスタンス間で '<' はサポートされていません

変数の型の問題であることは理解できますが、このエラーを解決する方法がわかりません。私はすでにしようとしました:

  1. 欠損値をすべて置き換える
  2. 考えられるすべての変数の型の指定ミスを修正

その他の有用な情報: データセットの最初の 6 つの変数は文字列で、その他は倍精度または整数です。

さらに情報が必要かどうか尋ねてください。

前もって感謝します。

4

1 に答える 1