Skip to main content
 首页 » 编程设计

python之reshape 和转置问题

2024年10月01日698°冷暖

User1190882 帮助解决了转置问题。我将为 SKlearn 问题打开一个新线程。

columns_train = np.array([df['A'], df['B'],  df['C'], df['D'], df['E'], df['F'], df['G']]) 
X = columns_train 
Y = columns_target 
 
X = np.transpose(X) 
print np.shape(X) 
print np.shape(Y) 
 
 
X_train, X_test, Y_train, Y_test = train_test_split(X,Y,test_size = 0.2, random_state = 42) 
 
clf = svm.LinearSVC() 
clf.fit(X_train, Y_train) 
print clf 
 
File "C:\Python27\lib\site-packages\sklearn\utils\multiclass.py", line 172, in check_classification_targets 
raise ValueError("Unknown label type: %r" % y_type) 
ValueError: Unknown label type: 'continuous' 

在查看其他线程后,我不确定我能做些什么来使这项工作正常进行。你能给我一些建议吗?谢谢

请您参考如下方法:

编辑问题前的回答

你要找的是

X = np.transpose(X) 

编辑问题后回答

当您的变量 Y 的数据类型是浮点类型时,您会收到 continuous 错误。在所有分类类型的问题中,您必须将标签类型维护为int。将变量 Y 的数据类型转换为 int,然后它应该可以正常工作。