贝叶斯模型预测值及其误差获取

2024-04-25 11:57:40 发布

您现在位置:Python中文网/ 问答频道 /正文

Dataset file我使用python中的贝叶斯模型预测没有人的价值观。我正在使用图片中给出的数据集。我的错误也附在图片Dataset sampleError in prediction

#My code is here 
import numpy as np
from pgmpy.models import BayesianModel
import pandas as pd
data = pd.read_csv('C:/Users/hp/Desktop/file3.csv')
train = data[:40]
test = data[40:].drop('no_of_people', axis=1)
restaurant_model = BayesianModel(
[('location', 'cost'),
('quality', 'cost'),
('location', 'no_of_people'),
('cost', 'no_of_people')])
restaurant_model.fit(train)
restaurant_model.get_cpds()
restaurant_model.predict(test).values.ravel()

请帮我解决这个问题。我怎样才能完美地预测这些值呢


Tags: ofcsvnotestimportdatamodelas