Beispiel #1
0
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
	<title>Apriori Alghoritm</title>
</head>
<body style="font-family: monospace;">
<pre>
<?php 
include 'Apriori.php';
$Apriori = new Apriori();
$Apriori->setMaxScan(3);
$Apriori->setMinSup(2);
$Apriori->setMinConf(100);
$Apriori->setDelimiter(',');
$Apriori->process('fichier.txt');
//Frequent Itemsets
echo '<h1>Frequent Itemsets</h1>';
$Apriori->printFreqItemsets();
echo '<h3>Frequent Itemsets Array</h3>';
print_r($Apriori->getFreqItemsets());
//Association Rules
echo '<h1>Association Rules</h1>';
$Apriori->printAssociationRules();
echo '<h3>Association Rules Array</h3>';
print_r($Apriori->getAssociationRules());
//Sauvegarde dans les fichiers
$Apriori->saveFreqItemsets('freqItemsets.txt');
$Apriori->saveAssociationRules('associationRules.txt');
?>
</pre>
</body>
</html>
Beispiel #2
0
if ($conn) {
    if (mysql_select_db('olx', $conn)) {
        $result = mysql_query("SELECT age,gender,salary,pid FROM user,cart,products WHERE pid=id and user_id=uid", $conn);
        if (!mysql_num_rows($result)) {
            $err = 'No product available';
        }
        $results = array();
        while ($res = mysql_fetch_assoc($result)) {
            $res['age'] = get_age_range($res['age']);
            $res['salary'] = get_salary_range($res['salary']);
            $res['gender'] = 'gender-' . $res['gender'];
            $r = array($res['age'], $res['salary'], $res['gender'], $res['pid']);
            $results[] = implode(", ", $r);
        }
        $Apriori->process($results);
        $rules = $Apriori->getAssociationRules();
        //$Apriori->saveFreqItemsets('freqItemsets.txt');
        //$Apriori->saveAssociationRules('associationRules.txt');
        //printInterestingRules($rules);
        $rec_products = array();
        foreach ($rules as $lhs => $rhs_list) {
            foreach ($rhs_list as $rhs_key => $rhs_conf) {
                if (is_int($rhs_key)) {
                    $str = $lhs . '=>' . $rhs_key . '<br>';
                    //echo '<b> Rule - '.$str.'</b>';
                    if (isSatisfied(explode(',', $lhs))) {
                        $rec_products[] = $rhs_key;
                    }
                    //print_r(explode(',',$lhs));
                    //echo $str;
                }