import{buildAlgorithmConfiguration,growTree,getTreeAccuracy,prune,sampleDataSets,dataSet,statistics,impurity}from'tree-garden';const[training,validation]=dataSet.getDividedSet(sampleDataSets.titanicSet,0.85);console.log(`length of validation: ${validation.length}, length of training: ${training.length} `);constmyConfig=buildAlgorithmConfiguration(sampleDataSets.titanicSet,{excludedAttributes: ['name','ticket','embarked','cabin'],// exclude some attrs that we do not want to useattributes: {pclass: {dataType: 'discrete'},parch: {dataType: 'discrete'},sibs: {dataType: 'discrete'}},// consider some number attributes as discrete valuesgetScoreForSplit: impurity.getInformationGainRatioForSplit,biggerScoreBetterSplit: true});consttree=growTree(myConfig,training);console.log(`UNPRUNED: Number of nodes,${statistics.getNumberOfTreeNodes(tree)} acc:${getTreeAccuracy(tree,validation,myConfig)}`);constprunedTree=prune.getPrunedTreeByCostComplexityPruning(tree,sampleDataSets.titanicSet,myConfig);console.log(`Pruned: Number of nodes,${statistics.getNumberOfTreeNodes(prunedTree)} acc:${getTreeAccuracy(prunedTree,validation,myConfig)}`);// console.log(JSON.stringify(prunedTree));