为了账号安全,请及时绑定邮箱和手机立即绑定

ErrorException(E_NOTICE)未定义变量:actualLabels

ErrorException(E_NOTICE)未定义变量:actualLabels

PHP
弑天下 2022-06-17 17:08:58
帮助,我的代码中出现错误“ErrorException (E_NOTICE) Undefined variable: actualLabels”$title = "Data Confusion Matrix";$testing_data = DataTesting::count();$klasifikasi = Klasifikasi::with('sentimen')->get();foreach($klasifikasi as $kelas){    $predictedLabels[] = $kelas->sentimen->kategori;    $testing = DataTesting::where('id_testing',$kelas->id_testing)->first();    $twitter = TwitterStream::with('sentimen')->where('id_crawling',$testing->id_crawling)->first();    $actualLabels[] = $twitter->sentimen->kategori; } $getPrecision = new ControllerConfusionMatrix($actualLabels, $predictedLabels); $accuracy = ControllerConfusionMatrix::score($actualLabels, $predictedLabels); $recall = $getPrecision->getRecall(); $precision = $getPrecision->getPrecision();
查看完整描述

2 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

将此行添加到代码的开头:$actualLabels = []; 您收到错误,因为当$klasifikasi为空时,则不会执行循环内的语句。所以$actualLabels没有创建变量。在这种情况下,您会得到(E_NOTICE) Undefined variable: actualLabels. 希望你能理解。



查看完整回答
反对 回复 2022-06-17
?
互换的青春

TA贡献1797条经验 获得超6个赞

定义Array()


$predictedLabels = array();

$actualLabels = array();

            foreach($klasifikasi as $kelas){

                $predictedLabels[] = $kelas->sentimen->kategori;

                $testing = DataTesting::where('id_testing',$kelas->id_testing)->first();

                $twitter = TwitterStream::with('sentimen')->where('id_crawling',$testing->id_crawling)->first();

                $actualLabels[] = $twitter->sentimen->kategori;

            }


查看完整回答
反对 回复 2022-06-17
  • 2 回答
  • 0 关注
  • 171 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信