package CQU.EDU.yu.cn;
import java.rmi.server.LogStream;
import java.util.ArrayList;
public class Deal_with_result {
private ArrayList<Record> total_record_table=null;
public ArrayList<Record> construct_decision_table=null;
public ArrayList<Record> record_need_for_decision=null;
private ArrayList entropy_array=new ArrayList ();
private ArrayList temp_entropy_array=new ArrayList ();
private ArrayList track_tag=new ArrayList();
private ArrayList decision_table_array=new ArrayList();
private int classify_column_number=4;//need for change in the special application;
private int yes_count=0;
private int no_count=0;
private int sum_count=0;
private double entropy=0;
private int count_of_column=4;
private int construct_decision_tree_dataset_row=0;
private ArrayList tag_array=new ArrayList();
public static String dataset_infor[][]={
{"Sunny","Hot","High","Weak","No"},
{"Sunny","Hot","High","Strong","No"},
{"Overcast","Hot","High","Weak","Yes"},
{"Rain","Mild","High","Weak","Yes"},
{"Rain","Cool","Normal","Weak","Yes"},
{"Rain","Cool","Normal","Strong","No"},
{"Overcast","Cool","Normal","Strong","Yes"},
{"Sunny","Mild","High","Weak","No"},
{"Sunny","Cool","Normal","Weak","Yes"},
{"Rain","Mild","Normal","Weak","Yes"},
{"Sunny","Mild","Normal","Strong","Yes"},
{"Overcast","Mild","High","Strong","Yes"},
{"Overcast","Hot","Normal","Weak","Yes"},
{"Rain","Mild","High","Strong","No"},
{"Rain","Cool","High","Weak","null"},
{"Sunny","Mild","High","Strong","null"},
{"Sunny","Hot","Normal","Strong","null"},
{"Sunny","Cool","Normal","Strong","null"},
{"Rain","Cool","High","Strong","null"},
{"Rain","Mild","Normal","Strong","null"},
};
public Deal_with_result(){
total_record_table=new ArrayList<Record>();
construct_decision_table=new ArrayList<Record>();
record_need_for_decision=new ArrayList<Record>();
int column_length=dataset_infor[0].length;
for(int row=0;row<dataset_infor.length;++row){
Record temp_record=new Record();
for(int column=0;column<column_length;++column){
temp_record.record.add(dataset_infor[row][column]);
}
total_record_table.add(temp_record);
}
}
public ArrayList<Record> Get_construct_decision_table(){
return this.construct_decision_table;
}
public ArrayList Get_decision_table_array(){
return this.decision_table_array;
}
public ArrayList<Record> Get_record_need_for_decision(){
return this.record_need_for_decision;
}
public int Get_construct_decision_tree_dataset_row(){
return this.construct_decision_tree_dataset_row;
}
public void Distinct_decision_record(){
for(int i=0;i<total_record_table.size();++i){
// construct decision table
if(total_record_table.get(i).record.get(classify_column_number).toString().equals("null")){
record_need_for_decision.add(total_record_table.get(i));
}
else{
construct_decision_table.add(total_record_table.get(i));
}
}
construct_decision_tree_dataset_row=construct_decision_table.size();
}
public void Distinct_tag_classify(ArrayList<Record> varial_array){
this.sum_count=varial_array.size();
for(int i=0;i<this.sum_count;++i){
if(varial_array.get(i).record.get(classify_column_number).toString().equals("Yes")){
++yes_count;
}
else{
++no_count;
}
}
}
public void Logic_deal_with(ArrayList<Record> varial_array,int sub_tag){
int temp_sum_count= varial_array.size();
ArrayList<Record> element_same_array=new ArrayList<Record>();
while(varial_array.size()!=0){//1
String temp_element= varial_array.get(0).record.get(sub_tag).toString();
for(int i=0;i<varial_array.size();++i){//2
if(temp_element.equals(varial_array.get(i).record.get(sub_tag).toString())){
element_same_array.add(varial_array.get(i));
varial_array.remove(i);
--i;
}
}//2
this.yes_count=0;
this.no_count=0;
this.sum_count=0;
Distinct_tag_classify(element_same_array);
double x=(double)this.yes_count/this.sum_count;
double y=(double)this.no_count/this.sum_count;
if(x==0||y==0){
this.entropy=0;
}
else{
double percent=(double)this.sum_count/temp_sum_count;
this.entropy=percent*(-(x)*(Math.log10(x)/Math.log10(2))-(y)*(Math.log10(y)/Math.log10(2)));
}
temp_entropy_array.add(this.entropy);
element_same_array.removeAll( element_same_array );
}//1
//Get the Entropy of one Column
try{
double column_entropy=Double.parseDouble( temp_entropy_array.get(0).toString());
for(int i=1;i< temp_entropy_array.size();++i){
column_entropy-=Double.parseDouble( temp_entropy_array.get(i).toString());
}
this.entropy_array.add(sub_tag);
this.entropy_array.add(column_entropy);
this.temp_entropy_array.removeAll(temp_entropy_array);
}
catch(Exception e){
System.out.println("TTT");
System.exit(1);
}
}
public void Product_decision_table(ArrayList<Record> varial_array){
//求取最重要的列属性
for(int i=0;i<this.count_of_column;++i){//1
boolean is_different=true;
for(int j=0;is_different&&j<this.tag_array.size();++j){//2
if(i==Integer.parseInt(this.tag_array.get(j).toString())){
is_different=false;
}
}//2
//
if(is_different){
this.yes_count=0;
this.no_count=0;
this.sum_count=0;
Distinct_tag_classify( varial_array);
double x=(double)this.yes_count/this.sum_count;
double y=(double)this.no_count/this.sum_count;
if(x==0||y==0){
this.temp_entropy_array.add(0);
}
else{
this.entropy=(-(x)*(Math.log10(x)/Math.log10(2))-(y)*(Math.log10(y)/Math.log10(2)));
this.temp_entropy_array.add(this.entropy);
}
ArrayList<Record> destinate_array=new ArrayList<Record>();
Copy_array(varial_array, destinate_array);
Logic_deal_with( destinate_array, i);
}
}//1
//Get the Maxmum Entropy in all columns
double temp_value=0.0;//Double.parseDouble(this.entropy_array.get(1).toString());
int temp_index=0;
for(int i=1;i<this.entropy_array.size();i+=2){
if(temp_value<=Double.parseDouble(this.entropy_array.get(i).toString())){
temp_value=Double.parseDouble(this.entropy_array.get(i).toString());
temp_index=i;
}
}
int real_important_index=Integer.parseInt(this.entropy_array.get(temp_index-1).toString());
this.entropy_array.removeAll(this.entropy_array);
this.decision_table_array.add(real_important_index);
this.track_tag.add(real_important_index);
/*
*
*/
Important_column_deal_with(varial_array,real_important_index);
}
//copy array
public void Copy_array(ArrayList<Record>source_array,ArrayList<Record>destinate_array){
for(int i=0;i<source_array.size();++i){
destinate_array.add(source_array.get(i));
}
}
public void Important_column_deal_with(ArrayList<Record> varial_array,int sub_tag){
int temp_sum_count= varial_array.size();
ArrayList<Record> element_same_array=new ArrayList<Record>();
while(varial_array.size()!=0){//1
String temp_element= varial_array.get(0).record.get(sub_tag).toString();
for(int i=0;i<varial_array.size();++i){//2
if(temp_element.equals(varial_array.get(i).record.get(sub_tag).toString())){
element_same_array.add(varial_array.get(i));
varial_array.remove(i);
--i;
}
}//2
this.yes_count=0;
this.no_count=0;
this.sum_count=0;
Distinct_tag_classify(element_same_array);
double x=(double)this.yes_count/this.sum_count;
double y=(double)this.no_count/this.sum_count;
if(x==0||y==0){
this.entropy=0;
}
else{
this.entropy=(-(x)*(Math.log10(x)/Math.log10(2))-(y)*(Math.log10(y)/Math.log10(2)));
}
if(this.entropy==0){
this.decision_table_array.add(temp_element);
temp_element= element_same_array.get(0).record.get(this.classify_column_number).toString();
this.decision_table_array.add(temp_element);
element_same_array.removeAll(element_same_array);
}
else{
this.decision_table_ar
没有合适的资源?快使用搜索试试~ 我知道了~
Java_DataMing.zip_Java 决策树_决策树_决策树 java
共13个文件
class:5个
java:5个
classpath:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 30 浏览量
2022-09-21
09:07:02
上传
评论
收藏 17KB ZIP 举报
温馨提示
应用递归思想,完成深度优先的递归,当完成递归后,生成决策树。最后根据决策树,作出决策
资源详情
资源评论
资源推荐
收起资源包目录
Java_DataMing.zip (13个子文件)
Exp1_DataMing
bin
CQU
EDU
yu
cn
Display_result.class 6KB
Deal_with_result.class 8KB
Record.class 444B
Construct_decision_tree_dataset.class 908B
Model_table.class 448B
.settings
org.eclipse.jdt.core.prefs 629B
src
CQU
EDU
yu
cn
Deal_with_result.java 9KB
Display_result.java 5KB
Construct_decision_tree_dataset.java 510B
Model_table.java 239B
Record.java 184B
.project 389B
.classpath 301B
共 13 条
- 1
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0