微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 SMOTETomek 进行过采样:无法将字符串转换为浮点错误

如何解决使用 SMOTETomek 进行过采样:无法将字符串转换为浮点错误

当我使用以下代码执行过采样时,使用 SMOTetomek 来平衡不平衡的数据集,

from imblearn.combine import SMOTetomek
import pandas as pd

# read the input dataset
input_dataset = pd.read_csv('sample.csv')

# get all the column names as the element of a list
columns = input_dataset.columns.tolist()

# get the target_column and all the other columns from the columns list
target_column = "svalue_numerical"
other_columns = [item for item in columns if item not in [target_column]]

X = input_dataset[other_columns]
y = input_dataset[target_column]

# Over-sampling using SMOTE and cleaning using Tomek links
oversample = SMOTetomek(random_state=42)
X_oversampled,y_oversampled = oversample.fit_resample(X,y)

我收到以下错误

ValueError: Could not convert string to float: '2019-04-04 00:00:00.000049'

我的理解是,我无法将字符串类型的 DataFrame 提供给 fit_resample() 方法。我尝试按照建议的 here 将 DataFrame 转换为 numpy array,但我无法得到预期的结果。

我的数据集样本如下:

timestamp                      evalue       svalue        evalue_numerical        svalue_numerical
2019-04-04 00:00:00.000049     cam          cam_on        0                       1
2019-04-04 00:00:15.020115     fan          fan_off       1                       3
2019-04-04 00:00:15.031492     pc           pc_on         2                       5
2019-04-04 00:00:15.050193     scr          scr_on        3                       7
................................................................................................
................................................................................................

你能提出一些可以解决这个问题的建议吗?感谢您的帮助。

注意:如果需要,我可以去掉 evaluesvalue 列,但我必须在过采样数据集中包含 timestamp 列。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。