Find-S:寻找极大特殊假设_Java实现

算法描述:

算法说明:该算法是概念空间挖掘最简单的算法,只考虑了正实例,不断做泛化,实际上求得了一个最特化边界

算法实现:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FindS {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        int maxTrain = 4;
        int maxLen = 7;
        int i = 0;
        String temp = null;
        String yes = new String("Yes");
        String[][] state = new String[maxTrain][maxLen];
        String[] concept = new String[maxLen];
        FileReader fr = new FileReader("e:\\workspace\\train.txt");
        BufferedReader br = new BufferedReader(fr);
        while((temp = br.readLine()) != null && i < 4){
            state[i] = temp.split(" ");
            i++;

        }
        for(int j = 1; j < maxLen; j++){
            concept[j] = state[0][j];
        }
        for(i = 1; i < maxTrain; i++){
            if(state[i][maxLen-1].equals(yes)){
                for(int k = 1; k < maxLen-1; k++){
                    if(!state[i][k].equals(concept[k])){
                        concept[k] = "?";
                    }
                }
            }
        }
        System.out.print("The concept is : ");
        for(i = 1; i < maxLen - 1; i++){
            System.out.print(concept[i] + " ");
        }
        br.close();
        return;
    }
}
预测数据:

1 Sunny Warm Normal Strong Warm Yes  
2 Sunny Warm High Strong Warm Yes  
3 Rainy Cold High Strong Warm No  
4 Sunny Warm High Strong Cool Yes

运行结果:

The concept is : Sunny Warm High Strong ? 

 

posted @ 2014-04-06 00:05  Bleachzk  阅读(393)  评论(0编辑  收藏  举报