Я создаю дерево решений в R, которое имеет около 50 категориальных и непрерывных переменных. Я хотел бы отобразить дерево решений, которое я создаю с использованием Rpart, в лучшем формате, чтобы отображалось только имя переменной, а не имя переменной и все уровни фактора. Если вы посмотрите на выходные данные ниже, имя первого узла даже не помещается на странице, я хотел бы, чтобы оно показывало только короткое имя, соответствующее имени переменной.
Это разные способы, которыми я пытался отобразить дерево решений:
temp_dia<- read.csv("~/temp_dia.csv")
fit<- rpart(temp_dia$diabetesMed ~ ., method = "class", data = temp_dia, control = rpart.control(minsplit = 10, cp = 1e-04), parms = list(prior = c(0.3, 0.7)))
#1
rpart.plot(fit, type = 2)
labels(fit,minlength=2)
#2
plot(cart_fit, uniform = TRUE, main = "Diabetes Tree: CART Method")
text(cart_fit, cex = .5, pretty = 1)
#3
fancyRpartPlot(cart_fit, tweak = 1, cex = .4)
И выходные данные всегда различаются по-разному:
"","encounter_id","patient_nbr","race","gender","age","weight","admission_type_id","discharge_disposition_id","admission_source_id","time_in_hospital","payer_code","medical_specialty","num_lab_procedures","num_procedures","num_medications","number_outpatient","number_emergency","number_inpatient","diag_1","diag_2","diag_3","number_diagnoses","max_glu_serum","A1Cresult","metformin","repaglinide","nateglinide","chlorpropamide","glimepiride","acetohexamide","glipizide","glyburide","tolbutamide","pioglitazone","rosiglitazone","acarbose","miglitol","troglitazone","tolazamide","examide","citoglipton","insulin","glyburide.metformin","glipizide.metformin","glimepiride.pioglitazone","metformin.rosiglitazone","metformin.pioglitazone","change","diabetesMed","readmitted","payer_Code"
"93102",330845978,182710562,"Other","Female","[20-30)",NA,1,1,7,2,"HM",NA,15,0,9,0,3,2,250.13,58,278,5,"None","None","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","Down","No","No","No","No","No","Ch","Yes",">30","HM"
"9676",41839230,3254877,"Caucasian","Female","[70-80)",NA,2,18,4,4,NA,NA,48,0,9,0,0,0,57,599,428,9,"None","None","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No",">30","?"
"80187",246965256,67722615,"Caucasian","Female","[60-70)",NA,1,1,7,4,"HM",NA,65,0,13,0,0,0,599,250.12,276,9,"None",">8","No","No","No","No","No","No","Steady","Steady","No","No","No","No","No","No","No","No","No","Up","No","No","No","No","No","Ch","Yes","NO","HM"
"74781",223125180,66812265,"Caucasian","Female","[70-80)",NA,1,1,7,2,"MC",NA,49,0,11,0,0,0,410,428,428,9,"None","None","No","No","No","No","No","No","No","Down","No","Steady","No","No","No","No","No","No","No","Steady","No","No","No","No","No","Ch","Yes","NO","MC"
"91571",310847996,103962996,NA,"Male","[50-60)",NA,1,6,7,8,"SP",NA,83,6,52,0,0,0,414,411,996,16,"None","None","No","No","No","No","Steady","No","No","No","No","No","No","No","No","No","No","No","No","Down","No","No","No","No","No","Ch","Yes","NO","SP"
"60355",169169532,72201339,"AfricanAmerican","Female","[70-80)",NA,2,1,1,3,NA,"Cardiology",34,3,7,0,0,0,402,280,425,9,"None","None","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No",">30","?"
"28270",92610462,24174819,"AfricanAmerican","Female","[70-80)",NA,5,3,17,6,"MD","Family/GeneralPractice",9,0,17,0,1,0,491,112,250,4,"Norm","None","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","Steady","No","No","No","No","No","No","Yes","NO","MD"
"38376",119309802,24587082,"AfricanAmerican","Female","[70-80)",NA,1,6,7,7,"MC","InternalMedicine",43,5,35,1,0,2,428,518,424,9,"None","None","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","<30","MC"
"21620",75215838,103528647,"Caucasian","Male","[50-60)",NA,2,1,7,1,NA,NA,10,0,16,0,0,1,415,427,707,9,"None","None","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","Steady","No","No","No","No","No","No","Yes","NO","?"```