nlptoolkit-classification 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -0
- package/datasets/bupa.data +345 -0
- package/datasets/car.data +1728 -0
- package/datasets/chess.data +28056 -0
- package/datasets/dermatology.data +366 -0
- package/datasets/iris.data +150 -0
- package/datasets/nursery.data +12960 -0
- package/datasets/tictactoe.data +958 -0
- package/dist/Attribute/Attribute.d.ts +4 -0
- package/dist/Attribute/Attribute.js +17 -0
- package/dist/Attribute/Attribute.js.map +1 -0
- package/dist/Attribute/AttributeType.d.ts +18 -0
- package/dist/Attribute/AttributeType.js +33 -0
- package/dist/Attribute/AttributeType.js.map +1 -0
- package/dist/Attribute/BinaryAttribute.d.ts +9 -0
- package/dist/Attribute/BinaryAttribute.js +26 -0
- package/dist/Attribute/BinaryAttribute.js.map +1 -0
- package/dist/Attribute/ContinuousAttribute.d.ts +30 -0
- package/dist/Attribute/ContinuousAttribute.js +59 -0
- package/dist/Attribute/ContinuousAttribute.js.map +1 -0
- package/dist/Attribute/DiscreteAttribute.d.ts +24 -0
- package/dist/Attribute/DiscreteAttribute.js +53 -0
- package/dist/Attribute/DiscreteAttribute.js.map +1 -0
- package/dist/Attribute/DiscreteIndexedAttribute.d.ts +27 -0
- package/dist/Attribute/DiscreteIndexedAttribute.js +61 -0
- package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -0
- package/dist/Classifier/Bagging.d.ts +16 -0
- package/dist/Classifier/Bagging.js +42 -0
- package/dist/Classifier/Bagging.js.map +1 -0
- package/dist/Classifier/C45.d.ts +13 -0
- package/dist/Classifier/C45.js +40 -0
- package/dist/Classifier/C45.js.map +1 -0
- package/dist/Classifier/C45Stump.d.ts +12 -0
- package/dist/Classifier/C45Stump.js +29 -0
- package/dist/Classifier/C45Stump.js.map +1 -0
- package/dist/Classifier/Classifier.d.ts +39 -0
- package/dist/Classifier/Classifier.js +72 -0
- package/dist/Classifier/Classifier.js.map +1 -0
- package/dist/Classifier/DeepNetwork.d.ts +13 -0
- package/dist/Classifier/DeepNetwork.js +31 -0
- package/dist/Classifier/DeepNetwork.js.map +1 -0
- package/dist/Classifier/Dummy.d.ts +13 -0
- package/dist/Classifier/Dummy.js +29 -0
- package/dist/Classifier/Dummy.js.map +1 -0
- package/dist/Classifier/KMeans.d.ts +12 -0
- package/dist/Classifier/KMeans.js +36 -0
- package/dist/Classifier/KMeans.js.map +1 -0
- package/dist/Classifier/Knn.d.ts +13 -0
- package/dist/Classifier/Knn.js +29 -0
- package/dist/Classifier/Knn.js.map +1 -0
- package/dist/Classifier/Lda.d.ts +12 -0
- package/dist/Classifier/Lda.js +52 -0
- package/dist/Classifier/Lda.js.map +1 -0
- package/dist/Classifier/LinearPerceptron.d.ts +14 -0
- package/dist/Classifier/LinearPerceptron.js +32 -0
- package/dist/Classifier/LinearPerceptron.js.map +1 -0
- package/dist/Classifier/MultiLayerPerceptron.d.ts +14 -0
- package/dist/Classifier/MultiLayerPerceptron.js +32 -0
- package/dist/Classifier/MultiLayerPerceptron.js.map +1 -0
- package/dist/Classifier/NaiveBayes.d.ts +25 -0
- package/dist/Classifier/NaiveBayes.js +67 -0
- package/dist/Classifier/NaiveBayes.js.map +1 -0
- package/dist/Classifier/Qda.d.ts +12 -0
- package/dist/Classifier/Qda.js +50 -0
- package/dist/Classifier/Qda.js.map +1 -0
- package/dist/Classifier/RandomClassifier.d.ts +12 -0
- package/dist/Classifier/RandomClassifier.js +32 -0
- package/dist/Classifier/RandomClassifier.js.map +1 -0
- package/dist/Classifier/RandomForest.d.ts +13 -0
- package/dist/Classifier/RandomForest.js +39 -0
- package/dist/Classifier/RandomForest.js.map +1 -0
- package/dist/DataSet/DataDefinition.d.ts +59 -0
- package/dist/DataSet/DataDefinition.js +108 -0
- package/dist/DataSet/DataDefinition.js.map +1 -0
- package/dist/DataSet/DataSet.d.ts +111 -0
- package/dist/DataSet/DataSet.js +286 -0
- package/dist/DataSet/DataSet.js.map +1 -0
- package/dist/DistanceMetric/DistanceMetric.d.ts +4 -0
- package/dist/DistanceMetric/DistanceMetric.js +13 -0
- package/dist/DistanceMetric/DistanceMetric.js.map +1 -0
- package/dist/DistanceMetric/EuclidianDistance.d.ts +13 -0
- package/dist/DistanceMetric/EuclidianDistance.js +43 -0
- package/dist/DistanceMetric/EuclidianDistance.js.map +1 -0
- package/dist/DistanceMetric/MahalanobisDistance.d.ts +20 -0
- package/dist/DistanceMetric/MahalanobisDistance.js +39 -0
- package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -0
- package/dist/Experiment/BootstrapRun.d.ts +19 -0
- package/dist/Experiment/BootstrapRun.js +44 -0
- package/dist/Experiment/BootstrapRun.js.map +1 -0
- package/dist/Experiment/Experiment.d.ts +37 -0
- package/dist/Experiment/Experiment.js +57 -0
- package/dist/Experiment/Experiment.js.map +1 -0
- package/dist/Experiment/KFoldRun.d.ts +19 -0
- package/dist/Experiment/KFoldRun.js +43 -0
- package/dist/Experiment/KFoldRun.js.map +1 -0
- package/dist/Experiment/KFoldRunSeparateTest.d.ts +24 -0
- package/dist/Experiment/KFoldRunSeparateTest.js +51 -0
- package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -0
- package/dist/Experiment/MultipleRun.d.ts +5 -0
- package/dist/Experiment/MultipleRun.js +13 -0
- package/dist/Experiment/MultipleRun.js.map +1 -0
- package/dist/Experiment/MxKFoldRun.d.ts +20 -0
- package/dist/Experiment/MxKFoldRun.js +44 -0
- package/dist/Experiment/MxKFoldRun.js.map +1 -0
- package/dist/Experiment/MxKFoldRunSeparateTest.d.ts +21 -0
- package/dist/Experiment/MxKFoldRunSeparateTest.js +48 -0
- package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -0
- package/dist/Experiment/SingleRun.d.ts +5 -0
- package/dist/Experiment/SingleRun.js +13 -0
- package/dist/Experiment/SingleRun.js.map +1 -0
- package/dist/Experiment/SingleRunWithK.d.ts +19 -0
- package/dist/Experiment/SingleRunWithK.js +37 -0
- package/dist/Experiment/SingleRunWithK.js.map +1 -0
- package/dist/Experiment/StratifiedKFoldRun.d.ts +17 -0
- package/dist/Experiment/StratifiedKFoldRun.js +39 -0
- package/dist/Experiment/StratifiedKFoldRun.js.map +1 -0
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.d.ts +18 -0
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +43 -0
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -0
- package/dist/Experiment/StratifiedMxKFoldRun.d.ts +19 -0
- package/dist/Experiment/StratifiedMxKFoldRun.js +43 -0
- package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -0
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.d.ts +20 -0
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +47 -0
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -0
- package/dist/Experiment/StratifiedSingleRunWithK.d.ts +18 -0
- package/dist/Experiment/StratifiedSingleRunWithK.js +39 -0
- package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -0
- package/dist/FeatureSelection/BackwardSelection.d.ts +18 -0
- package/dist/FeatureSelection/BackwardSelection.js +39 -0
- package/dist/FeatureSelection/BackwardSelection.js.map +1 -0
- package/dist/FeatureSelection/FeatureSubSet.d.ts +47 -0
- package/dist/FeatureSelection/FeatureSubSet.js +89 -0
- package/dist/FeatureSelection/FeatureSubSet.js.map +1 -0
- package/dist/FeatureSelection/FloatingSelection.d.ts +16 -0
- package/dist/FeatureSelection/FloatingSelection.js +38 -0
- package/dist/FeatureSelection/FloatingSelection.js.map +1 -0
- package/dist/FeatureSelection/ForwardSelection.d.ts +17 -0
- package/dist/FeatureSelection/ForwardSelection.js +38 -0
- package/dist/FeatureSelection/ForwardSelection.js.map +1 -0
- package/dist/FeatureSelection/SubSetSelection.d.ts +37 -0
- package/dist/FeatureSelection/SubSetSelection.js +90 -0
- package/dist/FeatureSelection/SubSetSelection.js.map +1 -0
- package/dist/Filter/DiscreteToContinuous.d.ts +25 -0
- package/dist/Filter/DiscreteToContinuous.js +69 -0
- package/dist/Filter/DiscreteToContinuous.js.map +1 -0
- package/dist/Filter/DiscreteToIndexed.d.ts +21 -0
- package/dist/Filter/DiscreteToIndexed.js +56 -0
- package/dist/Filter/DiscreteToIndexed.js.map +1 -0
- package/dist/Filter/FeatureFilter.d.ts +18 -0
- package/dist/Filter/FeatureFilter.js +36 -0
- package/dist/Filter/FeatureFilter.js.map +1 -0
- package/dist/Filter/LaryFilter.d.ts +27 -0
- package/dist/Filter/LaryFilter.js +62 -0
- package/dist/Filter/LaryFilter.js.map +1 -0
- package/dist/Filter/LaryToBinary.d.ts +23 -0
- package/dist/Filter/LaryToBinary.js +67 -0
- package/dist/Filter/LaryToBinary.js.map +1 -0
- package/dist/Filter/Normalize.d.ts +21 -0
- package/dist/Filter/Normalize.js +47 -0
- package/dist/Filter/Normalize.js.map +1 -0
- package/dist/Filter/Pca.d.ts +44 -0
- package/dist/Filter/Pca.js +109 -0
- package/dist/Filter/Pca.js.map +1 -0
- package/dist/Filter/TrainedFeatureFilter.d.ts +11 -0
- package/dist/Filter/TrainedFeatureFilter.js +26 -0
- package/dist/Filter/TrainedFeatureFilter.js.map +1 -0
- package/dist/Instance/CompositeInstance.d.ts +32 -0
- package/dist/Instance/CompositeInstance.js +61 -0
- package/dist/Instance/CompositeInstance.js.map +1 -0
- package/dist/Instance/Instance.d.ts +89 -0
- package/dist/Instance/Instance.js +170 -0
- package/dist/Instance/Instance.js.map +1 -0
- package/dist/InstanceList/InstanceList.d.ts +188 -0
- package/dist/InstanceList/InstanceList.js +517 -0
- package/dist/InstanceList/InstanceList.js.map +1 -0
- package/dist/InstanceList/InstanceListOfSameClass.d.ts +16 -0
- package/dist/InstanceList/InstanceListOfSameClass.js +35 -0
- package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -0
- package/dist/InstanceList/Partition.d.ts +31 -0
- package/dist/InstanceList/Partition.js +143 -0
- package/dist/InstanceList/Partition.js.map +1 -0
- package/dist/Model/DecisionTree/DecisionCondition.d.ts +34 -0
- package/dist/Model/DecisionTree/DecisionCondition.js +84 -0
- package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -0
- package/dist/Model/DecisionTree/DecisionNode.d.ts +82 -0
- package/dist/Model/DecisionTree/DecisionNode.js +271 -0
- package/dist/Model/DecisionTree/DecisionNode.js.map +1 -0
- package/dist/Model/DecisionTree/DecisionTree.d.ts +37 -0
- package/dist/Model/DecisionTree/DecisionTree.js +75 -0
- package/dist/Model/DecisionTree/DecisionTree.js.map +1 -0
- package/dist/Model/DeepNetworkModel.d.ts +42 -0
- package/dist/Model/DeepNetworkModel.js +163 -0
- package/dist/Model/DeepNetworkModel.js.map +1 -0
- package/dist/Model/DummyModel.d.ts +20 -0
- package/dist/Model/DummyModel.js +46 -0
- package/dist/Model/DummyModel.js.map +1 -0
- package/dist/Model/GaussianModel.d.ts +24 -0
- package/dist/Model/GaussianModel.js +59 -0
- package/dist/Model/GaussianModel.js.map +1 -0
- package/dist/Model/KMeansModel.d.ts +27 -0
- package/dist/Model/KMeansModel.js +48 -0
- package/dist/Model/KMeansModel.js.map +1 -0
- package/dist/Model/KnnInstance.d.ts +14 -0
- package/dist/Model/KnnInstance.js +33 -0
- package/dist/Model/KnnInstance.js.map +1 -0
- package/dist/Model/KnnModel.d.ts +36 -0
- package/dist/Model/KnnModel.js +83 -0
- package/dist/Model/KnnModel.js.map +1 -0
- package/dist/Model/LdaModel.d.ts +25 -0
- package/dist/Model/LdaModel.js +45 -0
- package/dist/Model/LdaModel.js.map +1 -0
- package/dist/Model/LinearPerceptronModel.d.ts +21 -0
- package/dist/Model/LinearPerceptronModel.js +62 -0
- package/dist/Model/LinearPerceptronModel.js.map +1 -0
- package/dist/Model/Model.d.ts +12 -0
- package/dist/Model/Model.js +31 -0
- package/dist/Model/Model.js.map +1 -0
- package/dist/Model/MultiLayerPerceptronModel.d.ts +29 -0
- package/dist/Model/MultiLayerPerceptronModel.js +101 -0
- package/dist/Model/MultiLayerPerceptronModel.js.map +1 -0
- package/dist/Model/NaiveBayesModel.d.ts +47 -0
- package/dist/Model/NaiveBayesModel.js +95 -0
- package/dist/Model/NaiveBayesModel.js.map +1 -0
- package/dist/Model/NeuralNetworkModel.d.ts +99 -0
- package/dist/Model/NeuralNetworkModel.js +180 -0
- package/dist/Model/NeuralNetworkModel.js.map +1 -0
- package/dist/Model/QdaModel.d.ts +26 -0
- package/dist/Model/QdaModel.js +45 -0
- package/dist/Model/QdaModel.js.map +1 -0
- package/dist/Model/RandomModel.d.ts +16 -0
- package/dist/Model/RandomModel.js +51 -0
- package/dist/Model/RandomModel.js.map +1 -0
- package/dist/Model/TreeEnsembleModel.d.ts +21 -0
- package/dist/Model/TreeEnsembleModel.js +49 -0
- package/dist/Model/TreeEnsembleModel.js.map +1 -0
- package/dist/Model/ValidatedModel.d.ts +12 -0
- package/dist/Model/ValidatedModel.js +35 -0
- package/dist/Model/ValidatedModel.js.map +1 -0
- package/dist/Parameter/ActivationFunction.d.ts +5 -0
- package/dist/Parameter/ActivationFunction.js +20 -0
- package/dist/Parameter/ActivationFunction.js.map +1 -0
- package/dist/Parameter/BaggingParameter.d.ts +17 -0
- package/dist/Parameter/BaggingParameter.js +36 -0
- package/dist/Parameter/BaggingParameter.js.map +1 -0
- package/dist/Parameter/C45Parameter.d.ts +25 -0
- package/dist/Parameter/C45Parameter.js +46 -0
- package/dist/Parameter/C45Parameter.js.map +1 -0
- package/dist/Parameter/DeepNetworkParameter.d.ts +38 -0
- package/dist/Parameter/DeepNetworkParameter.js +60 -0
- package/dist/Parameter/DeepNetworkParameter.js.map +1 -0
- package/dist/Parameter/KMeansParameter.d.ts +18 -0
- package/dist/Parameter/KMeansParameter.js +42 -0
- package/dist/Parameter/KMeansParameter.js.map +1 -0
- package/dist/Parameter/KnnParameter.d.ts +19 -0
- package/dist/Parameter/KnnParameter.js +37 -0
- package/dist/Parameter/KnnParameter.js.map +1 -0
- package/dist/Parameter/LinearPerceptronParameter.d.ts +41 -0
- package/dist/Parameter/LinearPerceptronParameter.js +66 -0
- package/dist/Parameter/LinearPerceptronParameter.js.map +1 -0
- package/dist/Parameter/MultiLayerPerceptronParameter.d.ts +30 -0
- package/dist/Parameter/MultiLayerPerceptronParameter.js +50 -0
- package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -0
- package/dist/Parameter/Parameter.d.ts +15 -0
- package/dist/Parameter/Parameter.js +33 -0
- package/dist/Parameter/Parameter.js.map +1 -0
- package/dist/Parameter/RandomForestParameter.d.ts +18 -0
- package/dist/Parameter/RandomForestParameter.js +37 -0
- package/dist/Parameter/RandomForestParameter.js.map +1 -0
- package/dist/Performance/ClassificationPerformance.d.ts +17 -0
- package/dist/Performance/ClassificationPerformance.js +36 -0
- package/dist/Performance/ClassificationPerformance.js.map +1 -0
- package/dist/Performance/ConfusionMatrix.d.ts +81 -0
- package/dist/Performance/ConfusionMatrix.js +178 -0
- package/dist/Performance/ConfusionMatrix.js.map +1 -0
- package/dist/Performance/DetailedClassificationPerformance.d.ts +17 -0
- package/dist/Performance/DetailedClassificationPerformance.js +35 -0
- package/dist/Performance/DetailedClassificationPerformance.js.map +1 -0
- package/dist/Performance/ExperimentPerformance.d.ts +88 -0
- package/dist/Performance/ExperimentPerformance.js +176 -0
- package/dist/Performance/ExperimentPerformance.js.map +1 -0
- package/dist/Performance/Performance.d.ts +15 -0
- package/dist/Performance/Performance.js +33 -0
- package/dist/Performance/Performance.js.map +1 -0
- package/dist/StatisticalTest/Combined5x2F.d.ts +7 -0
- package/dist/StatisticalTest/Combined5x2F.js +43 -0
- package/dist/StatisticalTest/Combined5x2F.js.map +1 -0
- package/dist/StatisticalTest/Combined5x2t.d.ts +7 -0
- package/dist/StatisticalTest/Combined5x2t.js +43 -0
- package/dist/StatisticalTest/Combined5x2t.js.map +1 -0
- package/dist/StatisticalTest/Paired5x2t.d.ts +7 -0
- package/dist/StatisticalTest/Paired5x2t.js +42 -0
- package/dist/StatisticalTest/Paired5x2t.js.map +1 -0
- package/dist/StatisticalTest/PairedTest.d.ts +6 -0
- package/dist/StatisticalTest/PairedTest.js +35 -0
- package/dist/StatisticalTest/PairedTest.js.map +1 -0
- package/dist/StatisticalTest/Pairedt.d.ts +7 -0
- package/dist/StatisticalTest/Pairedt.js +40 -0
- package/dist/StatisticalTest/Pairedt.js.map +1 -0
- package/dist/StatisticalTest/Sign.d.ts +8 -0
- package/dist/StatisticalTest/Sign.js +52 -0
- package/dist/StatisticalTest/Sign.js.map +1 -0
- package/dist/StatisticalTest/StatisticalTestResult.d.ts +9 -0
- package/dist/StatisticalTest/StatisticalTestResult.js +53 -0
- package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -0
- package/dist/StatisticalTest/StatisticalTestResultType.d.ts +7 -0
- package/dist/StatisticalTest/StatisticalTestResultType.js +22 -0
- package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -0
- package/index.js +100 -0
- package/package.json +30 -0
- package/source/Attribute/Attribute.ts +6 -0
- package/source/Attribute/AttributeType.ts +18 -0
- package/source/Attribute/BinaryAttribute.ts +14 -0
- package/source/Attribute/ContinuousAttribute.ts +53 -0
- package/source/Attribute/DiscreteAttribute.ts +46 -0
- package/source/Attribute/DiscreteIndexedAttribute.ts +54 -0
- package/source/Classifier/Bagging.ts +32 -0
- package/source/Classifier/C45.ts +30 -0
- package/source/Classifier/C45Stump.ts +19 -0
- package/source/Classifier/Classifier.ts +71 -0
- package/source/Classifier/DeepNetwork.ts +22 -0
- package/source/Classifier/Dummy.ts +19 -0
- package/source/Classifier/KMeans.ts +26 -0
- package/source/Classifier/Knn.ts +21 -0
- package/source/Classifier/Lda.ts +43 -0
- package/source/Classifier/LinearPerceptron.ts +23 -0
- package/source/Classifier/MultiLayerPerceptron.ts +23 -0
- package/source/Classifier/NaiveBayes.ts +62 -0
- package/source/Classifier/Qda.ts +42 -0
- package/source/Classifier/RandomClassifier.ts +22 -0
- package/source/Classifier/RandomForest.ts +29 -0
- package/source/DataSet/DataDefinition.ts +106 -0
- package/source/DataSet/DataSet.ts +279 -0
- package/source/DistanceMetric/DistanceMetric.ts +6 -0
- package/source/DistanceMetric/EuclidianDistance.ts +32 -0
- package/source/DistanceMetric/MahalanobisDistance.ts +33 -0
- package/source/Experiment/BootstrapRun.ts +37 -0
- package/source/Experiment/Experiment.ts +57 -0
- package/source/Experiment/KFoldRun.ts +44 -0
- package/source/Experiment/KFoldRunSeparateTest.ts +50 -0
- package/source/Experiment/MultipleRun.ts +7 -0
- package/source/Experiment/MxKFoldRun.ts +37 -0
- package/source/Experiment/MxKFoldRunSeparateTest.ts +40 -0
- package/source/Experiment/SingleRun.ts +7 -0
- package/source/Experiment/SingleRunWithK.ts +39 -0
- package/source/Experiment/StratifiedKFoldRun.ts +30 -0
- package/source/Experiment/StratifiedKFoldRunSeparateTest.ts +33 -0
- package/source/Experiment/StratifiedMxKFoldRun.ts +34 -0
- package/source/Experiment/StratifiedMxKFoldRunSeparateTest.ts +40 -0
- package/source/Experiment/StratifiedSingleRunWithK.ts +33 -0
- package/source/FeatureSelection/BackwardSelection.ts +28 -0
- package/source/FeatureSelection/FeatureSubSet.ts +82 -0
- package/source/FeatureSelection/FloatingSelection.ts +27 -0
- package/source/FeatureSelection/ForwardSelection.ts +27 -0
- package/source/FeatureSelection/SubSetSelection.ts +88 -0
- package/source/Filter/DiscreteToContinuous.ts +59 -0
- package/source/Filter/DiscreteToIndexed.ts +48 -0
- package/source/Filter/FeatureFilter.ts +31 -0
- package/source/Filter/LaryFilter.ts +54 -0
- package/source/Filter/LaryToBinary.ts +57 -0
- package/source/Filter/Normalize.ts +42 -0
- package/source/Filter/Pca.ts +104 -0
- package/source/Filter/TrainedFeatureFilter.ts +17 -0
- package/source/Instance/CompositeInstance.ts +53 -0
- package/source/Instance/Instance.ts +170 -0
- package/source/InstanceList/InstanceList.ts +519 -0
- package/source/InstanceList/InstanceListOfSameClass.ts +25 -0
- package/source/InstanceList/Partition.ts +131 -0
- package/source/Model/DecisionTree/DecisionCondition.ts +74 -0
- package/source/Model/DecisionTree/DecisionNode.ts +257 -0
- package/source/Model/DecisionTree/DecisionTree.ts +71 -0
- package/source/Model/DeepNetworkModel.ts +156 -0
- package/source/Model/DummyModel.ts +40 -0
- package/source/Model/GaussianModel.ts +58 -0
- package/source/Model/KMeansModel.ts +44 -0
- package/source/Model/KnnInstance.ts +27 -0
- package/source/Model/KnnModel.ts +78 -0
- package/source/Model/LdaModel.ts +39 -0
- package/source/Model/LinearPerceptronModel.ts +55 -0
- package/source/Model/Model.ts +22 -0
- package/source/Model/MultiLayerPerceptronModel.ts +95 -0
- package/source/Model/NaiveBayesModel.ts +89 -0
- package/source/Model/NeuralNetworkModel.ts +187 -0
- package/source/Model/QdaModel.ts +39 -0
- package/source/Model/RandomModel.ts +44 -0
- package/source/Model/TreeEnsembleModel.ts +43 -0
- package/source/Model/ValidatedModel.ts +23 -0
- package/source/Parameter/ActivationFunction.ts +3 -0
- package/source/Parameter/BaggingParameter.ts +26 -0
- package/source/Parameter/C45Parameter.ts +38 -0
- package/source/Parameter/DeepNetworkParameter.ts +59 -0
- package/source/Parameter/KMeansParameter.ts +33 -0
- package/source/Parameter/KnnParameter.ts +28 -0
- package/source/Parameter/LinearPerceptronParameter.ts +66 -0
- package/source/Parameter/MultiLayerPerceptronParameter.ts +49 -0
- package/source/Parameter/Parameter.ts +22 -0
- package/source/Parameter/RandomForestParameter.ts +27 -0
- package/source/Performance/ClassificationPerformance.ts +26 -0
- package/source/Performance/ConfusionMatrix.ts +175 -0
- package/source/Performance/DetailedClassificationPerformance.ts +26 -0
- package/source/Performance/ExperimentPerformance.ts +175 -0
- package/source/Performance/Performance.ts +22 -0
- package/source/StatisticalTest/Combined5x2F.ts +33 -0
- package/source/StatisticalTest/Combined5x2t.ts +33 -0
- package/source/StatisticalTest/Paired5x2t.ts +32 -0
- package/source/StatisticalTest/PairedTest.ts +24 -0
- package/source/StatisticalTest/Pairedt.ts +30 -0
- package/source/StatisticalTest/Sign.ts +41 -0
- package/source/StatisticalTest/StatisticalTestResult.ts +42 -0
- package/source/StatisticalTest/StatisticalTestResultType.ts +6 -0
- package/source/tsconfig.json +13 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./InstanceList", "./InstanceListOfSameClass"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Partition = void 0;
|
|
13
|
+
const InstanceList_1 = require("./InstanceList");
|
|
14
|
+
const InstanceListOfSameClass_1 = require("./InstanceListOfSameClass");
|
|
15
|
+
class Partition {
|
|
16
|
+
constructor(instanceList, attributeIndex, stratifiedOrValue) {
|
|
17
|
+
this.multiList = new Array();
|
|
18
|
+
if (instanceList != undefined) {
|
|
19
|
+
if (attributeIndex == undefined) {
|
|
20
|
+
let classLabels = instanceList.getDistinctClassLabels();
|
|
21
|
+
for (let classLabel of classLabels) {
|
|
22
|
+
this.add(new InstanceListOfSameClass_1.InstanceListOfSameClass(classLabel));
|
|
23
|
+
}
|
|
24
|
+
for (let instance of instanceList.getInstances()) {
|
|
25
|
+
this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (stratifiedOrValue == undefined) {
|
|
30
|
+
let valueList = instanceList.getAttributeValueList(attributeIndex);
|
|
31
|
+
for (let value of valueList) {
|
|
32
|
+
this.add(new InstanceList_1.InstanceList());
|
|
33
|
+
}
|
|
34
|
+
for (let instance of instanceList.getInstances()) {
|
|
35
|
+
this.get(valueList.indexOf(instance.getAttribute(attributeIndex).getValue())).add(instance);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (typeof stratifiedOrValue == "boolean") {
|
|
40
|
+
this.add(new InstanceList_1.InstanceList());
|
|
41
|
+
this.add(new InstanceList_1.InstanceList());
|
|
42
|
+
if (stratifiedOrValue) {
|
|
43
|
+
let distribution = instanceList.classDistribution();
|
|
44
|
+
let counts = new Array(distribution.size).fill(0);
|
|
45
|
+
let randomArray = new Array();
|
|
46
|
+
for (let i = 0; i < instanceList.size(); i++) {
|
|
47
|
+
randomArray.push(i);
|
|
48
|
+
}
|
|
49
|
+
for (let i = 0; i < instanceList.size(); i++) {
|
|
50
|
+
let instance = instanceList.get(randomArray[i]);
|
|
51
|
+
let classIndex = distribution.getIndex(instance.getClassLabel());
|
|
52
|
+
let ratio = attributeIndex;
|
|
53
|
+
if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
|
|
54
|
+
this.get(0).add(instance);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.get(1).add(instance);
|
|
58
|
+
}
|
|
59
|
+
counts[classIndex]++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
for (let i = 0; i < instanceList.size(); i++) {
|
|
64
|
+
let instance = instanceList.get(i);
|
|
65
|
+
let ratio = attributeIndex;
|
|
66
|
+
if (i < instanceList.size() * ratio) {
|
|
67
|
+
this.get(0).add(instance);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.get(1).add(instance);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.add(new InstanceList_1.InstanceList());
|
|
77
|
+
this.add(new InstanceList_1.InstanceList());
|
|
78
|
+
if (Number.isInteger(stratifiedOrValue)) {
|
|
79
|
+
for (let instance of instanceList.getInstances()) {
|
|
80
|
+
if (instance.getAttribute(attributeIndex).getIndex() == stratifiedOrValue) {
|
|
81
|
+
this.get(0).add(instance);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.get(1).add(instance);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
for (let instance of instanceList.getInstances()) {
|
|
90
|
+
if (instance.getAttribute(attributeIndex).getValue() <= stratifiedOrValue) {
|
|
91
|
+
this.get(0).add(instance);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.get(1).add(instance);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Adds given instance list to the list of instance lists.
|
|
105
|
+
*
|
|
106
|
+
* @param list Instance list to add.
|
|
107
|
+
*/
|
|
108
|
+
add(list) {
|
|
109
|
+
this.multiList.push(list);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns the size of the list of instance lists.
|
|
113
|
+
*
|
|
114
|
+
* @return The size of the list of instance lists.
|
|
115
|
+
*/
|
|
116
|
+
size() {
|
|
117
|
+
return this.multiList.length;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the corresponding instance list at given index of list of instance lists.
|
|
121
|
+
*
|
|
122
|
+
* @param index Index of the instance list.
|
|
123
|
+
* @return Instance list at given index of list of instance lists.
|
|
124
|
+
*/
|
|
125
|
+
get(index) {
|
|
126
|
+
return this.multiList[index];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns the instances of the items at the list of instance lists.
|
|
130
|
+
*
|
|
131
|
+
* @return Instances of the items at the list of instance lists.
|
|
132
|
+
*/
|
|
133
|
+
getLists() {
|
|
134
|
+
let result = new Array(this.multiList.length);
|
|
135
|
+
for (let i = 0; i < this.multiList.length; i++) {
|
|
136
|
+
result.push(this.multiList[i].getInstances());
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.Partition = Partition;
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=Partition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Partition.js","sourceRoot":"","sources":["../../source/InstanceList/Partition.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,iDAA4C;IAC5C,uEAAkE;IAMlE,MAAa,SAAS;QAIlB,YAAY,YAA2B,EAAE,cAAuB,EAAE,iBAAuB;YAFjF,cAAS,GAAwB,IAAI,KAAK,EAAgB,CAAA;YAG9D,IAAI,YAAY,IAAI,SAAS,EAAC;gBAC1B,IAAI,cAAc,IAAI,SAAS,EAAC;oBAC5B,IAAI,WAAW,GAAG,YAAY,CAAC,sBAAsB,EAAE,CAAC;oBACxD,KAAK,IAAI,UAAU,IAAI,WAAW,EAAC;wBAC/B,IAAI,CAAC,GAAG,CAAC,IAAI,iDAAuB,CAAC,UAAU,CAAC,CAAC,CAAC;qBACrD;oBACD,KAAK,IAAI,QAAQ,IAAI,YAAY,CAAC,YAAY,EAAE,EAAE;wBAC9C,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;qBACzE;iBACJ;qBAAM;oBACH,IAAI,iBAAiB,IAAI,SAAS,EAAC;wBAC/B,IAAI,SAAS,GAAG,YAAY,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;wBACnE,KAAK,IAAI,KAAK,IAAI,SAAS,EAAE;4BACzB,IAAI,CAAC,GAAG,CAAC,IAAI,2BAAY,EAAE,CAAC,CAAC;yBAChC;wBACD,KAAK,IAAI,QAAQ,IAAI,YAAY,CAAC,YAAY,EAAE,EAAE;4BAC9C,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAsB,QA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AQ,IAAI,YAAY,CAAC,YAAY,EAAE,EAAE;oCAC9C,IAA2B,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,IAAI,iBAAiB,EAAE;wCAC/F,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;qCAC7B;yCAAM;wCACH,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;qCAC7B;iCACJ;6BACJ;yBACJ;qBACJ;iBACJ;aACJ;QACL,CAAC;QAED;;;;WAIG;QACH,GAAG,CAAC,IAAkB;YAClB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;QAED;;;;WAIG;QACH,IAAI;YACA,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAA;QAChC,CAAC;QAED;;;;;WAKG;QACH,GAAG,CAAC,KAAa;YACb,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;QAED;;;;WAIG;QACH,QAAQ;YACJ,IAAI,MAAM,GAAG,IAAI,KAAK,CAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC/D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC5C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;aACjD;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;KAEJ;IA3HD,8BA2HC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Attribute } from "../../Attribute/Attribute";
|
|
2
|
+
import { Instance } from "../../Instance/Instance";
|
|
3
|
+
export declare class DecisionCondition {
|
|
4
|
+
private attributeIndex;
|
|
5
|
+
private comparison;
|
|
6
|
+
private value;
|
|
7
|
+
/**
|
|
8
|
+
* A constructor that sets attributeIndex, comparison and {@link Attribute} value.
|
|
9
|
+
*
|
|
10
|
+
* @param attributeIndex Integer number that shows attribute index.
|
|
11
|
+
* @param value The value of the {@link Attribute}.
|
|
12
|
+
* @param comparison Comparison character.
|
|
13
|
+
*/
|
|
14
|
+
constructor(attributeIndex: number, value: Attribute, comparison?: string);
|
|
15
|
+
getAttributeIndex(): number;
|
|
16
|
+
getValue(): Attribute;
|
|
17
|
+
/**
|
|
18
|
+
* The satisfy method takes an {@link Instance} as an input.
|
|
19
|
+
* <p>
|
|
20
|
+
* If defined {@link Attribute} value is a {@link DiscreteIndexedAttribute} it compares the index of {@link Attribute} of instance at the
|
|
21
|
+
* attributeIndex and the index of {@link Attribute} value and returns the result.
|
|
22
|
+
* <p>
|
|
23
|
+
* If defined {@link Attribute} value is a {@link DiscreteAttribute} it compares the value of {@link Attribute} of instance at the
|
|
24
|
+
* attributeIndex and the value of {@link Attribute} value and returns the result.
|
|
25
|
+
* <p>
|
|
26
|
+
* If defined {@link Attribute} value is a {@link ContinuousAttribute} it compares the value of {@link Attribute} of instance at the
|
|
27
|
+
* attributeIndex and the value of {@link Attribute} value and returns the result according to the comparison character whether it is
|
|
28
|
+
* less than or greater than signs.
|
|
29
|
+
*
|
|
30
|
+
* @param instance Instance to compare.
|
|
31
|
+
* @return True if gicen instance satisfies the conditions.
|
|
32
|
+
*/
|
|
33
|
+
satisfy(instance: Instance): boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../../Attribute/DiscreteIndexedAttribute", "../../Attribute/DiscreteAttribute", "../../Attribute/ContinuousAttribute"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DecisionCondition = void 0;
|
|
13
|
+
const DiscreteIndexedAttribute_1 = require("../../Attribute/DiscreteIndexedAttribute");
|
|
14
|
+
const DiscreteAttribute_1 = require("../../Attribute/DiscreteAttribute");
|
|
15
|
+
const ContinuousAttribute_1 = require("../../Attribute/ContinuousAttribute");
|
|
16
|
+
class DecisionCondition {
|
|
17
|
+
/**
|
|
18
|
+
* A constructor that sets attributeIndex, comparison and {@link Attribute} value.
|
|
19
|
+
*
|
|
20
|
+
* @param attributeIndex Integer number that shows attribute index.
|
|
21
|
+
* @param value The value of the {@link Attribute}.
|
|
22
|
+
* @param comparison Comparison character.
|
|
23
|
+
*/
|
|
24
|
+
constructor(attributeIndex, value, comparison) {
|
|
25
|
+
this.attributeIndex = -1;
|
|
26
|
+
this.comparison = undefined;
|
|
27
|
+
this.attributeIndex = attributeIndex;
|
|
28
|
+
this.comparison = comparison;
|
|
29
|
+
this.value = value;
|
|
30
|
+
}
|
|
31
|
+
getAttributeIndex() {
|
|
32
|
+
return this.attributeIndex;
|
|
33
|
+
}
|
|
34
|
+
getValue() {
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The satisfy method takes an {@link Instance} as an input.
|
|
39
|
+
* <p>
|
|
40
|
+
* If defined {@link Attribute} value is a {@link DiscreteIndexedAttribute} it compares the index of {@link Attribute} of instance at the
|
|
41
|
+
* attributeIndex and the index of {@link Attribute} value and returns the result.
|
|
42
|
+
* <p>
|
|
43
|
+
* If defined {@link Attribute} value is a {@link DiscreteAttribute} it compares the value of {@link Attribute} of instance at the
|
|
44
|
+
* attributeIndex and the value of {@link Attribute} value and returns the result.
|
|
45
|
+
* <p>
|
|
46
|
+
* If defined {@link Attribute} value is a {@link ContinuousAttribute} it compares the value of {@link Attribute} of instance at the
|
|
47
|
+
* attributeIndex and the value of {@link Attribute} value and returns the result according to the comparison character whether it is
|
|
48
|
+
* less than or greater than signs.
|
|
49
|
+
*
|
|
50
|
+
* @param instance Instance to compare.
|
|
51
|
+
* @return True if gicen instance satisfies the conditions.
|
|
52
|
+
*/
|
|
53
|
+
satisfy(instance) {
|
|
54
|
+
if (this.value instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
|
|
55
|
+
if (this.value.getIndex() != -1) {
|
|
56
|
+
return instance.getAttribute(this.attributeIndex).getIndex() == this.value.getIndex();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (this.value instanceof DiscreteAttribute_1.DiscreteAttribute) {
|
|
64
|
+
return (instance.getAttribute(this.attributeIndex).getValue() == this.value.getValue());
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (this.value instanceof ContinuousAttribute_1.ContinuousAttribute) {
|
|
68
|
+
if (this.comparison == "<") {
|
|
69
|
+
return instance.getAttribute(this.attributeIndex).getValue() <= this.value.getValue();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (this.comparison == ">") {
|
|
73
|
+
return instance.getAttribute(this.attributeIndex).getValue() > this.value.getValue();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.DecisionCondition = DecisionCondition;
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=DecisionCondition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecisionCondition.js","sourceRoot":"","sources":["../../../source/Model/DecisionTree/DecisionCondition.ts"],"names":[],"mappings":";;;;;;;;;;;;IAEA,uFAAkF;IAClF,yEAAoE;IACpE,6EAAwE;IAExE,MAAa,iBAAiB;QAM1B;;;;;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,CAAC,UAAU,IAAI,GAAG,EAAE;gCACxB,OAA8B,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,GAA0B,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC;6BACxI;yBACJ;qBACJ;iBACJ;aACJ;YACD,OAAO,KAAK,CAAC;QACjB,CAAC;KACJ;IAnED,8CAmEC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { InstanceList } from "../../InstanceList/InstanceList";
|
|
2
|
+
import { DecisionCondition } from "./DecisionCondition";
|
|
3
|
+
import { RandomForestParameter } from "../../Parameter/RandomForestParameter";
|
|
4
|
+
import { Instance } from "../../Instance/Instance";
|
|
5
|
+
export declare class DecisionNode {
|
|
6
|
+
children: Array<DecisionNode>;
|
|
7
|
+
private EPSILON;
|
|
8
|
+
private readonly data;
|
|
9
|
+
private readonly classLabel;
|
|
10
|
+
leaf: boolean;
|
|
11
|
+
private condition;
|
|
12
|
+
/**
|
|
13
|
+
* The DecisionNode method takes {@link InstanceList} data as input, and then it sets the class label parameter by finding
|
|
14
|
+
* the most occurred class label of given data, it then gets distinct class labels as class labels ArrayList. Later, it adds ordered
|
|
15
|
+
* indices to the indexList and shuffles them randomly. Then, it gets the class distribution of given data and finds the best entropy value
|
|
16
|
+
* of these class distribution.
|
|
17
|
+
* <p>
|
|
18
|
+
* If an attribute of given data is {@link DiscreteIndexedAttribute}, it creates a Distribution according to discrete indexed attribute class distribution
|
|
19
|
+
* and finds the entropy. If it is better than the last best entropy it reassigns the best entropy, best attribute and best split value according to
|
|
20
|
+
* the newly founded best entropy's index. At the end, it also adds new distribution to the class distribution .
|
|
21
|
+
* <p>
|
|
22
|
+
* If an attribute of given data is {@link DiscreteAttribute}, it directly finds the entropy. If it is better than the last best entropy it
|
|
23
|
+
* reassigns the best entropy, best attribute and best split value according to the newly founded best entropy's index.
|
|
24
|
+
* <p>
|
|
25
|
+
* If an attribute of given data is {@link ContinuousAttribute}, it creates two distributions; left and right according to class distribution
|
|
26
|
+
* and discrete distribution respectively, and finds the entropy. If it is better than the last best entropy it reassigns the best entropy,
|
|
27
|
+
* best attribute and best split value according to the newly founded best entropy's index. At the end, it also adds new distribution to
|
|
28
|
+
* the right distribution and removes from left distribution .
|
|
29
|
+
*
|
|
30
|
+
* @param data {@link InstanceList} input.
|
|
31
|
+
* @param condition {@link DecisionCondition} to check.
|
|
32
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
33
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
34
|
+
*/
|
|
35
|
+
constructor(data: InstanceList, condition: DecisionCondition, parameter: RandomForestParameter, isStump: boolean);
|
|
36
|
+
/**
|
|
37
|
+
* The entropyForDiscreteAttribute method takes an attributeIndex and creates an ArrayList of DiscreteDistribution.
|
|
38
|
+
* Then loops through the distributions and calculates the total entropy.
|
|
39
|
+
*
|
|
40
|
+
* @param attributeIndex Index of the attribute.
|
|
41
|
+
* @return Total entropy for the discrete attribute.
|
|
42
|
+
*/
|
|
43
|
+
private entropyForDiscreteAttribute;
|
|
44
|
+
/**
|
|
45
|
+
* The createChildrenForDiscreteIndexed method creates an ArrayList of DecisionNodes as children and a partition with respect to
|
|
46
|
+
* indexed attribute.
|
|
47
|
+
*
|
|
48
|
+
* @param attributeIndex Index of the attribute.
|
|
49
|
+
* @param attributeValue Value of the attribute.
|
|
50
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
51
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
52
|
+
*/
|
|
53
|
+
private createChildrenForDiscreteIndexed;
|
|
54
|
+
/**
|
|
55
|
+
* The createChildrenForDiscrete method creates an ArrayList of values, a partition with respect to attributes and an ArrayList
|
|
56
|
+
* of DecisionNodes as children.
|
|
57
|
+
*
|
|
58
|
+
* @param attributeIndex Index of the attribute.
|
|
59
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
60
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
61
|
+
*/
|
|
62
|
+
private createChildrenForDiscrete;
|
|
63
|
+
/**
|
|
64
|
+
* The createChildrenForContinuous method creates an ArrayList of DecisionNodes as children and a partition with respect to
|
|
65
|
+
* continuous attribute and the given split value.
|
|
66
|
+
*
|
|
67
|
+
* @param attributeIndex Index of the attribute.
|
|
68
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
69
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
70
|
+
* @param splitValue Split value is used for partitioning.
|
|
71
|
+
*/
|
|
72
|
+
private createChildrenForContinuous;
|
|
73
|
+
/**
|
|
74
|
+
* The predict method takes an {@link Instance} as input and performs prediction on the DecisionNodes and returns the prediction
|
|
75
|
+
* for that instance.
|
|
76
|
+
*
|
|
77
|
+
* @param instance Instance to make prediction.
|
|
78
|
+
* @return The prediction for given instance.
|
|
79
|
+
*/
|
|
80
|
+
predict(instance: Instance): string;
|
|
81
|
+
predictProbabilityDistribution(instance: Instance): Map<string, number>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./DecisionCondition", "../Model", "../../Attribute/DiscreteIndexedAttribute", "../../Attribute/DiscreteAttribute", "../../Attribute/ContinuousAttribute", "nlptoolkit-math/dist/DiscreteDistribution", "../../InstanceList/Partition", "../../Instance/CompositeInstance"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DecisionNode = void 0;
|
|
13
|
+
const DecisionCondition_1 = require("./DecisionCondition");
|
|
14
|
+
const Model_1 = require("../Model");
|
|
15
|
+
const DiscreteIndexedAttribute_1 = require("../../Attribute/DiscreteIndexedAttribute");
|
|
16
|
+
const DiscreteAttribute_1 = require("../../Attribute/DiscreteAttribute");
|
|
17
|
+
const ContinuousAttribute_1 = require("../../Attribute/ContinuousAttribute");
|
|
18
|
+
const DiscreteDistribution_1 = require("nlptoolkit-math/dist/DiscreteDistribution");
|
|
19
|
+
const Partition_1 = require("../../InstanceList/Partition");
|
|
20
|
+
const CompositeInstance_1 = require("../../Instance/CompositeInstance");
|
|
21
|
+
class DecisionNode {
|
|
22
|
+
/**
|
|
23
|
+
* The DecisionNode method takes {@link InstanceList} data as input, and then it sets the class label parameter by finding
|
|
24
|
+
* the most occurred class label of given data, it then gets distinct class labels as class labels ArrayList. Later, it adds ordered
|
|
25
|
+
* indices to the indexList and shuffles them randomly. Then, it gets the class distribution of given data and finds the best entropy value
|
|
26
|
+
* of these class distribution.
|
|
27
|
+
* <p>
|
|
28
|
+
* If an attribute of given data is {@link DiscreteIndexedAttribute}, it creates a Distribution according to discrete indexed attribute class distribution
|
|
29
|
+
* and finds the entropy. If it is better than the last best entropy it reassigns the best entropy, best attribute and best split value according to
|
|
30
|
+
* the newly founded best entropy's index. At the end, it also adds new distribution to the class distribution .
|
|
31
|
+
* <p>
|
|
32
|
+
* If an attribute of given data is {@link DiscreteAttribute}, it directly finds the entropy. If it is better than the last best entropy it
|
|
33
|
+
* reassigns the best entropy, best attribute and best split value according to the newly founded best entropy's index.
|
|
34
|
+
* <p>
|
|
35
|
+
* If an attribute of given data is {@link ContinuousAttribute}, it creates two distributions; left and right according to class distribution
|
|
36
|
+
* and discrete distribution respectively, and finds the entropy. If it is better than the last best entropy it reassigns the best entropy,
|
|
37
|
+
* best attribute and best split value according to the newly founded best entropy's index. At the end, it also adds new distribution to
|
|
38
|
+
* the right distribution and removes from left distribution .
|
|
39
|
+
*
|
|
40
|
+
* @param data {@link InstanceList} input.
|
|
41
|
+
* @param condition {@link DecisionCondition} to check.
|
|
42
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
43
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
44
|
+
*/
|
|
45
|
+
constructor(data, condition, parameter, isStump) {
|
|
46
|
+
this.children = undefined;
|
|
47
|
+
this.EPSILON = 0.0000000001;
|
|
48
|
+
this.data = undefined;
|
|
49
|
+
this.classLabel = undefined;
|
|
50
|
+
this.leaf = false;
|
|
51
|
+
this.condition = undefined;
|
|
52
|
+
let bestAttribute = -1;
|
|
53
|
+
let bestSplitValue = 0;
|
|
54
|
+
this.condition = condition;
|
|
55
|
+
this.data = data;
|
|
56
|
+
this.classLabel = Model_1.Model.getMaximum(data.getClassLabels());
|
|
57
|
+
this.leaf = true;
|
|
58
|
+
let classLabels = data.getDistinctClassLabels();
|
|
59
|
+
if (classLabels.length == 1) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (isStump && condition != null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let indexList = new Array();
|
|
66
|
+
for (let i = 0; i < data.get(0).attributeSize(); i++) {
|
|
67
|
+
indexList.push(i);
|
|
68
|
+
}
|
|
69
|
+
let size;
|
|
70
|
+
if (parameter != undefined && parameter.getAttributeSubsetSize() < data.get(0).attributeSize()) {
|
|
71
|
+
size = parameter.getAttributeSubsetSize();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
size = data.get(0).attributeSize();
|
|
75
|
+
}
|
|
76
|
+
let classDistribution = data.classDistribution();
|
|
77
|
+
let bestEntropy = data.classDistribution().entropy();
|
|
78
|
+
for (let j = 0; j < size; j++) {
|
|
79
|
+
let index = indexList[j];
|
|
80
|
+
if (data.get(0).getAttribute(index) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
|
|
81
|
+
for (let k = 0; k < data.get(0).getAttribute(index).getMaxIndex(); k++) {
|
|
82
|
+
let distribution = data.discreteIndexedAttributeClassDistribution(index, k);
|
|
83
|
+
if (distribution.getSum() > 0) {
|
|
84
|
+
classDistribution.removeDistribution(distribution);
|
|
85
|
+
let entropy = (classDistribution.entropy() * classDistribution.getSum() + distribution.entropy() * distribution.getSum()) / data.size();
|
|
86
|
+
if (entropy + this.EPSILON < bestEntropy) {
|
|
87
|
+
bestEntropy = entropy;
|
|
88
|
+
bestAttribute = index;
|
|
89
|
+
bestSplitValue = k;
|
|
90
|
+
}
|
|
91
|
+
classDistribution.addDistribution(distribution);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (data.get(0).getAttribute(index) instanceof DiscreteAttribute_1.DiscreteAttribute) {
|
|
97
|
+
let entropy = this.entropyForDiscreteAttribute(index);
|
|
98
|
+
if (entropy + this.EPSILON < bestEntropy) {
|
|
99
|
+
bestEntropy = entropy;
|
|
100
|
+
bestAttribute = index;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (data.get(0).getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
|
|
105
|
+
data.sort(index);
|
|
106
|
+
let previousValue = Number.NEGATIVE_INFINITY;
|
|
107
|
+
let leftDistribution = data.classDistribution();
|
|
108
|
+
let rightDistribution = new DiscreteDistribution_1.DiscreteDistribution();
|
|
109
|
+
for (let k = 0; k < data.size(); k++) {
|
|
110
|
+
let instance = data.get(k);
|
|
111
|
+
if (k == 0) {
|
|
112
|
+
previousValue = instance.getAttribute(index).getValue();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (instance.getAttribute(index).getValue() != previousValue) {
|
|
116
|
+
let splitValue = (previousValue + instance.getAttribute(index).getValue()) / 2;
|
|
117
|
+
previousValue = instance.getAttribute(index).getValue();
|
|
118
|
+
let entropy = (leftDistribution.getSum() / data.size()) * leftDistribution.entropy() + (rightDistribution.getSum() / data.size()) * rightDistribution.entropy();
|
|
119
|
+
if (entropy + this.EPSILON < bestEntropy) {
|
|
120
|
+
bestEntropy = entropy;
|
|
121
|
+
bestSplitValue = splitValue;
|
|
122
|
+
bestAttribute = index;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
leftDistribution.removeItem(instance.getClassLabel());
|
|
127
|
+
rightDistribution.addItem(instance.getClassLabel());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (bestAttribute != -1) {
|
|
134
|
+
this.leaf = false;
|
|
135
|
+
if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
|
|
136
|
+
this.createChildrenForDiscreteIndexed(bestAttribute, bestSplitValue, parameter, isStump);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteAttribute_1.DiscreteAttribute) {
|
|
140
|
+
this.createChildrenForDiscrete(bestAttribute, parameter, isStump);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
if (data.get(0).getAttribute(bestAttribute) instanceof ContinuousAttribute_1.ContinuousAttribute) {
|
|
144
|
+
this.createChildrenForContinuous(bestAttribute, bestSplitValue, parameter, isStump);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The entropyForDiscreteAttribute method takes an attributeIndex and creates an ArrayList of DiscreteDistribution.
|
|
152
|
+
* Then loops through the distributions and calculates the total entropy.
|
|
153
|
+
*
|
|
154
|
+
* @param attributeIndex Index of the attribute.
|
|
155
|
+
* @return Total entropy for the discrete attribute.
|
|
156
|
+
*/
|
|
157
|
+
entropyForDiscreteAttribute(attributeIndex) {
|
|
158
|
+
let sum = 0.0;
|
|
159
|
+
let distributions = this.data.attributeClassDistribution(attributeIndex);
|
|
160
|
+
for (let distribution of distributions) {
|
|
161
|
+
sum += (distribution.getSum() / this.data.size()) * distribution.entropy();
|
|
162
|
+
}
|
|
163
|
+
return sum;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The createChildrenForDiscreteIndexed method creates an ArrayList of DecisionNodes as children and a partition with respect to
|
|
167
|
+
* indexed attribute.
|
|
168
|
+
*
|
|
169
|
+
* @param attributeIndex Index of the attribute.
|
|
170
|
+
* @param attributeValue Value of the attribute.
|
|
171
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
172
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
173
|
+
*/
|
|
174
|
+
createChildrenForDiscreteIndexed(attributeIndex, attributeValue, parameter, isStump) {
|
|
175
|
+
let childrenData = new Partition_1.Partition(this.data, attributeIndex, attributeValue);
|
|
176
|
+
this.children = new Array();
|
|
177
|
+
this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute("", attributeValue, this.data.get(0).getAttribute(attributeIndex).getMaxIndex())), parameter, isStump));
|
|
178
|
+
this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute("", -1, this.data.get(0).getAttribute(attributeIndex).getMaxIndex())), parameter, isStump));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The createChildrenForDiscrete method creates an ArrayList of values, a partition with respect to attributes and an ArrayList
|
|
182
|
+
* of DecisionNodes as children.
|
|
183
|
+
*
|
|
184
|
+
* @param attributeIndex Index of the attribute.
|
|
185
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
186
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
187
|
+
*/
|
|
188
|
+
createChildrenForDiscrete(attributeIndex, parameter, isStump) {
|
|
189
|
+
let valueList = this.data.getAttributeValueList(attributeIndex);
|
|
190
|
+
let childrenData = new Partition_1.Partition(this.data, attributeIndex);
|
|
191
|
+
this.children = new Array();
|
|
192
|
+
for (let i = 0; i < valueList.length; i++) {
|
|
193
|
+
this.children.push(new DecisionNode(childrenData.get(i), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteAttribute_1.DiscreteAttribute(valueList[i])), parameter, isStump));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The createChildrenForContinuous method creates an ArrayList of DecisionNodes as children and a partition with respect to
|
|
198
|
+
* continuous attribute and the given split value.
|
|
199
|
+
*
|
|
200
|
+
* @param attributeIndex Index of the attribute.
|
|
201
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
202
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
203
|
+
* @param splitValue Split value is used for partitioning.
|
|
204
|
+
*/
|
|
205
|
+
createChildrenForContinuous(attributeIndex, splitValue, parameter, isStump) {
|
|
206
|
+
let childrenData = new Partition_1.Partition(this.data, attributeIndex, splitValue);
|
|
207
|
+
this.children = new Array();
|
|
208
|
+
this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition_1.DecisionCondition(attributeIndex, new ContinuousAttribute_1.ContinuousAttribute(splitValue), "<"), parameter, isStump));
|
|
209
|
+
this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition_1.DecisionCondition(attributeIndex, new ContinuousAttribute_1.ContinuousAttribute(splitValue), ">"), parameter, isStump));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The predict method takes an {@link Instance} as input and performs prediction on the DecisionNodes and returns the prediction
|
|
213
|
+
* for that instance.
|
|
214
|
+
*
|
|
215
|
+
* @param instance Instance to make prediction.
|
|
216
|
+
* @return The prediction for given instance.
|
|
217
|
+
*/
|
|
218
|
+
predict(instance) {
|
|
219
|
+
if (instance instanceof CompositeInstance_1.CompositeInstance) {
|
|
220
|
+
let possibleClassLabels = instance.getPossibleClassLabels();
|
|
221
|
+
let distribution = this.data.classDistribution();
|
|
222
|
+
let predictedClass = distribution.getMaxItem(possibleClassLabels);
|
|
223
|
+
if (this.leaf) {
|
|
224
|
+
return predictedClass;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
for (let node of this.children) {
|
|
228
|
+
if (node.condition.satisfy(instance)) {
|
|
229
|
+
let childPrediction = node.predict(instance);
|
|
230
|
+
if (childPrediction != undefined) {
|
|
231
|
+
return childPrediction;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
return predictedClass;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return predictedClass;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (this.leaf) {
|
|
243
|
+
return this.classLabel;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
for (let node of this.children) {
|
|
247
|
+
if (node.condition.satisfy(instance)) {
|
|
248
|
+
return node.predict(instance);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return this.classLabel;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
predictProbabilityDistribution(instance) {
|
|
256
|
+
if (this.leaf) {
|
|
257
|
+
return this.data.classDistribution().getProbabilityDistribution();
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
for (let node of this.children) {
|
|
261
|
+
if (node.condition.satisfy(instance)) {
|
|
262
|
+
return node.predictProbabilityDistribution(instance);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return this.data.classDistribution().getProbabilityDistribution();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.DecisionNode = DecisionNode;
|
|
270
|
+
});
|
|
271
|
+
//# sourceMappingURL=DecisionNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecisionNode.js","sourceRoot":"","sources":["../../../source/Model/DecisionTree/DecisionNode.ts"],"names":[],"mappings":";;;;;;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