GaussianNB 不是基于直方图类的正确模型?

问题描述 投票:0回答:2

我有一个包含 1140 列的 Excel 文件 A:AQV。每个都有 31 行,数字介于 0 和 1 之间。这些可以显示为直方图。无论曲线看起来好、中等还是坏,A:AQV 中的另一行包含类 (0,1,4)。

我希望 AI 模型通过查看每列中从 0 到 1 的 31 个值来预测类别 (0, 1, 4)。

这是我的代码:

import pandas as pd
from pandas import *
import numpy as np
import glob
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score

path = 'C:/Users/user/Desktop/JupyterNB/train.xlsx'
dfs = []
df = []
y = []

for f in glob.glob(path):
    dfs.append(pd.read_excel(f, skiprows=2, usecols='A:AQV', nrows=31))
    L = [(x-np.min(x))/(np.max(x)-np.min(x)) for x in dfs]
df = pd.concat(L, ignore_index=True, axis=1)

y = [pd.read_excel(path, usecols='A:AQV', skiprows=80, nrows=1)]
y_char = pd.concat(y, ignore_index=True, axis=1)

y_char = y_char.T
df = df.T

x_train, x_test, y_train, y_test = train_test_split(df, y_char, test_size=0.33, random_state=38)
clf = GaussianNB()
model = clf.fit(x_train, y_train)
preds = clf.predict(x_test)
print(preds)

print(accuracy_score(y_test, preds))

遗憾的是我无法达到 60% 或更高的准确率。我很确定我在这个 excel 文件中的分类非常合适。还有其他原因我不能超过 60% 吗?也许该模型不适合我的问题?或者它没有足够的数据?

python scikit-learn naivebayes
2个回答
-1
投票

我真的不知道你的数据,但即使有 10000 行也不足以正确训练模型。而且你已经有太多列了。你能以某种方式通过使用领域知识来减少你的专栏吗?或者您是否尝试过任何其他型号来检查 NB 是否是坏的。


-1
投票

实际上我用 keras 的 Sequential() 模型试过了。理解模型要容易得多。我的图层是 64-relu 和 31 input_shape、32-relu、16-relu 和 3-softmax。有了 1000 个纪元,我得到了 98-99% 的准确率。所以我认为 naive_bayes GaussianNB() 不是适合我的问题的最佳模型。

数据实际上是 31 个值(每个值从 0-1)和 1140 个数据集上的标签(0,1,4)。

© www.soinside.com 2019 - 2024. All rights reserved.