- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个大小为 200 的小数据集。该数据集非常简单:每行由 [0, 1] 范围内的实数值组成,映射到单个标签。总共有 24 个标签,我的任务的本质是训练分类器以基本上找到映射到标签的范围。
我能想到两种方法。第一个是 SVC,因为它们能够将输入平面分为 24 个区域,这正是我所需要的。然而,当我尝试对其进行编码时,最终得到了一些可怕的结果:分类器没有学到任何东西,并且无论输入值如何,都会输出相同的标签。
我正在考虑的第二种方法是神经网络,但由于缺乏特征和训练数据,我非常怀疑这种方法的可行性。
如果需要,我可以分享我用 scikit-learn 开发的 SVC 代码。
这是我转储到终端的数据:
Label: Min, Mean, Max
{0: [0.96, 0.98, 1.0],
1: [0.15, 0.36, 0.92],
2: [0.14, 0.56, 0.98],
3: [0.37, 0.7, 1.0],
4: [0.23, 0.23, 0.23],
6: [0.41, 0.63, 0.97],
7: [0.13, 0.38, 0.61],
8: [0.11, 0.68, 1.0],
9: [0.09, 0.51, 1.0],
10: [0.19, 0.61, 0.97],
11: [0.26, 0.41, 0.57],
12: [0.29, 0.72, 0.95],
13: [0.63, 0.9, 0.99],
14: [0.06, 0.55, 1.0],
15: [0.1, 0.64, 1.0],
16: [0.26, 0.58, 0.95],
17: [0.29, 0.88, 1.0],
21: [0.58, 0.79, 1.0],
22: [0.24, 0.59, 0.94],
23: [0.12, 0.62, 0.95]}
正如你所看到的,数据到处都是,但我想知道是否有可能找到每个标签最能代表的范围。
如果有人能告诉我我是否走在正确的道路上,我将不胜感激。谢谢!
最佳答案
如果我们假设每个类的样本有些居中(但仍然有噪音;可能存在重叠),那么 sklearn 中可用的最自然的分类器可能是 Gaussian Naive Bayes我们假设每个类别的分数遵循正态分布。
这是一些代码,它构建一些虚假数据,对其进行分类并评估:
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
np.random.seed(1)
""" Data-params + Data-generation """
N_CLASSES = 24
N_SAMPLES_PER_CLASS = 10
SIGMA = 0.01
class_centers = np.random.random(size=N_CLASSES)
# ugly code with bad numpy-style
X = []
for class_center in class_centers:
samples = np.random.normal(size=N_SAMPLES_PER_CLASS)*SIGMA
for sample in samples + class_center:
X.append(sample)
Y = []
for ind, c in enumerate(class_centers):
for s in range(N_SAMPLES_PER_CLASS):
Y.append(ind)
X = np.array(X).reshape(-1, 1)
Y = np.array(Y)
""" Split & Fit & Eval """
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.1, random_state=0)
et = GaussianNB()
et.fit(X_train, y_train)
print('Prediction on test')
preds = et.predict(X_test)
print(preds)
print('Original samples')
print(y_test)
print('Accuracy-score')
print(accuracy_score(y_test, preds))
输出
Prediction on test
[10 7 3 7 8 3 23 3 11 19 7 20 8 15 11 13 18 11 3 16 8 9 8 12]
Original samples
[10 7 3 7 10 22 15 22 15 19 7 20 8 15 23 13 18 11 22 0 10 17 8 12]
Accuracy-score
0.583333333333
当然,结果高度依赖于 N_SAMPLES_PER_CLASS
和 SIGMA
。
编辑:
正如您现在提供的数据一样,很明显我的假设不成立。请参阅此代码完成的以下绘图(文件已从 []()
中删除;人们确实应该发布 csv 兼容的数据!):
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv('idVXjwgZ.txt', usecols=[0,1], names=['x', 'y'])
sns.swarmplot(data=data, x='y', y='x')
plt.show()
剧情:
现在只要考虑观察一些x
,您就需要决定y
。对于大多数x范围来说相当困难。
显然还存在类平衡问题,它解释了大多数预测的第 14 类的输出。
关于machine-learning - 用于数值转换的机器学习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42772637/
基本上,我的问题是,由于无监督学习是机器学习的一种,是否需要机器“学习”的某些方面并根据其发现进行改进?例如,如果开发了一种算法来获取未标记的图像并找到它们之间的关联,那么它是否需要根据这些关联来改进
生成模型和判别模型似乎可以学习条件 P(x|y) 和联合 P(x,y) 概率分布。但从根本上讲,我无法说服自己“学习概率分布”意味着什么。 最佳答案 这意味着您的模型要么充当训练样本的分布估计器,要么
是否有类似于 的 scikit-learn 方法/类元成本 在 Weka 或其他实用程序中实现的算法以执行常量敏感分析? 最佳答案 不,没有。部分分类器提供 class_weight和 sample_
是否Scikit-learn支持迁移学习?请检查以下代码。 型号 clf由 fit(X,y) 获取 jar 头型号clf2在clf的基础上学习和转移学习 fit(X2,y2) ? >>> from s
我发现使用相同数据的两种交叉验证技术之间的分类性能存在差异。我想知道是否有人可以阐明这一点。 方法一:cross_validation.train_test_split 方法 2:分层折叠。 具有相同
我正在查看 scikit-learn 文档中的这个示例:http://scikit-learn.org/0.18/auto_examples/model_selection/plot_nested_c
我想训练一个具有很多标称属性的数据集。我从一些帖子中注意到,要转换标称属性必须将它们转换为重复的二进制特征。另外据我所知,这样做在概念上会使数据集稀疏。我也知道 scikit-learn 使用稀疏矩阵
我正在尝试在 scikit-learn (sklearn.feature_selection.SelectKBest) 中通过卡方方法进行特征选择。当我尝试将其应用于多标签问题时,我收到此警告: 用户
有几种算法可以构建决策树,例如 CART(分类和回归树)、ID3(迭代二分法 3)等 scikit-learn 默认使用哪种决策树算法? 当我查看一些决策树 python 脚本时,它神奇地生成了带有
我正在尝试在 scikit-learn (sklearn.feature_selection.SelectKBest) 中通过卡方方法进行特征选择。当我尝试将其应用于多标签问题时,我收到此警告: 用户
有几种算法可以构建决策树,例如 CART(分类和回归树)、ID3(迭代二分法 3)等 scikit-learn 默认使用哪种决策树算法? 当我查看一些决策树 python 脚本时,它神奇地生成了带有
有没有办法让 scikit-learn 中的 fit 方法有一个进度条? 是否可以包含自定义的类似 Pyprind 的内容? ? 最佳答案 如果您使用 verbose=1 初始化模型调用前 fit你应
我正在使用基于 rlglue 的 python-rl q 学习框架。 我的理解是,随着情节的发展,算法会收敛到一个最优策略(这是一个映射,说明在什么状态下采取什么行动)。 问题 1:这是否意味着经过若
我正在尝试使用 grisSearchCV 在 scikit-learn 中拟合一些模型,并且我想使用“一个标准错误”规则来选择最佳模型,即从分数在 1 以内的模型子集中选择最简约的模型最好成绩的标准误
我正在尝试离散数据以进行分类。它们的值是字符串,我将它们转换为数字 0,1,2,3。 这就是数据的样子(pandas 数据框)。我已将数据帧拆分为 dataLabel 和 dataFeatures L
每当我开始拥有更多的类(1000 或更多)时,MultinominalNB 就会变得非常慢并且需要 GB 的 RAM。对于所有支持 .partial_fit()(SGDClassifier、Perce
我需要使用感知器算法来研究一些非线性可分数据集的学习率和渐近误差。 为了做到这一点,我需要了解构造函数的一些参数。我花了很多时间在谷歌上搜索它们,但我仍然不太明白它们的作用或如何使用它们。 给我带来更
我知道作为功能 ordinal data could be assigned arbitrary numbers and OneHotEncoding could be done for catego
这是一个示例,其中有逐步的过程使系统学习并对输入数据进行分类。 它对给定的 5 个数据集域进行了正确分类。此外,它还对停用词进行分类。 例如 输入:docs_new = ['上帝就是爱', '什么在哪
我有一个 scikit-learn 模型,它简化了一点,如下所示: clf1 = RandomForestClassifier() clf1.fit(data_training, non_binary
我是一名优秀的程序员,十分优秀!