【发布时间】:2020-06-03 23:30:58
【问题描述】:
我想使用 SVM 聚类方法对列的行进行分类。我可以在网上找到很多可以生成图表或打印预测准确性的内容,但我找不到打印集群的方法。下面的示例将更好地解释我正在尝试做的事情:
我有一个数据框用作测试数据集
import pandas as pd
train_data = {'Serial': [1,2,3,4,5,6,7,8,9,10],
'Text': ['Dog is a faithful animal',cat are not reliable','Tortoise can live a long life',
'camel stores water in its hump','horse are used as means of transport','pen is a powerful weapon',
'stop when the signal is red','oxygen is a life gas','chocolates are bad for health','lets grab a cup of coffee'],
'classification':['Animal','Animal','Animal','Animal','Animal','Thing','Thing','Miscellenous','Thing','Thing']
}
df = pd.DataFrame(train_data, columns = ['Serial', 'Text', 'classification'])
print (df)
我想预测文本行是在谈论动物/事物还是杂项。我要通过的测试数据是
test_data = {'Serial': [1,2,3,4,5],
'Text': ['Is this your dog?','Lets talk about the problem','You have a cat eye',
'Donot forget to take the camel ride when u goto dessert','Plants give us O2']
}
df = pd.DataFrame(test_data, columns = ['Serial', 'Text'])
预期结果是在测试数据框中创建了一个附加列“分类”,其值为 ['Animal','Miscellenous','Animal','Animal','Miscellenous']
【问题讨论】:
标签: python scikit-learn cluster-analysis svm scikits