ID3算法 C++实现

思想:

用dfs每次都在前一次的基础上更新表,对于每层都判断是否是底层

(代码有点辣鸡qwq)

#include 

using namespace std;
typedef pairP;

const int INF=0x3f3f3f3f;
const int N=25,mod=32767;

string sep="     ";
vectornow[6],tmp[6],vec[6];
vectortype[6];
int vis[6];
string name[6]={" ","weather","temperature","humidity","windy"};

double cal(double a,double b){
    double c=a+b;
    if(c==a||c==b)return 0;
    double t1=log(a/c)/log(2);
    double t2=log(b/c)/log(2);
    return -(a/c)*t1-(b/c)*t2;
}

double Info(vectornow[6],int k){
    double res=0;
    for(int i=0;inow[6],vectortmp[6],int k,string s){
    for(int i=1;i<=5;i++)tmp[i].clear();
    for(int i=0;itmp[6],int u,string s){
    int c1=0,c2=0,tot=0;
    for(int i=0;inow[6],vectortmp[6]){
    for(int i=0;i>t;
    init();
    string s;
    for(int i=1;i<=t;i++){
        for(int j=1;j<=5;j++){
            cin>>s;
            now[j].push_back(s);
            tmp[j].push_back(s);
        }
    }

    int ans;
    double mi=INF;
    for(int i=1;i<5;i++){
        double c=Info(tmp,i);
        if(c

运行结果:

ID3算法 C++实现_第1张图片

你可能感兴趣的:(思维)