问题描述
我有两个数据框,有一个公共 A 列。我将每个数据框分组并在每个组的 A 列上应用了一个热编码。结果,我为每个数据帧获得了一组 onehot-encoded 值。这是这些数组的基本结构:
数据帧 1 的单热编码数组:
A
Item1 [[0.0,1.0,0.0,0.0],[0.0,0....
Item2 [[0.0,...
Item3 [[0.0,...
Item4 [[0.0,[0....
Item5 [[0.0,...
用于 dataframe2 的单热编码数组:
A
Item0 [[0.0,...
Item7 [[0.0,...
Item8 [[0.0,[0....
Item9 [[0.0,...
我尝试使用 train_test_split() 将这些数组拆分为训练集和测试集:
x_train,y_train,x_test,y_test = train_test_split(array_1,array_2,test_size=0.2,train_size=0.8)
但由于它们的长度不同,我收到了错误:
ValueError: Found input variables with inconsistent numbers of samples: [4832,5396]
我使用 reshape()
将两个数组重新整形为:
array_1 = array_1.values.reshape(1,-1)
array_2 = array_2.values.reshape(1,-1)
但我收到错误:
ValueError: With n_samples=1,test_size=0.2 and train_size=0.8,the resulting train set will be empty. Adjust any of the aforementioned parameters.
有没有一种有效的方法来重塑单热编码数组?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)