From b16b60fcb56f801070b89a4867e69422a78dd81a Mon Sep 17 00:00:00 2001 From: Ayush Date: Thu, 23 Jul 2020 16:45:31 +0530 Subject: [PATCH] Adding Example script for CART --- examples/datasets/boston_house_prices.csv | 1460 +++++++++++++++++++++ examples/datasets/titanic.csv | 889 +++++++++++++ examples/trees/cart.go | 61 + trees/cart_classifier.go | 2 +- 4 files changed, 2411 insertions(+), 1 deletion(-) create mode 100644 examples/datasets/boston_house_prices.csv create mode 100644 examples/datasets/titanic.csv create mode 100644 examples/trees/cart.go diff --git a/examples/datasets/boston_house_prices.csv b/examples/datasets/boston_house_prices.csv new file mode 100644 index 0000000..a330ca0 --- /dev/null +++ b/examples/datasets/boston_house_prices.csv @@ -0,0 +1,1460 @@ +7,208500 +6,181500 +7,223500 +7,140000 +8,250000 +5,143000 +8,307000 +7,200000 +7,129900 +5,118000 +5,129500 +9,345000 +5,144000 +7,279500 +6,157000 +7,132000 +6,149000 +4,90000 +5,159000 +5,139000 +8,325300 +7,139400 +8,230000 +5,129900 +5,154000 +8,256300 +5,134800 +8,306000 +5,207500 +4,68500 +4,40000 +5,149350 +8,179900 +5,165500 +9,277500 +8,309000 +5,145000 +5,153000 +5,109000 +4,82000 +6,160000 +5,170000 +5,144000 +5,130250 +5,141000 +9,319900 +7,239686 +8,249700 +4,113000 +5,127000 +6,177000 +6,114500 +5,110000 +9,385000 +5,130000 +6,180500 +8,172500 +7,196500 +10,438780 +5,124900 +6,158000 +5,101000 +8,202500 +7,140000 +7,219500 +8,317000 +7,180000 +7,226000 +4,80000 +7,225000 +7,244000 +4,129500 +7,185000 +5,144900 +3,107400 +4,91000 +4,135750 +5,127000 +4,136500 +5,110000 +6,193500 +6,153500 +8,245000 +5,126500 +7,168500 +8,260000 +6,174000 +6,164500 +3,85000 +4,123600 +4,109900 +5,98600 +5,163500 +6,133900 +6,204750 +6,185000 +7,214000 +4,94750 +5,83000 +4,128950 +6,205000 +6,178000 +5,118964 +7,198900 +7,169500 +8,250000 +4,100000 +5,115000 +5,115000 +6,190000 +6,136900 +7,180000 +7,383970 +6,217000 +6,259500 +6,176000 +5,139000 +5,155000 +7,320000 +6,163990 +6,180000 +4,100000 +6,136000 +6,153900 +6,181000 +6,84500 +6,128000 +5,87000 +6,155000 +5,150000 +7,226000 +6,244000 +5,150750 +8,220000 +5,180000 +7,174000 +5,143000 +7,171000 +8,230000 +6,231500 +4,115000 +7,260000 +5,166000 +7,204000 +5,125000 +6,130000 +5,105000 +7,222500 +7,141000 +5,115000 +5,122000 +8,372402 +6,190000 +6,235000 +6,125000 +6,79000 +5,109500 +8,269500 +7,254900 +7,320000 +6,162500 +9,412500 +7,220000 +4,103200 +6,152000 +5,127500 +5,190000 +8,325624 +7,183500 +8,228000 +5,128500 +6,215000 +7,239000 +6,163000 +6,184000 +6,243000 +6,211000 +5,172500 +9,501837 +5,100000 +6,177000 +7,200100 +5,120000 +7,200000 +5,127000 +10,475000 +7,173000 +5,135000 +5,153337 +8,286000 +8,315000 +7,184000 +7,192000 +7,130000 +5,127000 +6,148500 +7,311872 +8,235000 +6,104000 +8,274900 +4,140000 +6,171500 +6,112000 +6,149000 +5,110000 +7,180500 +5,143900 +4,141000 +7,277000 +6,145000 +5,98000 +6,186000 +7,252678 +5,156000 +6,161750 +5,134450 +7,210000 +4,107000 +7,311500 +7,167240 +7,204900 +6,200000 +6,179900 +4,97000 +10,386250 +5,112000 +7,290000 +6,106000 +5,125000 +7,192500 +6,148000 +8,403000 +6,94500 +5,128200 +6,216500 +6,89500 +7,185500 +7,194500 +8,318000 +6,113000 +8,262500 +5,110500 +5,79000 +6,120000 +7,205000 +7,241500 +6,137000 +6,140000 +7,180000 +6,277000 +3,76500 +8,235000 +6,173000 +6,158000 +5,145000 +7,230000 +6,207500 +7,220000 +7,231500 +5,97000 +6,176000 +8,276000 +6,151000 +5,130000 +5,73000 +6,175500 +6,185000 +5,179500 +5,120500 +6,148000 +8,266000 +7,241500 +8,290000 +6,139000 +5,124500 +7,205000 +7,201000 +4,141000 +9,415298 +7,192000 +7,228500 +6,185000 +7,207500 +8,244600 +6,179200 +7,164700 +6,159000 +4,88000 +5,122000 +6,153575 +8,233230 +5,135900 +5,131000 +7,235000 +6,167000 +6,142500 +5,152000 +7,239000 +6,175000 +6,158500 +5,157000 +8,267000 +7,205000 +5,149900 +7,295000 +8,305900 +7,225000 +6,89500 +4,82500 +9,360000 +6,165600 +6,132000 +5,119900 +7,375000 +7,178000 +7,188500 +7,260000 +8,270000 +7,260000 +7,187500 +9,342643 +8,354000 +7,301000 +3,126175 +7,242000 +5,87000 +8,324000 +6,145250 +6,214500 +5,78000 +5,119000 +5,139000 +8,284000 +7,207000 +6,192000 +5,228950 +9,377426 +7,214000 +7,202500 +6,155000 +8,202900 +4,82000 +3,87500 +9,266000 +5,85000 +6,140200 +6,151500 +6,157500 +7,154000 +9,437154 +9,318061 +7,190000 +5,95000 +6,105900 +6,140000 +6,177500 +6,173000 +5,134000 +5,130000 +8,280000 +6,156000 +5,145000 +7,198500 +6,118000 +6,190000 +5,147000 +6,159000 +6,165000 +5,132000 +5,162000 +6,172400 +4,134432 +6,125000 +5,123000 +7,219500 +1,61000 +5,148000 +8,340000 +9,394432 +6,179000 +5,127000 +7,187750 +7,213500 +6,76000 +6,240000 +8,192000 +5,81000 +6,125000 +7,191000 +10,426000 +5,119000 +6,215000 +5,106500 +4,100000 +5,109000 +5,129000 +5,123000 +5,169500 +5,67000 +7,241000 +8,245500 +7,164990 +5,108000 +8,258000 +6,168000 +4,150000 +6,115000 +6,177000 +7,280000 +8,339750 +5,60000 +5,145000 +7,222000 +5,115000 +7,228000 +7,181134 +6,149500 +6,239000 +5,126000 +5,142000 +7,206300 +6,215000 +5,113000 +8,315000 +6,139000 +7,135000 +7,275000 +4,109008 +7,195400 +6,175000 +6,85400 +6,79900 +5,122500 +6,181000 +4,81000 +7,212000 +6,116000 +6,119000 +5,90350 +6,110000 +10,555000 +4,118000 +5,162900 +7,172500 +7,210000 +6,127500 +6,190000 +7,199900 +6,119500 +3,120000 +6,110000 +7,280000 +6,204000 +8,210000 +5,188000 +7,175500 +5,98000 +4,256000 +8,161000 +5,110000 +8,263435 +7,155000 +5,62383 +6,188700 +5,124000 +7,178740 +7,167000 +5,146500 +8,250000 +6,187000 +8,212000 +7,190000 +6,148000 +8,440000 +8,251000 +5,132500 +6,208900 +9,380000 +8,297000 +4,89471 +9,326000 +9,374000 +7,155000 +6,164000 +5,132500 +5,147000 +5,156000 +5,175000 +5,160000 +4,86000 +5,115000 +6,133000 +6,172785 +5,155000 +5,91300 +4,34900 +8,430000 +7,184000 +5,130000 +5,120000 +6,113000 +7,226700 +5,140000 +7,289000 +6,147000 +5,124500 +8,215000 +6,208300 +7,161000 +5,124500 +5,164900 +7,202665 +5,129900 +6,134000 +5,96500 +10,402861 +6,158000 +7,265000 +6,211000 +7,234000 +4,106250 +6,150000 +6,159000 +10,184750 +7,315750 +7,176000 +5,132000 +9,446261 +4,86000 +6,200624 +6,175000 +6,128000 +5,107500 +1,39300 +8,178000 +5,107500 +7,188000 +4,111250 +5,158000 +8,272000 +9,315000 +8,248000 +7,213250 +7,133000 +7,179665 +7,229000 +6,210000 +5,129500 +5,125000 +7,263000 +6,140000 +5,112500 +8,255500 +4,108000 +7,284000 +5,113000 +5,141000 +4,108000 +7,175000 +7,234000 +5,121500 +5,170000 +5,108000 +6,185000 +7,268000 +6,128000 +9,325000 +7,214000 +8,316600 +5,135960 +5,142600 +6,120000 +7,224500 +7,170000 +5,139000 +5,118500 +7,145000 +5,164500 +7,146000 +5,131500 +6,181900 +8,253293 +6,118500 +10,325000 +4,133000 +8,369900 +6,130000 +5,137000 +5,143000 +5,79500 +7,185900 +10,451950 +5,138000 +6,140000 +5,110000 +8,319000 +6,114504 +7,194201 +5,217500 +6,151000 +8,275000 +6,141000 +8,220000 +7,151000 +7,221000 +7,205000 +5,152000 +5,225000 +8,359100 +4,118500 +9,313000 +6,148000 +8,261500 +5,147000 +4,75500 +6,137500 +6,183200 +6,105500 +9,314813 +8,305000 +3,67000 +6,240000 +5,135000 +6,168500 +6,165150 +6,160000 +5,139900 +6,153000 +5,135000 +6,168500 +5,124000 +8,209500 +7,82500 +5,139400 +6,144000 +6,200000 +2,60000 +5,93000 +5,85000 +8,264561 +8,274000 +7,226000 +8,345000 +5,152000 +9,370878 +6,143250 +5,98300 +6,155000 +6,155000 +4,84500 +7,205950 +4,108000 +7,191000 +6,135000 +8,350000 +6,88000 +5,145500 +7,149000 +6,97500 +5,167000 +7,197900 +8,402000 +6,110000 +4,137500 +8,423000 +8,230500 +6,129000 +6,193500 +5,168000 +4,137500 +6,173500 +6,103600 +6,165000 +6,257500 +6,140000 +6,148500 +4,87000 +5,109500 +8,372500 +5,128500 +6,143000 +5,159434 +6,173000 +9,285000 +7,221000 +7,207500 +7,227875 +7,148800 +8,392000 +6,194700 +6,141000 +10,755000 +7,335000 +5,108480 +5,141500 +6,176000 +5,89000 +5,123500 +5,138500 +7,196000 +8,312500 +7,140000 +8,361919 +5,140000 +7,213000 +4,55000 +7,302000 +8,254000 +7,179540 +5,109900 +3,52000 +4,102776 +8,189000 +4,129000 +6,130500 +6,165000 +7,159500 +5,157000 +7,341000 +5,128500 +8,275000 +6,143000 +4,124500 +4,135000 +9,320000 +4,120500 +6,222000 +7,194500 +5,110000 +4,103000 +8,236500 +7,187500 +7,222500 +5,131400 +5,108000 +7,163000 +3,93500 +8,239900 +5,179000 +7,190000 +5,132000 +6,142000 +7,179000 +5,175000 +8,180000 +8,299800 +7,236000 +7,265979 +7,260400 +4,98000 +4,96500 +7,162000 +6,217000 +8,275500 +6,156000 +6,172500 +8,212000 +6,158900 +7,179400 +8,290000 +6,127500 +5,100000 +7,215200 +8,337000 +8,270000 +9,264132 +7,196500 +6,160000 +7,216837 +8,538000 +5,134900 +4,102000 +6,107000 +5,114500 +8,395000 +6,162000 +7,221500 +5,142500 +5,144000 +6,135000 +7,176000 +6,175900 +7,187100 +5,165500 +6,128000 +6,161500 +5,139000 +7,233000 +4,107900 +6,187500 +7,160200 +6,146800 +7,269790 +8,225000 +7,194500 +6,171000 +6,143500 +5,110000 +9,485000 +5,175000 +6,200000 +4,109900 +7,189000 +9,582933 +5,118000 +7,227680 +5,135500 +5,223500 +5,159950 +5,106000 +6,181000 +6,144500 +5,55993 +6,157900 +5,116000 +7,224900 +5,137000 +8,271000 +6,155000 +7,224000 +7,183000 +4,93000 +7,225000 +6,139500 +8,232600 +10,385000 +5,109500 +7,189000 +5,185000 +7,147400 +6,166000 +7,151000 +7,237000 +6,167000 +5,139950 +4,128000 +5,153500 +6,100000 +5,144000 +5,130500 +6,140000 +5,157500 +6,174900 +5,141000 +5,153900 +5,171000 +7,213000 +5,133500 +6,240000 +6,187000 +6,131500 +8,215000 +7,164000 +6,158000 +5,170000 +5,127000 +6,147000 +6,174000 +7,152000 +6,250000 +7,189950 +5,131500 +6,152000 +5,132500 +7,250580 +5,148500 +8,248900 +4,129000 +5,169000 +7,236000 +5,109500 +6,200500 +5,116000 +5,133000 +5,66500 +8,303477 +4,132250 +9,350000 +5,148000 +5,136500 +5,157000 +7,187500 +6,178000 +4,118500 +5,100000 +9,328900 +5,145000 +5,135500 +8,268000 +6,149500 +5,122900 +6,172500 +6,154500 +5,165000 +5,118858 +6,140000 +4,106500 +5,142953 +9,611657 +5,135000 +4,110000 +5,153000 +7,180000 +7,240000 +5,125500 +5,128000 +8,255000 +7,250000 +5,131000 +6,174000 +5,154300 +5,143500 +5,88000 +5,145000 +6,173733 +4,75000 +2,35311 +4,135000 +7,238000 +6,176500 +6,201000 +5,145900 +6,169990 +6,193000 +6,207500 +5,175000 +8,285000 +7,176000 +8,236500 +7,222000 +8,201000 +5,117500 +9,320000 +7,190000 +7,242000 +4,79900 +7,184900 +7,253000 +7,239799 +7,244400 +6,150900 +7,214000 +4,150000 +5,143000 +6,137500 +5,124900 +5,143000 +8,270000 +7,192500 +6,197500 +5,129000 +5,119900 +5,133900 +5,172000 +6,127500 +6,145000 +6,124000 +5,132000 +7,185000 +7,155000 +5,116500 +6,272000 +6,155000 +9,239000 +7,214900 +6,178900 +5,160000 +5,135000 +3,37900 +6,140000 +4,135000 +7,173000 +6,99500 +7,182000 +7,167500 +7,165000 +4,85500 +7,199900 +4,110000 +5,139000 +7,178400 +8,336000 +7,159895 +8,255900 +5,126000 +5,125000 +6,117000 +9,395192 +6,195000 +7,197000 +8,348000 +8,168000 +6,187000 +6,173900 +10,337500 +4,121600 +5,136500 +6,185000 +3,91000 +7,206000 +3,82000 +5,86000 +8,232000 +5,136905 +7,181000 +5,149900 +6,163500 +4,88000 +7,240000 +5,102000 +5,135000 +5,100000 +6,165000 +5,85000 +6,119200 +8,227000 +7,203000 +8,187500 +7,160000 +7,213490 +4,176000 +7,194000 +5,87000 +7,191000 +8,287000 +5,112500 +5,167500 +8,293077 +5,105000 +6,118000 +5,160000 +7,197000 +8,310000 +7,230000 +5,119750 +4,84000 +9,315500 +8,287000 +4,97000 +4,80000 +5,155000 +6,173000 +6,196000 +7,262280 +8,278000 +3,139600 +9,556581 +5,145000 +5,115000 +4,84900 +7,176485 +7,200141 +6,165000 +5,144500 +8,255000 +6,180000 +7,185850 +7,248000 +9,335000 +6,220000 +8,213500 +3,81000 +5,90000 +6,110500 +5,154000 +7,328000 +6,178000 +6,167900 +6,151400 +5,135000 +5,135000 +6,154000 +5,91500 +6,159500 +7,194000 +7,219500 +5,170000 +5,138800 +6,155900 +5,126000 +6,145000 +5,133000 +7,192000 +6,160000 +6,187500 +6,147000 +4,83500 +8,252000 +7,137500 +8,197000 +3,92900 +7,160000 +6,136500 +5,146000 +5,129000 +6,176432 +6,127000 +8,170000 +4,128000 +7,157000 +2,60000 +5,119500 +5,135000 +6,159500 +5,106000 +8,325000 +7,179900 +7,274725 +6,181000 +8,280000 +6,188000 +7,205000 +5,129900 +5,134500 +5,117000 +8,318000 +8,184100 +5,130000 +5,140000 +5,133700 +6,118400 +7,212900 +4,112000 +5,118000 +7,163900 +4,115000 +7,174000 +7,259000 +7,215000 +5,140000 +4,135000 +5,93500 +6,117500 +8,239500 +6,169000 +6,102000 +6,119000 +5,94000 +6,196000 +5,144000 +5,139000 +5,197500 +8,424870 +5,80000 +4,80000 +5,149000 +6,180000 +7,174500 +7,116900 +7,143000 +6,124000 +5,149900 +6,230000 +6,120500 +7,201800 +5,218000 +5,179900 +7,230000 +8,235128 +6,185000 +6,146000 +6,224000 +5,129000 +4,108959 +5,194000 +7,233170 +8,245350 +6,173000 +6,235000 +10,625000 +6,171000 +6,163000 +7,171900 +5,200500 +6,239000 +8,285000 +5,119500 +6,115000 +5,154900 +5,93000 +7,250000 +8,392500 +10,745000 +5,120000 +5,186700 +5,104900 +3,95000 +8,262000 +7,195000 +7,189000 +4,168000 +8,174000 +5,125000 +6,165000 +6,158000 +6,176000 +7,219210 +7,144000 +7,178000 +4,148000 +4,116050 +7,197900 +5,117000 +7,213000 +5,153500 +7,271900 +4,107000 +6,200000 +5,140000 +8,290000 +6,189000 +8,164000 +4,113000 +4,145000 +5,134500 +5,125000 +6,112000 +8,229456 +4,80500 +6,91500 +5,115000 +5,134000 +6,143000 +5,137900 +7,184000 +6,145000 +6,214000 +5,147000 +9,367294 +5,127000 +5,190000 +5,132500 +4,101800 +5,142000 +5,130000 +5,138887 +7,175500 +7,195000 +6,142500 +8,265900 +7,224900 +7,248328 +7,170000 +10,465000 +8,230000 +6,178000 +7,186500 +6,169900 +6,129500 +5,119000 +7,244000 +7,171750 +5,130000 +7,294000 +7,165400 +6,127500 +8,301500 +5,99900 +7,190000 +6,151000 +6,181000 +5,128900 +4,161500 +6,180500 +6,181000 +7,183900 +7,122000 +9,378500 +8,381000 +5,144000 +7,260000 +6,185750 +5,137000 +6,177000 +5,139000 +5,137000 +6,162000 +6,197900 +8,237000 +4,68400 +7,227000 +7,180000 +5,150500 +6,139000 +6,169000 +6,132500 +6,143000 +5,190000 +8,278000 +8,281000 +5,180500 +5,119500 +5,107500 +7,162900 +5,115000 +5,138500 +5,155000 +6,140000 +10,160000 +5,154000 +7,225000 +6,177500 +8,290000 +7,232000 +7,130000 +9,325000 +7,202500 +5,138000 +5,147000 +6,179200 +7,335000 +7,203000 +8,302000 +9,333168 +4,119000 +6,206900 +8,295493 +7,208900 +8,275000 +4,111000 +6,156500 +3,72500 +7,190000 +4,82500 +8,147000 +4,55000 +3,79000 +5,130500 +6,256000 +7,176500 +8,227000 +5,132500 +4,100000 +5,125500 +5,125000 +6,167900 +5,135000 +4,52500 +7,200000 +5,128500 +4,123000 +6,155000 +8,228500 +6,177000 +7,155835 +4,108500 +7,262500 +8,283463 +7,215000 +8,122000 +5,200000 +6,171000 +6,134900 +8,410000 +7,235000 +7,170000 +5,110000 +5,149900 +6,177500 +9,315000 +5,189000 +7,260000 +4,104900 +6,156932 +7,144152 +7,216000 +7,193000 +5,127000 +6,144000 +8,232000 +4,105000 +6,165500 +7,274300 +10,466500 +7,250000 +8,239000 +6,91000 +5,117000 +6,83000 +5,167500 +3,58500 +6,237500 +7,157000 +5,112000 +6,105000 +4,125500 +7,250000 +6,136000 +9,377500 +6,131000 +7,235000 +5,124000 +5,123000 +6,163000 +7,246578 +8,281213 +5,160000 +5,137500 +5,138000 +6,137450 +6,120000 +6,193000 +7,193879 +8,282922 +3,105000 +8,275000 +5,133000 +5,112000 +4,125500 +7,215000 +7,230000 +6,140000 +4,90000 +8,257000 +6,207000 +7,175900 +4,122500 +8,340000 +5,124000 +6,223000 +6,179900 +6,127500 +6,136500 +6,274970 +5,144000 +6,142000 +7,271000 +5,140000 +5,119000 +6,182900 +5,192140 +6,143750 +4,64500 +6,186500 +5,160000 +6,174000 +4,120500 +8,394617 +6,149700 +7,197000 +6,191000 +6,149300 +10,310000 +6,121000 +7,179600 +6,129000 +5,157900 +8,240000 +4,112000 +5,92000 +5,136000 +8,287090 +5,145000 +5,84500 +7,185000 +6,175000 +6,210000 +7,266500 +5,142125 +5,147500 \ No newline at end of file diff --git a/examples/datasets/titanic.csv b/examples/datasets/titanic.csv new file mode 100644 index 0000000..bb66baf --- /dev/null +++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+0,3,1,2 +0,2,1,2 +1,1,0,2 +1,3,0,2 +0,3,1,0 +0,3,0,2 +0,2,1,2 +1,2,0,2 +1,1,1,2 +1,3,1,0 +1,3,1,2 +0,3,1,2 +0,1,1,2 +0,3,0,2 +0,2,1,2 +1,1,0,2 +0,3,1,2 +0,3,1,2 +0,2,1,2 +0,3,0,2 +0,3,1,2 +0,1,1,2 +0,3,0,2 +0,2,1,0 +0,3,1,2 +0,3,1,2 +1,1,0,2 +1,3,1,2 +0,1,1,2 +1,3,0,2 +0,3,1,2 +0,3,1,1 +0,3,1,2 +1,2,1,0 +1,3,1,1 +1,3,0,0 +1,2,1,2 +0,3,1,0 +0,3,1,2 +0,3,1,2 +1,1,0,0 +0,3,1,2 +0,3,1,2 +1,3,1,2 +1,1,1,0 +0,3,1,2 +0,2,1,2 +1,1,0,0 +0,3,1,0 +0,3,1,2 +0,3,1,2 +0,3,1,2 +0,3,1,0 +0,2,1,2 +1,1,0,0 +0,3,1,2 +0,3,1,2 +0,3,0,0 +1,1,0,2 +0,2,0,2 +1,3,0,2 +1,1,0,2 +1,1,1,2 +1,3,0,0 +0,3,1,0 +0,3,1,2 +0,2,1,2 +1,1,0,2 +0,3,0,2 +0,2,1,2 +1,2,0,2 +1,2,0,0 +0,1,1,2 +0,3,1,2 +1,3,1,2 +0,3,1,2 +1,1,0,2 +0,1,1,2 +0,3,1,2 +1,2,0,0 +1,3,0,0 +0,3,1,2 +0,3,1,2 +0,3,1,2 +1,1,0,0 +1,2,0,2 +0,3,1,2 +0,3,0,2 +0,2,1,2 +0,3,1,2 +0,3,0,1 +0,2,1,2 +1,1,0,2 +0,3,0,2 +1,1,1,0 +0,3,1,1 \ No newline at end of file diff --git a/examples/trees/cart.go b/examples/trees/cart.go new file mode 100644 index 0000000..931b7e5 --- /dev/null +++ b/examples/trees/cart.go @@ -0,0 +1,61 @@ +// Example of how to use CART trees for both Classification and Regression + +package main + +import ( + "fmt" + + "github.com/sjwhitworth/golearn/base" +) + +func main() { + + // Load Titanic Data For classification + classificationData, err := base.ParseCSVToInstances("../datasets/titanic.csv", false) + if err != nil { + panic(err) + } + trainData, testData := base.InstancesTrainTestSplit(classificationData, 0.5) + + // Create New Classification Tree + // Hyperparameters - loss function, max Depth (-1 will split until pure), list of unique labels + decTree = NewDecisionTreeClassifier("entropy", -1, []int64{0, 1}) + + // Train Tree + decTree.Fit(trainData) + // Print out tree for visualization - shows splits and feature and predictions + fmt.Println(decTree.String()) + + // Access Predictions + classificationPreds := decTree.Predict(testData) + + fmt.Println("Titanic Predictions") + fmt.Println(classificationPreds) + + // Evaluate Accuracy on Test Data + fmt.Println(decTree.Evaluate(testData)) + + // Load House Price Data For Regression + + regressionData, err := base.ParseCSVToInstances("../datasets/boston_house_prices.csv", false) + if err != nil { + panic(err) + } + trainRegData, testRegData := base.InstancesTrainTestSplit(regressionData, 0.5) + + // Hyperparameters - Loss function, max Depth (-1 will split until pure) + regTree := NewDecisionTreeRegressor("mse", -1) + + // Train Tree + regTree.Fit(trainRegData) + + // Print out tree for visualization + fmt.Println(regTree.String()) + + // Access Predictions + regressionPreds := regTree.Predict(testRegData) + + fmt.Println("Boston House Price Predictions") + fmt.Println(regressionPreds) + +} diff --git a/trees/cart_classifier.go b/trees/cart_classifier.go index 29646fb..39b7165 100644 --- a/trees/cart_classifier.go +++ b/trees/cart_classifier.go @@ -432,7 +432,7 @@ func cpredictFromNode(tree CNode, test [][]float64) []int64 { return preds } -// Given Test data and label, return the accuracy of the classifier. Data has to be in float slice format before feeding. +// Given Test data and label, return the accuracy of the classifier. func (tree *CARTDecisionTreeClassifier) Evaluate(test base.FixedDataGrid) float64 { rootNode := *tree.RootNode xTest := classifierConvertInstancesToProblemVec(test)