在 Python 中将 SVM 拟合到 pandas 数据框上
我有一个名为 dataset
的 pandas 数据框,并将其前两列导出为 X
,将名为“Class”的最后一列导出为 y
code>:
X = dataset.drop('Class', axis=1)
y = dataset['Class']
然后使用以下代码行,我尝试使用这些数据来拟合 SVM:
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20)
之后,使用下面的两行,我尝试训练 SVM,但出现以下错误。
SupportVectorClassModel = SVC()
SupportVectorClassModel.fit(X_train,y_train)
如何解决此问题?
I have a pandas data frame named dataset
and I exported the first two columns of it as X
and the last column which is named "Class" as y
:
X = dataset.drop('Class', axis=1)
y = dataset['Class']
Then using the following lines of code, I tried to fit SVM using these data:
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20)
After that, using the two lines below, I tried to train the SVM but I got the following error.
SupportVectorClassModel = SVC()
SupportVectorClassModel.fit(X_train,y_train)
How can I fix this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将您的数据框转换为列表。然后将数据帧拆分为 X 和 Y 后拆分并适合模型
,使用
values
函数或tolist
函数将其转换为列表。 IEtry to convert your dataframe into the list. then split and fit into model
after you split the dataframe into X and Y, convert it into list by using
values
function ortolist
function. i.e