【发布时间】:2018-12-22 11:25:25
【问题描述】:
样本数据:
名称 描述 位置
玫瑰种花克什米尔,乌蒂
洋葱类蔬菜古吉拉特邦
我需要传递一个记录(string1,string2)。这两个字符串是 数据集包含类似
name description
但我尝试在 python 中使用 svm 传递一个标签并预测另一个标签
#Python CODE
data=pandas.csv(data.csv)
data_1=data[0:800]
data_2=data[800:1000]
svm.fit(data_1['name'], data_1['description'])
svm.predict(data_2['name'])
print("enter the name")
i=str(input())
predicted=svm.predict(i)
print("predicted description is")
print(predicted) #here the description will be predicted
但在上面的代码中,我只传递标题作为输入并预测描述。
我通过添加另一列作为位置来扩展数据集
所以数据集中会有三列
name,description,location
所以我现在需要传递名称和描述作为输入,我需要预测位置作为结果
我不知道如何在 predict() 方法中传递两个标签(名称、描述)来预测位置作为结果或任何其他可用的解决方案(如果适用)意味着请发布解决方案。
编辑:
我按照cmets修改了代码:
#Python CODE
data=pandas.csv(data.csv)
data_1=data[0:100]
data_2=data[50:100]
svm.fit(data_1[['name','description']], data_1['location'])
svm.predict(data_2['location'])
print("enter the name")
i=str(input())
print("enter the description")
j=str(input())
predicted=svm.predict(i)
print("predicted location is")
print(predicted) #here the location will be predicted
运行此代码后出现以下错误:
ValueError:在 svm_fit(data_1[['name','description']],data_1['location']) 中找到样本数不一致的输入变量[2,100]
【问题讨论】:
-
试试:
svm.fit(data_1[['name','description']], data_1['location']) -
你试过了吗?成功了吗?
-
它正在生成ValueError:添加svm.fit(data_1[['name','description']],data_1['location']后发现样本数不一致的输入变量[2,100] ) 而不是 svm.fit(data_1['name'], data_1['description'])。有没有其他解决方案
-
在上面的问题中发布您的代码。它应该被排序。
-
您可以从数据变量中添加示例记录吗?
标签: python machine-learning svm