我的数据不平衡,M 的百分比为 80%,F 的百分比为 20%。以下是数据示例:
NAME COUNTRY HEIGHT HANDPHONE TYPE GENDER
NOVI USA 160 samsung SM-G610F F
JOHN JAPAN 181 vivo 1718 M
RICHARD UK 175 samsung SM-G532G M
ANTHONY UK 179 OPPO F1fw M
SAMUEL UK 185 Iphone 8 plus M
BUNGA KOREA 170 Iphone 6s F
所以我想用 M:F 的百分比来平衡数据是 50%:50% 使用SMOTENC
. 我试过这个脚本:
import numpy as np
import pandas as pd
import scipy.stats as stats
import sklearn
import keras
import imblearn
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('ggplot')
df=pd.read_excel('Data for oversampling.xlsx')
Data = df
Data.GENDER.replace({'M':0,'F':1},inplace=True)
sns.countplot('GENDER', data = Data)
y = Data.GENDER
x = Data.drop('GENDER', axis=1)
from imblearn.over_sampling import SMOTENC
smote_nc = SMOTENC(categorical_features=[0,3], random_state=0)
x_resampled, y_resampled = smote_nc.fit_resample(x, y)
但我得到这样的错误:
could not convert string to float
任何人都可以帮忙吗?