Ich denke, der folgende Fehler wird aufgrund von Werten wie 4 und 5 . Konvertieren Sie sie in Kategorie DataType. (aber es funktioniert trotzdem nicht) < /p>
Code: Select all
cols=X_train.select_dtypes(exclude='int').columns.to_list()
X_train[cols]=X_train[cols].astype('category')
< /code>
Und meine Dateninformationen sehen unten nach < /p>
Int64Index: 683 entries, 21 to 965
Data columns (total 9 columns):
#   Column                                           Non-Null Count  Dtype
---  ------                                           --------------  -----
0   Feature_A                                        683 non-null    category
1   Product Classification                           683 non-null    category
2   Industry                                         683 non-null    category
3   DIVISION                                         683 non-null    category
4   biz_category                                     683 non-null    category
5   Country                                          683 non-null    category
6   Product segment                                  683 non-null    category
7   SUBREGION                                        683 non-null    category
8   Quantity 1st year                                683 non-null    int64
dtypes: category(8), int64(1)
< /code>
Also erhalte ich nach DTYPE -Konvertierung, wenn ich den folgenden Smotenc versuche, einen Fehler < /p>
print("Before OverSampling, counts of label '1': {}".format(sum(y_train == 1)))
print("Before OverSampling, counts of label '0': {} \n".format(sum(y_train == 0)))
cat_index = [0,1,2,3,4,5,6,7]
# import SMOTE module from imblearn library
# pip install imblearn (if you don't have imblearn in your system)
from imblearn.over_sampling import SMOTE, SMOTENC
sm = SMOTENC(categorical_features=cat_index,random_state = 2,sampling_strategy = 'minority')
X_train_res, y_train_res = sm.fit_resample(X_train, y_train)
< /code>
Dies führt zu einem Fehler wie unten gezeigt < /p>
------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ TypeError TraceBack (neuester Anruf
letztes)
~\appdata\roaming\Python\Python39\site-Packages\Sklearn\utils_encode.py
In _unique_python (Werte, return_inverse)
134
-> 135 Uniques = sortiert (uniques_set)
136 uniques.extend (fehlende_values.to_List ()) < /p>
TypeError: ' Mobile version
 Mobile version