Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $periode=isset($_GET['period'])?$_GET['period']:3;
- $data=array(
- array('2201','1618'),
- array('2202','1625'),
- array('2203','1643'),
- array('2204','1661'),
- array('2205','1678'),
- array('2206','1740'),
- array('2207','1746'),
- array('2208','1749'),
- array('2209','1757'),
- array('2210','1793'),
- array('2211','1810'),
- array('2212','1865'),
- );
- ?>
- <html>
- <head>
- <title>Weighted Metode Moving Average</title>
- <style>
- td,th {padding:5px;border: solid 1px #333;}
- </style>
- </head>
- <body>
- <table>
- <caption>Weighted Metode Moving Average (period= <select name='period' onChange='ubah(this.value);'>
- <?php
- for($i=1;$i<10;$i++){
- echo "<option value='{$i}'".($i==$periode?' selected':'').">{$i}</option>";
- }
- ?>
- </select>)</caption>
- <tr><th>bulan</th><th>penjualan(y)</th><th>prediksi(x)</th>
- <th>MAPE |(y-x)/y|</th>
- <th>MAD |(y-x)|</th>
- <th>MSE (y-x)<sup>2</th>
- </tr>
- <?php
- $prediksi=$mape=$mad=array();
- $panjang_data=count($data);
- for($i=$periode;$i<$panjang_data;$i++){
- $pembagi=0;
- $jml=0;
- for($j=$i-$periode;$j<$i;$j++){
- $jml+=$data[$j][1]*($j-($i-$periode)+1);
- $pembagi+=($j-($i-$periode)+1);
- }
- $prediksi[$data[$i][0]]=$jml/$pembagi;
- $mape[$data[$i][0]]=abs(($prediksi[$data[$i][0]]-$data[$i][1])/$prediksi[$data[$i][0]]);
- $mad[$data[$i][0]]=abs($prediksi[$data[$i][0]]-$data[$i][1]);
- $mse[$data[$i][0]]=pow($mad[$data[$i][0]],2);
- }
- foreach($data as $k=>$v){
- echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td>"
- ."<td>".($k<$periode?"-":round($prediksi[$v[0]],4))."</td>"
- ."<td>".($k<$periode?"-":round($mape[$v[0]],4))."</td>"
- ."<td>".($k<$periode?"-":round($mad[$v[0]],4))."</td>"
- ."<td>".($k<$periode?"-":round($mse[$v[0]],4))."</td>"
- ."</tr>";
- }
- $total_mape=round(array_sum($mape),4);
- $total_mad =round(array_sum($mad),4);
- $total_mse =round(array_sum($mse),4);
- $jml_mape=count($mape);
- $jml_mad=count($mad);
- $jml_mse=count($mse);
- $hasil_mape=round($total_mape/$jml_mape*100,4);
- $hasil_mad =round($total_mad/$jml_mad,4);
- $hasil_mse =round($total_mse/$jml_mse,4);
- echo "<tr><th colspan='3'>Total</th><th>{$total_mape}</th><th>{$total_mad}</th><th>{$total_mse}</th></tr>";
- echo "<tr><th colspan='3'>Jumlah Data</th><th>{$jml_mape}</th><th>{$jml_mad}</th><th>{$jml_mse}</th></tr>";
- echo "<tr><th colspan='3'>Hasil</th><th>{$hasil_mape} %</th><th>{$hasil_mad}</th><th>{$hasil_mse}</th></tr>";
- ?>
- </table>
- <p>
- <b>MAPE</b> = <i>Mean Absolute Percent Error</i><br />
- <b>MAD</b> = <i>Mean Absolute Deviation</i><br />
- <b>MSE</b> = <i>Mean Squared Error</i>
- </p>
- <script>
- function ubah(nilai){
- location.href='?period='+nilai;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement