SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    keys and values is not match when combine?

    I'm installing apriori algorithm. I want to take 1-itemset but when I combine array, the result is not exactly (before and after combine, the result is not match). Here is my code:

    PHP Code:
    <?php
        $transactions 
    = array(
            array(
    'A' => 1'B' => 0'C' => 1'D' => 1'E' => 0),
            array(
    'A' => 0'B' => 1'C' => 1'D' => 0'E' => 1),
            array(
    'A' => 1'B' => 1'C' => 1'D' => 0'E' => 1),
            array(
    'A' => 0'B' => 1'C' => 0'D' => 0'E' => 1)
        );
        
        
    // take keys of $transactions and add into $items
        
    while(list($key)=each($transactions[1])){
            
    $items[] = $key;
        }
            
        
    // count quantity of each item in $items
        
    for($i=0$i<count($transactions); $i++){
            for(
    $j=0$j<count($items); $j++){
                if(
    $transactions[$i][$items[$j]]==1){
                    
    $support[$j]++;
                }
            }
        }
        
        echo 
    'Before combine:  (I want to the result like this)<br />';
        for(
    $i=0$i<count($support); $i++){
            echo 
    $support[$i],'-',$items[$i];
            echo 
    '<br />';
        }
        
        
    $itemset1 array_combine($items$support);
        echo 
    '<br />';
        
        echo 
    'After combine: <br />';    
        while(list(
    $key$value)=each($itemset1)){
            echo 
    $key,'-',$value;
            echo 
    '<br />';
        }
    ?>
    Before combine (I want to the result like this):
    A-2
    B-3
    C-3
    D-1
    E-3

    After combine:
    A-2
    B-3
    C-1
    D-3
    E-3
    Please help me! Thank a lot!

  2. #2
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I have done it. Thank for watching!

    PHP Code:
        // take keys of $transactions and add into $items 
        
    while(list($key)=each($transactions[1])){
            
    $items[] = $key;
        }
            
        
    // count quantity of each item in $items
        
    for($i=0$i<count($transactions); $i++){
            for(
    $j=0$j<count($items); $j++){
                if(
    $transactions[$i][$items[$j]]==1){
                    
    $support[$items[$j]]++;
                }
            }
        } 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •