【问题标题】:multiclass classification with double values and scikit具有双值和 scikit 的多类分类
【发布时间】:2017-01-11 07:47:52
【问题描述】:

我想训练一个程序来根据它们包含的数值给字典提供各种标签 - 使用 scikit。 我的问题是,我似乎只了解如何对文本(句子)或数字变量(而不是包含多个数字的变量)进行分类。

这是我想要做的:

# available classes:
# hot, cold, wet, sticky

first_sample = {}
first_sample["temp"] = 30
first_sample["airpressure"] = 104
first_sample["airmoisture"] = 70

second_sample = {}
second_sample["temp"] = 2
second_sample["airpressure"] = 100
second_sample["airmoisture"] = 40

# do this manually X times
train(first_sample, ['sticky', 'hot'])
train(second_sample, ['wet', 'cold'])
train(...)

# then do it on a bunch of data by programme
classify(bunch_of_data)

【问题讨论】:

  • 这将是(在 sci-kit 术语中)多标签分类或多任务分类的示例。这个page 有更多信息。如果 dict 必须有标签(必须是 hotcold,必须是 stickywet),那么它可能是更多的多任务分类。如果它可以有可变数量的标签分配给它,它可能是多标签分类。将 dicts 中的信息转换为数据框将是构建此类分类器的第一步。

标签: python scikit-learn classification


【解决方案1】:

您需要训练两个分类器并将它们拟合到您的数据中两次。假设您的数据是(您可以使用 Pandas 将您的 dicts 转换为数据框):

| "temp" | "airpressure" | "airmoisture"| "target1" | "target2" | 
|:------:|:-------------:|:------------:|:---------:|:---------:|
|   30   |      104      |      70      |  'sticky' |   'hot'   |
|   2    |      100      |      40      |    'wet'  |   'cold'  |
|   .    |       .       |       .      |      .    |     .     |
|   .    |       .       |       .      |      .    |     .     |
|   .    |       .       |       .      |      .    |     .     |

首先,将第一个分类器 (clf1) 拟合到所有样本(我们称之为 X)和目标的第一列 target1(我们称之为 y1)

clf1.fit(X,y1)

然后是 X 上的第二个分类器 (clf2) 和目标 target2(或 y2)的第二列。

clf2.fit(X,y2)

【讨论】:

    猜你喜欢
    • 2014-09-21
    • 2013-09-26
    • 2019-08-31
    • 2015-07-26
    • 2016-09-04
    • 1970-01-01
    • 2016-10-17
    • 2020-05-18
    • 2019-04-01
    相关资源
    最近更新 更多