gpt4 book ai didi

machine-learning - 用于数值转换的机器学习

转载 作者:行者123 更新时间:2023-11-30 09:29:15 25 4
gpt4 key购买 nike

我有一个大小为 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_CLASSSIGMA

编辑:

正如您现在提供的数据一样,很明显我的假设不成立。请参阅此代码完成的以下绘图(文件已从 []() 中删除;人们确实应该发布 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()

剧情:

enter image description here

现在只要考虑观察一些x,您就需要决定y。对于大多数x范围来说相当困难。

显然还存在类平衡问题,它解释了大多数预测的第 14 类的输出。

关于machine-learning - 用于数值转换的机器学习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42772637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com