该算法是概念空间挖掘最简单的算法,只考虑了正实例,不断做泛化,实际上求得了一个最特化边界
概念挖掘需求
C++实现
#include <iostream> #include <string> using namespace std; #define MAXTRAIN 4 #define MAXLEN 7 int main(){ int i, j; string state[MAXTRAIN][MAXLEN]; string concept[MAXLEN]; string yes("Yes"); for( i = 0; i < MAXTRAIN; i++){ for( j = 0;j < MAXLEN; j++){ cin>>state[i][j]; } } for( j = 1;j < MAXLEN; j++){ concept[j] = state[0][j]; } for( i = 1; i < MAXTRAIN; i++){ if(state[i][MAXLEN-1].compare(yes) == 0){ for( j = 1;j < MAXLEN-1; j++){ if(state[i][j].compare(concept[j]) != 0){ concept[j] = "?"; } } } } cout<<"the concept is:"; for( j = 1;j < MAXLEN-1; j++){ cout<<concept[j]<<" "; } return 0;
}
测试数据
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 ? Strong ?