帮助,我的代码中出现错误“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
. 希望你能理解。
互换的青春
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;
}
- 2 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消