Assalamu’alaikum

Sebelumnya kita sudah membuat aplikasi Aplikasi forecasting peramalan penerimaan mahasiswa baru, Kali ini kita akan belajar bagaimana mengimplementasikan rumus dari teori pelajaran Data Mining dengan menggunakan bahasa pemrograman PHP dan database MySQL / MariaDB. Yang kita butuhkan adalah Web Server (XAMPP/LAMP), Text Editor (Atom/Sublime Text / Notepad++ / etc), & Web Browser (Google Chrome / Mozilla Firefox).

Disini saya mempunyai studi kasus “Peramalan Penerimaan Wisuda”. Langkah pertama kalian harus membuat databasenya dulu, disini saya menggunakan mysql sebagai databasenya.

Setelah membuat database, selanjutnya kita buat folder baru di htdocs dan download file tambahan, file ini bersifat opsional jika ingin tampilan aplikasi forecasting enak dipandang.

Download Assets

Extract dan copy ke dalam folder yang telah tadi dibuat, dan dibawah ini adalah hasil perhitungan di excel dan diaplikasi forecasting, di excel bertujuan untuk membuktikan apakah sama dengan aplikasi apa tidak.

pembuktian dengan excel

Langsung saja kita bikin aplikasinya, pertama bikin file dengan nama index.php file ini akan tampil pertama kali saat aplikasi dijalankan.

<!doctype html>
<html lang=''>
<head>
   <meta charset='utf-8'>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="assets/styles.css">
   <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
   <script src="script.js"></script>
   <title>Aplikasi Forecasting</title>
   <link rel="apple-touch-icon" href="images/favicon.png">
   <link rel="shortcut icon" href="images/favicon.png">

   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.0/css/flag-icon.min.css">
   <link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
   <link rel="stylesheet" href="assets/css/style.css">

   <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>

<div id='cssmenu'>
<ul>
   <li class='active'><a href='index.php'>Home</a></li>
   <li><a href='input.php'>Input wisuda</a></li>
   <li><a href='tampil.php'>Tampil wisuda</a></li>
   <li><a href='prediksi.php'>Prediksi</a></li>
</ul>
</div>

<div class="content">
          <div class="animated fadeIn">
              <div class="row">
                  <div class="col-lg-12">
                      <div class="card">
                          <div class="card-body">
                              <!-- Credit Card -->
                              <div id="hai">
                                  <div class="card-body">
                                      <div>
                                          <img src="images/umk.png" width="90px" height="90px" />
                                          <a href="https://www.kuycoding.com">
                                          <img src="images/favicon.png" width="90px" height="90px" align="right"/>
                                        </a>
                                        <div class="col-sm-12">
                                            <div class="page-header float-center">
                                                <div class="page-title">
                                                    <h1 class="text-sm-center">APLIKASI FORECASTING PERAMALAN WISUDA</h1>
                                                </div>
                                            </div>
                                        </div>
                                      </div>
                                      <hr>
                                      <div class="clearfix"></div>
                                        <center>
                                        <div class="col-md-6">
                                            <div class="card">
                                                <div class="card-header">
                                                    <strong class="card-title mb-3">Profil Mahasiswa</strong>
                                                </div>
                                                <div class="card-body">
                                                    <div class="mx-auto d-block">
                                                        <img class="rounded-circle rounded-circle mr-3" src="images/afif.jpg" alt="Card image cap">
                                                        <h4 class="text-sm-center mt-2 mb-1">Afif Nor Yusuf</h4>
                                                        <h5 class="text-sm-center"></h5>
                                                        <div class="location text-sm-center">Teknik Informatika</div>
                                                        <p></p>
                                                        <a href="https://www.kuycoding.com">
                                                          <!--halaman web jangan dihapus hargai pembuat-->
                                                        <h5 class="text-sm-center mt-2 mb-1">WWW.KUYCODING.COM</h5>
                                                      </a>
                                                        <div class="location text-sm-center"><i class="fa fa-map-marker"></i> Mayong Lor, RT03/RW05, Mayong, Jepara</div>
                                                    </div>
                                                    <hr>
                                                    <div class="card-text text-sm-center">
                                                        <a href="http://facebook.com/afiftwrp"><i class="fa fa-facebook pr-1"></i></a>
                                                        <a href="https://kuycoding.com"><i class="fa fa-globe pr-1"></i></a>
                                                        <a href="http://instagram.com/afif_ny"><i class="fa fa-instagram pr-1"></i></a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        </center>
                                      </hr>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="clearfix"></div>
                      <?php include "assets/footer.php" ?>
</body>
<html>

Selanjutnya membuat file koneksi.php bertujuan untuk menghubungkan aplikasi dengan database

<?php

   ob_start();
   $koneksi;
   $namaserver=	" localhost";
   $username	= "root";
   $password	= "";
   $namadb	= "forecasting";

   $koneksi	=	mysqli_connect($namaserver,$username,$password,$namadb);
   if(!$koneksi) {
      die("Maaf, Koneksi Gagal:".mysqli_connect_error());
   }

?>

form input.php file ini untuk memasukan data yang telah diinputkan dan disimpan di dalam database

<!doctype html>
<html lang=''>
<head>
   <meta charset='utf-8'>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="assets/styles.css">
   <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
   <script src="script.js"></script>
   <title>Aplikasi Forecasting</title>
   <link rel="apple-touch-icon" href="images/favicon.png">
   <link rel="shortcut icon" href="images/favicon.png">

   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.0/css/flag-icon.min.css">
   <link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
   <link rel="stylesheet" href="assets/css/style.css">

   <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>

<div id='cssmenu'>
<ul>
   <li><a href='index.php'>Home</a></li>
   <li class='active'><a href='input.php'>Input wisuda</a></li>
   <li><a href='tampil.php'>Tampil wisuda</a></li>
   <li><a href='prediksi.php'>Prediksi</a></li>
</ul>
</div>
<div class="content">
          <div class="animated fadeIn">
            <div class="row">
                  <div class="col-lg-12">
                      <div class="card">
                          <div class="card-header">
                              <strong class="card-title">Input Data</strong>
                          </div>
                          <div class="card-body">
                              <!-- Credit Card -->
                              <div id="pay-invoice">
                                  <div class="card-body">
                                      <div class="card-title">
                                          <h3 class="text-center">Input Prediksi Wisuda</h3>
                                      </div>
                                      <hr>
                                      <form action="simpan.php" method="post">
                                          <div class="form-group text-center">
                                          </div>
                                          <div class="form-group">
                                            <label for="periode_wisuda" class="control-label mb-1">Periode Wisuda</label>
                                            <select name="periode_wisuda" id="periode_wisuda" class="form-control">
                                              <?php
                                              $now = date('Y');
                                              for ($i = $now; $i >= 2000; $i--) {
                                                echo "<option value='".$i."/".($i+1)."'>".$i."/".($i+1)."</option>"
                                                ;
                                              }
                                              ?>
                                            </select>
                                          </div>
                                          <div class="form-group">
                                            <label>Jumlah Wisuda</label>
                                            <input id="jumlah_wisuda" name="jumlah_wisuda" type="number" class="form-control" value="">
                                          </div>
                                          <div class="form-actions form-group">
                                            <button type="submit" name="simpan" class="btn btn-primary btn-sm">Simpan</button>
                                          </div>
                                        </form>
                                      </hr>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
        <div class="clearfix"></div>
        <?php include "assets/footer.php" ?>
</body>
<html>

file simpan.php untuk melakukan penyimpanan terhadap data yang dimasukkan dalam form input ke dalam database.

<?php
include "koneksi.php";
if(isset($_POST['simpan'])) {
  $periode_wisuda = $_POST['periode_wisuda'];
  $jumlah_wisuda = $_POST['jumlah_wisuda'];
  $sql = @mysqli_query($koneksi, "INSERT INTO wisuda VALUES ('$kode_wisuda','$periode_wisuda','$jumlah_wisuda')") or
    die(mysqli_error($koneksi));
  if($koneksi) {
    echo "<script>alert('Berhasil menambahkan data'); window.location='/wisuda_forecasting/input.php';</script>";
  }
}
?>

tampil.php file ini bertujuan untuk menampilkan data yang ada pada database

<!doctype html>
<html lang=''>
<head>
   <meta charset='utf-8'>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="assets/styles.css">
   <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
   <script src="script.js"></script>
   <title>Aplikasi Forecasting</title>
   <link rel="apple-touch-icon" href="images/favicon.png">
   <link rel="shortcut icon" href="images/favicon.png">

   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.0/css/flag-icon.min.css">
   <link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
   <link rel="stylesheet" href="assets/css/style.css">

   <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>

<div id='cssmenu'>
<ul>
   <li><a href='index.php'>Home</a></li>
   <li><a href='input.php'>Input wisuda</a></li>
   <li class='active'><a href='tampil.php'>Tampil wisuda</a></li>
   <li><a href='prediksi.php'>Prediksi</a></li>
</ul>
</div>
<div class="content">
  <div class="animated fadeIn">
    <div class="rows">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-header">
            <strong class="card-title">Tampil Data</strong>
          </div>
          <div class="panel-body">
            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                      <th width="27">NO</th>
                                    	<th width="200">Periode_Wisuda</th>
                                    	<th width="60" align="right">Data</th>
                                    	<th width="40" align="right">X</th>
                                    	<th width="40" align="right">Y</th>
                                    	<th width="40" align="right">XX</th>
                                    	<th width="40" align="right">XY</th>
                                    </tr>
                                </thead>
                                <tbody>
                                  <?php
                                    $con=mysqli_connect("localhost","root","","forecasting");
                                        if (mysqli_connect_errno()) {
                                            throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
                                        };
                                      $sql = mysqli_query($con, "SELECT * FROM wisuda") or die (mysqli_error($con));
                                    //  if (mysqli_num_error($sql) > 0) {
                                        // code...
                                        {
                                        $x = 0;
                                        $jumlah_x = 0;
                                        $jumlah_y = 0;
                                        $jumlah_xx = 0;
                                        $jumlah_xy = 0;
                                        while ($data = mysqli_fetch_array($sql)) {
                                              $jumlah_x += $x;
                                              $jumlah_y += $data['jumlah_wisuda'];
                                              $jumlah_xx += ($x * $x);
                                              $jumlah_xy += ($x * $data['jumlah_wisuda']);
                                            ?>
                                            <tr>
                                              <td><?=$x+1;?>.</td>
                                              <td><?=$data['periode_wisuda'];?></td>
                                              <td align="left"><?=$data['jumlah_wisuda'];?></td>
                                              <td align="left"><?=$x;?></td>
                                              <td align="left"><?=$data['jumlah_wisuda'];?></td>
                                              <td align="left"><?=$x * $x;?></td>
                                              <td align="left"><?=$x * $data['jumlah_wisuda'];?></td>
                                            </tr>
                                            <?php
                                            $x++;
                                          }
                                          ?>
                                          <tr>
                                            <td colspan="2">Jumlah</td>
                                            <td></td>
                                            <td><?=$jumlah_x;?></td>
                                            <td><?=$jumlah_y;?></td>
                                            <td><?=$jumlah_xx;?></td>
                                            <td><?=$jumlah_xy;?></td>
                                          </tr>
                                          <tr>
                                            <td colspan="2">Rata2</td>
                                            <td></td>
                                            <td>
                                              <?php
                                              $rata2_x = $jumlah_x / $x;
                                              echo $rata2_x;
                                              ?>
                                            </td>
                                            <td>
                                              <?php
                                              $rata2_y = $jumlah_y / $x;
                                              echo $rata2_y;
                                              ?>
                                            </td>
                                            <td colspan="2"></td>
                                          </tr>
                                          <tr>
                                            <td colspan="2">B1</td>
                                            <td colspan="6">
                                              <?php
                                              $b1 = ($jumlah_xy - (($jumlah_x * $jumlah_y) / $x)) / ($jumlah_xx - ($jumlah_x * $jumlah_x) / $x);
                                              echo $b1;
                                              ?>
                                            </td>
                                          </tr>
                                          <tr>
                                            <td colspan="2">B0</td>
                                              <td colspan="6">
                                                <?php
                                                $b0 = $rata2_y - $b1 * $rata2_x;
                                                echo $b0;
                                                ?>
                                              </td>
                                            </tr>
                                            <?php
                                          }
                                          ?>

                                </tbody>
                            </table>
                            <div>
                              Rumus Regresi Linier :<br>
                              <?php
                              $y = $b0." + ".$b1." x";
                              echo $y;
                              ?>
                            </div>
                            <?php
                            if (isset($_POST['prediksi'])) {
                              $periode_pmb = $_POST['periode_wisuda'];
                              $thn = ($x - 1) + $periode_pmb;
                              $prediksi = $b0 + ($b1 * $thn);
                              ?>
                              <div>
                                Prediksi PMB untuk <?=$periode_pmb;?> tahun berikunya adalah <?=$prediksi;?>
                              </div>
                              <?php
                            }
                            ?>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            <div class="clearfix"></div>
          <?php include "assets/footer.php" ?>
</body>
<html>

prediksi.php file ini  berfungsi untuk melakukan prediksi dari data yang ada didatabase.

<!doctype html>
<html lang=''>
<head>
   <meta charset='utf-8'>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="assets/styles.css">
   <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
   <script src="script.js"></script>
   <title>Aplikasi Forecasting</title>
   <link rel="apple-touch-icon" href="images/favicon.png">
   <link rel="shortcut icon" href="images/favicon.png">

   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css">
   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.0/css/flag-icon.min.css">
   <link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
   <link rel="stylesheet" href="assets/css/style.css">

   <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>

<div id='cssmenu'>
<ul>
   <li><a href='index.php'>Home</a></li>
   <li><a href='input.php'>Input wisuda</a></li>
   <li><a href='tampil.php'>Tampil wisuda</a></li>
   <li class='active'><a href='prediksi.php'>Prediksi</a></li>
</ul>
</div>
<div class="content">
        <div class="animated fadeIn">
          <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <strong class="card-title">Prediksi</strong>
                        </div>
                        <div class="card-body">
                          <!-- Credit Card -->
                          <div id="prediksi">
                              <div class="card-body">
                      <form id="form1" name="form1" action="tampil.php" method="post">
                        Peramalan wisuda untuk
                        <select name="periode_wisuda" required>
                          <?php
                          for ($i=1; $i <=10 ; $i++) {
                            // code...
                            echo "<option value='$i'>$i</option>";
                          }
                           ?>
                         </select>
                         Tahun akademik berikutnya <input type="submit" name="prediksi" id="prediksi"class="btn btn-primary btn-sm" value="Prediksi"/>
                      </form>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="clearfix"></div>
      <?php include "assets/footer.php" ?>
</body>
<html>

Tampilan hampir sama dengan penerimaan mahasiswa baru, silahkan cek postingan sebelumnya.

[artikel number=1 tag=”peramalan” ]

Script saya diatas sudah menggunakan mysqli extension, bukan mysql extension yang lama. Jadi support di PHP versi 5 ataupun 7.

Jika masih ada error coba sesuaikan sama persis dengan script diatas dulu, diteliti lagi. Kalo udah paham silakan diedit sesuka hati sesuai kebutuhan.

Semoga bermanfaat. Happy coding 

Wassalamu’alaikum wr. wb.

LEAVE A REPLY

Please enter your comment!
Please enter your name here