<?php
    error_reporting(E_ALL ^ E_NOTICE);
    set_time_limit(0);

    $hd = mysql_connect("localhost", "root", "")
          or die ("Unable to connect");

    mysql_select_db ("movie", $hd)
          or die ("Unable to select database");

    $res0 = mysql_query("SELECT * FROM users", $hd)
           or die ("Unable to run query");
    $count_users = mysql_num_rows($res0);

    $res1 = mysql_query("SELECT * FROM movies", $hd)
           or die ("Unable to run query");
    $count_movies = mysql_num_rows($res1);

    $movieid_array = array();

    for ($i = 1; $i <= $count_users; $i++) {
        $res = mysql_query("SELECT movieid FROM ratings WHERE userid = $i", $hd)
               or die ("Unable to run query");

        $mid = array();
        while ($row = mysql_fetch_assoc($res)) {
            $data = $row["movieid"];
            array_push($mid, $data);
            //echo "$data ";
        }
        array_push($movieid_array, $mid);
        //echo "<br>";
    }

    function array_icount_values($arr) { 
        $arr2=array(); 
            if(!is_array($arr['0'])){$arr=array($arr);} 
                foreach($arr as $k=> $v){ 
                    foreach($v as $v2){ 
                        if(!isset($arr2[$v2])){ 
                            $arr2[$v2]=1; 
                        }else{ 
                            $arr2[$v2]++;
                        }
                    }
                }
        return $arr2;
    }

    $count_arr = array_icount_values ($movieid_array);
    //print_r($count_arr);

    $fis = array();
    for ($i = 1; $i <= $count_movies; $i++) {
        if (($count_arr[$i]/$count_movies) > 0.1) { // minSupport is 0.1
            array_push($fis, $i);
        }
    }
?>

I am trying to apply apriori algo to a movie rating dataset so that I can get association rules between movies ....
In array $fis the set of single frequent items is stored!
I want the list of set with two items and then, three items, that are frequent .....
How should I proceed ?
Please help!

Member Avatar for diafol

Could you elaborate further? I'm a bit slow on the uptake here. You want to list array items that themselves have multiple items? I'm not familiar with the algo. I know it's used for setting rules, but I've never used it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.