nlptoolkit-classification 1.0.7 → 1.0.9
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 +1 -0
- package/dist/Attribute/Attribute.js +6 -16
- package/dist/Attribute/Attribute.js.map +1 -1
- package/dist/Attribute/AttributeType.js +22 -32
- package/dist/Attribute/AttributeType.js.map +1 -1
- package/dist/Attribute/BinaryAttribute.js +14 -24
- package/dist/Attribute/BinaryAttribute.js.map +1 -1
- package/dist/Attribute/ContinuousAttribute.js +46 -55
- package/dist/Attribute/ContinuousAttribute.js.map +1 -1
- package/dist/Attribute/DiscreteAttribute.d.ts +1 -1
- package/dist/Attribute/DiscreteAttribute.js +38 -48
- package/dist/Attribute/DiscreteAttribute.js.map +1 -1
- package/dist/Attribute/DiscreteIndexedAttribute.d.ts +2 -2
- package/dist/Attribute/DiscreteIndexedAttribute.js +47 -55
- package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -1
- package/dist/DataSet/DataDefinition.d.ts +11 -0
- package/dist/DataSet/DataDefinition.js +115 -112
- package/dist/DataSet/DataDefinition.js.map +1 -1
- package/dist/DataSet/DataSet.js +268 -245
- package/dist/DataSet/DataSet.js.map +1 -1
- package/dist/DistanceMetric/DistanceMetric.js +2 -12
- package/dist/DistanceMetric/EuclidianDistance.js +27 -37
- package/dist/DistanceMetric/EuclidianDistance.js.map +1 -1
- package/dist/DistanceMetric/MahalanobisDistance.js +27 -36
- package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -1
- package/dist/Experiment/BootstrapRun.js +31 -40
- package/dist/Experiment/BootstrapRun.js.map +1 -1
- package/dist/Experiment/Experiment.d.ts +7 -7
- package/dist/Experiment/Experiment.js +46 -53
- package/dist/Experiment/Experiment.js.map +1 -1
- package/dist/Experiment/KFoldRun.d.ts +17 -2
- package/dist/Experiment/KFoldRun.js +45 -39
- package/dist/Experiment/KFoldRun.js.map +1 -1
- package/dist/Experiment/KFoldRunSeparateTest.d.ts +13 -2
- package/dist/Experiment/KFoldRunSeparateTest.js +48 -47
- package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/MultipleRun.js +2 -12
- package/dist/Experiment/MxKFoldRun.js +31 -40
- package/dist/Experiment/MxKFoldRun.js.map +1 -1
- package/dist/Experiment/MxKFoldRunSeparateTest.js +35 -44
- package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/SingleRun.js +2 -12
- package/dist/Experiment/SingleRunWithK.d.ts +18 -3
- package/dist/Experiment/SingleRunWithK.js +39 -33
- package/dist/Experiment/SingleRunWithK.js.map +1 -1
- package/dist/Experiment/StratifiedKFoldRun.js +26 -36
- package/dist/Experiment/StratifiedKFoldRun.js.map +1 -1
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +30 -40
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/StratifiedMxKFoldRun.js +29 -39
- package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -1
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +34 -43
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/StratifiedSingleRunWithK.js +27 -36
- package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -1
- package/dist/FeatureSelection/BackwardSelection.js +26 -36
- package/dist/FeatureSelection/BackwardSelection.js.map +1 -1
- package/dist/FeatureSelection/FeatureSubSet.js +72 -82
- package/dist/FeatureSelection/FeatureSubSet.js.map +1 -1
- package/dist/FeatureSelection/FloatingSelection.js +25 -35
- package/dist/FeatureSelection/FloatingSelection.js.map +1 -1
- package/dist/FeatureSelection/ForwardSelection.js +25 -35
- package/dist/FeatureSelection/ForwardSelection.js.map +1 -1
- package/dist/FeatureSelection/SubSetSelection.js +69 -78
- package/dist/FeatureSelection/SubSetSelection.js.map +1 -1
- package/dist/Filter/DiscreteToContinuous.js +50 -60
- package/dist/Filter/DiscreteToContinuous.js.map +1 -1
- package/dist/Filter/DiscreteToIndexed.js +40 -50
- package/dist/Filter/DiscreteToIndexed.js.map +1 -1
- package/dist/Filter/FeatureFilter.js +23 -32
- package/dist/Filter/FeatureFilter.js.map +1 -1
- package/dist/Filter/LaryFilter.d.ts +1 -1
- package/dist/Filter/LaryFilter.js +46 -55
- package/dist/Filter/LaryFilter.js.map +1 -1
- package/dist/Filter/LaryToBinary.js +48 -58
- package/dist/Filter/LaryToBinary.js.map +1 -1
- package/dist/Filter/Normalize.js +33 -41
- package/dist/Filter/Normalize.js.map +1 -1
- package/dist/Filter/Pca.js +86 -96
- package/dist/Filter/Pca.js.map +1 -1
- package/dist/Filter/TrainedFeatureFilter.d.ts +1 -1
- package/dist/Filter/TrainedFeatureFilter.js +14 -24
- package/dist/Filter/TrainedFeatureFilter.js.map +1 -1
- package/dist/Instance/CompositeInstance.js +46 -56
- package/dist/Instance/CompositeInstance.js.map +1 -1
- package/dist/Instance/Instance.js +145 -154
- package/dist/Instance/Instance.js.map +1 -1
- package/dist/InstanceList/InstanceList.js +466 -443
- package/dist/InstanceList/InstanceList.js.map +1 -1
- package/dist/InstanceList/InstanceListOfSameClass.js +23 -32
- package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -1
- package/dist/InstanceList/Partition.d.ts +45 -0
- package/dist/InstanceList/Partition.js +176 -131
- package/dist/InstanceList/Partition.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionCondition.d.ts +8 -0
- package/dist/Model/DecisionTree/DecisionCondition.js +71 -72
- package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionNode.d.ts +38 -1
- package/dist/Model/DecisionTree/DecisionNode.js +302 -275
- package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionStump.d.ts +17 -0
- package/dist/Model/DecisionTree/DecisionStump.js +25 -0
- package/dist/Model/DecisionTree/DecisionStump.js.map +1 -0
- package/dist/Model/DecisionTree/DecisionTree.d.ts +24 -9
- package/dist/Model/DecisionTree/DecisionTree.js +90 -76
- package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
- package/dist/Model/DummyModel.d.ts +28 -3
- package/dist/Model/DummyModel.js +64 -50
- package/dist/Model/DummyModel.js.map +1 -1
- package/dist/{Classifier/Bagging.d.ts → Model/Ensemble/BaggingModel.d.ts} +8 -4
- package/dist/Model/Ensemble/BaggingModel.js +37 -0
- package/dist/Model/Ensemble/BaggingModel.js.map +1 -0
- package/dist/{Classifier/RandomForest.d.ts → Model/Ensemble/RandomForestModel.d.ts} +8 -4
- package/dist/Model/Ensemble/RandomForestModel.js +34 -0
- package/dist/Model/Ensemble/RandomForestModel.js.map +1 -0
- package/dist/Model/Ensemble/TreeEnsembleModel.d.ts +32 -0
- package/dist/Model/Ensemble/TreeEnsembleModel.js +61 -0
- package/dist/Model/Ensemble/TreeEnsembleModel.js.map +1 -0
- package/dist/Model/Model.d.ts +50 -0
- package/dist/Model/Model.js +131 -72
- package/dist/Model/Model.js.map +1 -1
- package/dist/Model/NeuralNetwork/DeepNetworkModel.d.ts +47 -0
- package/dist/Model/NeuralNetwork/DeepNetworkModel.js +180 -0
- package/dist/Model/NeuralNetwork/DeepNetworkModel.js.map +1 -0
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.d.ts +31 -0
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.js +75 -0
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.js.map +1 -0
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.d.ts +39 -0
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js +119 -0
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js.map +1 -0
- package/dist/Model/{NeuralNetworkModel.d.ts → NeuralNetwork/NeuralNetworkModel.d.ts} +19 -5
- package/dist/Model/NeuralNetwork/NeuralNetworkModel.js +211 -0
- package/dist/Model/NeuralNetwork/NeuralNetworkModel.js.map +1 -0
- package/dist/Model/{KnnInstance.d.ts → NonParametric/KnnInstance.d.ts} +1 -1
- package/dist/Model/NonParametric/KnnInstance.js +25 -0
- package/dist/Model/NonParametric/KnnInstance.js.map +1 -0
- package/dist/Model/{KnnModel.d.ts → NonParametric/KnnModel.d.ts} +30 -6
- package/dist/Model/NonParametric/KnnModel.js +111 -0
- package/dist/Model/NonParametric/KnnModel.js.map +1 -0
- package/dist/Model/{GaussianModel.d.ts → Parametric/GaussianModel.d.ts} +20 -2
- package/dist/Model/Parametric/GaussianModel.js +95 -0
- package/dist/Model/Parametric/GaussianModel.js.map +1 -0
- package/dist/Model/Parametric/KMeansModel.d.ts +36 -0
- package/dist/Model/Parametric/KMeansModel.js +65 -0
- package/dist/Model/Parametric/KMeansModel.js.map +1 -0
- package/dist/Model/Parametric/LdaModel.d.ts +44 -0
- package/dist/Model/Parametric/LdaModel.js +90 -0
- package/dist/Model/Parametric/LdaModel.js.map +1 -0
- package/dist/Model/{NaiveBayesModel.d.ts → Parametric/NaiveBayesModel.d.ts} +30 -10
- package/dist/Model/Parametric/NaiveBayesModel.js +131 -0
- package/dist/Model/Parametric/NaiveBayesModel.js.map +1 -0
- package/dist/Model/Parametric/QdaModel.d.ts +30 -0
- package/dist/Model/Parametric/QdaModel.js +75 -0
- package/dist/Model/Parametric/QdaModel.js.map +1 -0
- package/dist/Model/RandomModel.d.ts +32 -2
- package/dist/Model/RandomModel.js +85 -60
- package/dist/Model/RandomModel.js.map +1 -1
- package/dist/Model/ValidatedModel.js +21 -31
- package/dist/Model/ValidatedModel.js.map +1 -1
- package/dist/Parameter/ActivationFunction.js +9 -19
- package/dist/Parameter/ActivationFunction.js.map +1 -1
- package/dist/Parameter/BaggingParameter.js +24 -33
- package/dist/Parameter/BaggingParameter.js.map +1 -1
- package/dist/Parameter/C45Parameter.d.ts +2 -2
- package/dist/Parameter/C45Parameter.js +34 -42
- package/dist/Parameter/C45Parameter.js.map +1 -1
- package/dist/Parameter/DeepNetworkParameter.d.ts +2 -2
- package/dist/Parameter/DeepNetworkParameter.js +48 -56
- package/dist/Parameter/DeepNetworkParameter.js.map +1 -1
- package/dist/Parameter/KMeansParameter.js +29 -38
- package/dist/Parameter/KMeansParameter.js.map +1 -1
- package/dist/Parameter/KnnParameter.d.ts +1 -1
- package/dist/Parameter/KnnParameter.js +25 -34
- package/dist/Parameter/KnnParameter.js.map +1 -1
- package/dist/Parameter/LinearPerceptronParameter.d.ts +4 -4
- package/dist/Parameter/LinearPerceptronParameter.js +56 -62
- package/dist/Parameter/LinearPerceptronParameter.js.map +1 -1
- package/dist/Parameter/MultiLayerPerceptronParameter.d.ts +2 -2
- package/dist/Parameter/MultiLayerPerceptronParameter.js +38 -46
- package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -1
- package/dist/Parameter/Parameter.d.ts +1 -1
- package/dist/Parameter/Parameter.js +21 -30
- package/dist/Parameter/Parameter.js.map +1 -1
- package/dist/Parameter/RandomForestParameter.js +25 -34
- package/dist/Parameter/RandomForestParameter.js.map +1 -1
- package/dist/Performance/ClassificationPerformance.js +24 -33
- package/dist/Performance/ClassificationPerformance.js.map +1 -1
- package/dist/Performance/ConfusionMatrix.d.ts +1 -1
- package/dist/Performance/ConfusionMatrix.js +149 -158
- package/dist/Performance/ConfusionMatrix.js.map +1 -1
- package/dist/Performance/DetailedClassificationPerformance.js +23 -32
- package/dist/Performance/DetailedClassificationPerformance.js.map +1 -1
- package/dist/Performance/ExperimentPerformance.js +184 -161
- package/dist/Performance/ExperimentPerformance.js.map +1 -1
- package/dist/Performance/Performance.js +21 -30
- package/dist/Performance/Performance.js.map +1 -1
- package/dist/StatisticalTest/Combined5x2F.d.ts +12 -0
- package/dist/StatisticalTest/Combined5x2F.js +41 -39
- package/dist/StatisticalTest/Combined5x2F.js.map +1 -1
- package/dist/StatisticalTest/Combined5x2t.d.ts +13 -0
- package/dist/StatisticalTest/Combined5x2t.js +42 -39
- package/dist/StatisticalTest/Combined5x2t.js.map +1 -1
- package/dist/StatisticalTest/Paired5x2t.d.ts +12 -0
- package/dist/StatisticalTest/Paired5x2t.js +40 -38
- package/dist/StatisticalTest/Paired5x2t.js.map +1 -1
- package/dist/StatisticalTest/PairedTest.d.ts +12 -0
- package/dist/StatisticalTest/PairedTest.js +31 -29
- package/dist/StatisticalTest/PairedTest.js.map +1 -1
- package/dist/StatisticalTest/Pairedt.d.ts +12 -0
- package/dist/StatisticalTest/Pairedt.js +38 -36
- package/dist/StatisticalTest/Pairedt.js.map +1 -1
- package/dist/StatisticalTest/Sign.d.ts +17 -0
- package/dist/StatisticalTest/Sign.js +50 -43
- package/dist/StatisticalTest/Sign.js.map +1 -1
- package/dist/StatisticalTest/StatisticalTestResult.d.ts +30 -0
- package/dist/StatisticalTest/StatisticalTestResult.js +65 -43
- package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -1
- package/dist/StatisticalTest/StatisticalTestResultType.js +11 -21
- package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -1
- package/dist/index.d.ts +88 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/package.json +9 -8
- package/source/Attribute/DiscreteAttribute.ts +1 -1
- package/source/Attribute/DiscreteIndexedAttribute.ts +2 -2
- package/source/DataSet/DataDefinition.ts +11 -0
- package/source/Experiment/BootstrapRun.ts +2 -2
- package/source/Experiment/Experiment.ts +10 -10
- package/source/Experiment/KFoldRun.ts +20 -5
- package/source/Experiment/KFoldRunSeparateTest.ts +16 -5
- package/source/Experiment/MxKFoldRun.ts +1 -1
- package/source/Experiment/MxKFoldRunSeparateTest.ts +1 -1
- package/source/Experiment/SingleRunWithK.ts +20 -5
- package/source/Experiment/StratifiedKFoldRun.ts +1 -1
- package/source/Experiment/StratifiedKFoldRunSeparateTest.ts +1 -1
- package/source/Experiment/StratifiedMxKFoldRun.ts +1 -1
- package/source/Experiment/StratifiedMxKFoldRunSeparateTest.ts +3 -3
- package/source/Experiment/StratifiedSingleRunWithK.ts +1 -1
- package/source/Filter/LaryFilter.ts +1 -1
- package/source/Filter/TrainedFeatureFilter.ts +1 -1
- package/source/InstanceList/Partition.ts +125 -65
- package/source/Model/DecisionTree/DecisionCondition.ts +8 -0
- package/source/Model/DecisionTree/DecisionNode.ts +56 -20
- package/source/Model/DecisionTree/DecisionStump.ts +26 -0
- package/source/Model/DecisionTree/DecisionTree.ts +44 -15
- package/source/Model/DummyModel.ts +40 -10
- package/source/{Classifier/Bagging.ts → Model/Ensemble/BaggingModel.ts} +15 -12
- package/source/{Classifier/RandomForest.ts → Model/Ensemble/RandomForestModel.ts} +14 -12
- package/source/Model/{TreeEnsembleModel.ts → Ensemble/TreeEnsembleModel.ts} +26 -18
- package/source/Model/Model.ts +77 -0
- package/source/Model/{DeepNetworkModel.ts → NeuralNetwork/DeepNetworkModel.ts} +59 -56
- package/source/Model/NeuralNetwork/LinearPerceptronModel.ts +81 -0
- package/source/Model/{MultiLayerPerceptronModel.ts → NeuralNetwork/MultiLayerPerceptronModel.ts} +46 -39
- package/source/Model/{NeuralNetworkModel.ts → NeuralNetwork/NeuralNetworkModel.ts} +20 -7
- package/source/Model/{KnnInstance.ts → NonParametric/KnnInstance.ts} +1 -1
- package/source/Model/{KnnModel.ts → NonParametric/KnnModel.ts} +48 -19
- package/source/Model/{GaussianModel.ts → Parametric/GaussianModel.ts} +21 -3
- package/source/Model/Parametric/KMeansModel.ts +72 -0
- package/source/Model/Parametric/LdaModel.ts +98 -0
- package/source/Model/{NaiveBayesModel.ts → Parametric/NaiveBayesModel.ts} +68 -25
- package/source/Model/Parametric/QdaModel.ts +83 -0
- package/source/Model/RandomModel.ts +54 -16
- package/source/Parameter/C45Parameter.ts +2 -2
- package/source/Parameter/DeepNetworkParameter.ts +2 -2
- package/source/Parameter/KnnParameter.ts +1 -1
- package/source/Parameter/LinearPerceptronParameter.ts +4 -4
- package/source/Parameter/MultiLayerPerceptronParameter.ts +2 -2
- package/source/Parameter/Parameter.ts +1 -1
- package/source/Performance/ConfusionMatrix.ts +1 -1
- package/source/StatisticalTest/Combined5x2F.ts +12 -0
- package/source/StatisticalTest/Combined5x2t.ts +13 -0
- package/source/StatisticalTest/Paired5x2t.ts +12 -0
- package/source/StatisticalTest/PairedTest.ts +12 -0
- package/source/StatisticalTest/Pairedt.ts +12 -0
- package/source/StatisticalTest/Sign.ts +17 -0
- package/source/StatisticalTest/StatisticalTestResult.ts +30 -0
- package/source/index.ts +88 -0
- package/tests/Classifier/C45Test.ts +2 -2
- package/tests/Classifier/DeepNetworkTest.ts +3 -5
- package/tests/Classifier/DummyTest.ts +2 -2
- package/tests/Classifier/KMeansTest.ts +2 -2
- package/tests/Classifier/KnnTest.ts +2 -2
- package/tests/Classifier/LdaTest.ts +2 -2
- package/tests/Classifier/LinearPerceptronTest.ts +2 -2
- package/tests/Classifier/MultiLayerPerceptronTest.ts +2 -3
- package/tests/Classifier/NaiveBayesTest.ts +2 -2
- package/tests/Classifier/QdaTest.ts +2 -2
- package/tests/Classifier/RandomForestTest.ts +2 -2
- package/tsconfig.json +4 -4
- package/dist/Classifier/Bagging.js +0 -45
- package/dist/Classifier/Bagging.js.map +0 -1
- package/dist/Classifier/C45.d.ts +0 -14
- package/dist/Classifier/C45.js +0 -43
- package/dist/Classifier/C45.js.map +0 -1
- package/dist/Classifier/C45Stump.d.ts +0 -13
- package/dist/Classifier/C45Stump.js +0 -32
- package/dist/Classifier/C45Stump.js.map +0 -1
- package/dist/Classifier/Classifier.d.ts +0 -40
- package/dist/Classifier/Classifier.js +0 -72
- package/dist/Classifier/Classifier.js.map +0 -1
- package/dist/Classifier/DeepNetwork.d.ts +0 -14
- package/dist/Classifier/DeepNetwork.js +0 -34
- package/dist/Classifier/DeepNetwork.js.map +0 -1
- package/dist/Classifier/Dummy.d.ts +0 -14
- package/dist/Classifier/Dummy.js +0 -32
- package/dist/Classifier/Dummy.js.map +0 -1
- package/dist/Classifier/KMeans.d.ts +0 -13
- package/dist/Classifier/KMeans.js +0 -39
- package/dist/Classifier/KMeans.js.map +0 -1
- package/dist/Classifier/Knn.d.ts +0 -14
- package/dist/Classifier/Knn.js +0 -32
- package/dist/Classifier/Knn.js.map +0 -1
- package/dist/Classifier/Lda.d.ts +0 -13
- package/dist/Classifier/Lda.js +0 -55
- package/dist/Classifier/Lda.js.map +0 -1
- package/dist/Classifier/LinearPerceptron.d.ts +0 -15
- package/dist/Classifier/LinearPerceptron.js +0 -35
- package/dist/Classifier/LinearPerceptron.js.map +0 -1
- package/dist/Classifier/MultiLayerPerceptron.d.ts +0 -15
- package/dist/Classifier/MultiLayerPerceptron.js +0 -35
- package/dist/Classifier/MultiLayerPerceptron.js.map +0 -1
- package/dist/Classifier/NaiveBayes.d.ts +0 -26
- package/dist/Classifier/NaiveBayes.js +0 -70
- package/dist/Classifier/NaiveBayes.js.map +0 -1
- package/dist/Classifier/Qda.d.ts +0 -13
- package/dist/Classifier/Qda.js +0 -53
- package/dist/Classifier/Qda.js.map +0 -1
- package/dist/Classifier/RandomClassifier.d.ts +0 -13
- package/dist/Classifier/RandomClassifier.js +0 -35
- package/dist/Classifier/RandomClassifier.js.map +0 -1
- package/dist/Classifier/RandomForest.js +0 -42
- package/dist/Classifier/RandomForest.js.map +0 -1
- package/dist/Model/DeepNetworkModel.d.ts +0 -45
- package/dist/Model/DeepNetworkModel.js +0 -187
- package/dist/Model/DeepNetworkModel.js.map +0 -1
- package/dist/Model/GaussianModel.js +0 -86
- package/dist/Model/GaussianModel.js.map +0 -1
- package/dist/Model/KMeansModel.d.ts +0 -28
- package/dist/Model/KMeansModel.js +0 -61
- package/dist/Model/KMeansModel.js.map +0 -1
- package/dist/Model/KnnInstance.js +0 -33
- package/dist/Model/KnnInstance.js.map +0 -1
- package/dist/Model/KnnModel.js +0 -95
- package/dist/Model/KnnModel.js.map +0 -1
- package/dist/Model/LdaModel.d.ts +0 -28
- package/dist/Model/LdaModel.js +0 -67
- package/dist/Model/LdaModel.js.map +0 -1
- package/dist/Model/LinearPerceptronModel.d.ts +0 -24
- package/dist/Model/LinearPerceptronModel.js +0 -91
- package/dist/Model/LinearPerceptronModel.js.map +0 -1
- package/dist/Model/MultiLayerPerceptronModel.d.ts +0 -33
- package/dist/Model/MultiLayerPerceptronModel.js +0 -123
- package/dist/Model/MultiLayerPerceptronModel.js.map +0 -1
- package/dist/Model/NaiveBayesModel.js +0 -107
- package/dist/Model/NaiveBayesModel.js.map +0 -1
- package/dist/Model/NeuralNetworkModel.js +0 -202
- package/dist/Model/NeuralNetworkModel.js.map +0 -1
- package/dist/Model/QdaModel.d.ts +0 -27
- package/dist/Model/QdaModel.js +0 -63
- package/dist/Model/QdaModel.js.map +0 -1
- package/dist/Model/TreeEnsembleModel.d.ts +0 -22
- package/dist/Model/TreeEnsembleModel.js +0 -64
- package/dist/Model/TreeEnsembleModel.js.map +0 -1
- package/index.js +0 -100
- package/source/Classifier/C45.ts +0 -34
- package/source/Classifier/C45Stump.ts +0 -23
- package/source/Classifier/Classifier.ts +0 -72
- package/source/Classifier/DeepNetwork.ts +0 -26
- package/source/Classifier/Dummy.ts +0 -23
- package/source/Classifier/KMeans.ts +0 -30
- package/source/Classifier/Knn.ts +0 -25
- package/source/Classifier/Lda.ts +0 -47
- package/source/Classifier/LinearPerceptron.ts +0 -27
- package/source/Classifier/MultiLayerPerceptron.ts +0 -27
- package/source/Classifier/NaiveBayes.ts +0 -66
- package/source/Classifier/Qda.ts +0 -46
- package/source/Classifier/RandomClassifier.ts +0 -26
- package/source/Model/KMeansModel.ts +0 -56
- package/source/Model/LdaModel.ts +0 -62
- package/source/Model/LinearPerceptronModel.ts +0 -83
- package/source/Model/QdaModel.ts +0 -57
- package/source/tsconfig.json +0 -13
|
@@ -33,7 +33,7 @@ export class MxKFoldRunSeparateTest extends KFoldRunSeparateTest{
|
|
|
33
33
|
let partition = new Partition(instanceList, 0.25, true);
|
|
34
34
|
for (let j = 0; j < this.M; j++) {
|
|
35
35
|
let crossValidation = new KFoldCrossValidation<Instance>(partition.get(1).getInstances(), this.K, experiment.getParameter().getSeed());
|
|
36
|
-
this.runExperiment(experiment.
|
|
36
|
+
this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
|
|
37
37
|
}
|
|
38
38
|
return result;
|
|
39
39
|
}
|
|
@@ -4,24 +4,39 @@ import {KFoldCrossValidation} from "nlptoolkit-sampling/dist/KFoldCrossValidatio
|
|
|
4
4
|
import {Instance} from "../Instance/Instance";
|
|
5
5
|
import {Performance} from "../Performance/Performance";
|
|
6
6
|
import {InstanceList} from "../InstanceList/InstanceList";
|
|
7
|
-
import {Classifier} from "../Classifier/Classifier";
|
|
8
7
|
import {Parameter} from "../Parameter/Parameter";
|
|
9
8
|
import {CrossValidation} from "nlptoolkit-sampling/dist/CrossValidation";
|
|
9
|
+
import {Model} from "../Model/Model";
|
|
10
10
|
|
|
11
11
|
export class SingleRunWithK implements SingleRun{
|
|
12
12
|
|
|
13
|
-
private K: number
|
|
13
|
+
private readonly K: number
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Constructor for SingleRunWithK class. Basically sets K parameter of the K-fold cross-validation.
|
|
17
|
+
*
|
|
18
|
+
* @param K K of the K-fold cross-validation.
|
|
19
|
+
*/
|
|
15
20
|
constructor(K: number) {
|
|
16
21
|
this.K = K
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Runs first fold of a K fold cross-validated experiment for the given classifier with the given parameters.
|
|
26
|
+
* The experiment result will be returned.
|
|
27
|
+
* @param model Classifier for the experiment
|
|
28
|
+
* @param parameter Hyperparameters of the classifier of the experiment
|
|
29
|
+
* @param crossValidation K-fold crossvalidated dataset.
|
|
30
|
+
* @return The experiment result of the first fold of the K-fold cross-validated experiment.
|
|
31
|
+
* @throws DiscreteFeaturesNotAllowed If the classifier does not allow discrete features and the dataset contains
|
|
32
|
+
* discrete features, DiscreteFeaturesNotAllowed will be thrown.
|
|
33
|
+
*/
|
|
34
|
+
runExperiment(model: Model,
|
|
20
35
|
parameter: Parameter,
|
|
21
36
|
crossValidation: CrossValidation<Instance>){
|
|
22
37
|
let trainSet = new InstanceList(crossValidation.getTrainFold(0));
|
|
23
38
|
let testSet = new InstanceList(crossValidation.getTestFold(0));
|
|
24
|
-
return
|
|
39
|
+
return model.singleRun(parameter, trainSet, testSet);
|
|
25
40
|
}
|
|
26
41
|
|
|
27
42
|
/**
|
|
@@ -33,7 +48,7 @@ export class SingleRunWithK implements SingleRun{
|
|
|
33
48
|
execute(experiment: Experiment): Performance {
|
|
34
49
|
let crossValidation = new KFoldCrossValidation<Instance>(experiment.getDataSet().getInstances(), this.K,
|
|
35
50
|
experiment.getParameter().getSeed());
|
|
36
|
-
return this.runExperiment(experiment.
|
|
51
|
+
return this.runExperiment(experiment.getmodel(), experiment.getParameter(), crossValidation);
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
}
|
|
@@ -23,7 +23,7 @@ export class StratifiedKFoldRun extends KFoldRun{
|
|
|
23
23
|
execute(experiment: Experiment): ExperimentPerformance {
|
|
24
24
|
let result = new ExperimentPerformance();
|
|
25
25
|
let crossValidation = new StratifiedKFoldCrossValidation<Instance>(experiment.getDataSet().getClassInstances(), this.K, experiment.getParameter().getSeed());
|
|
26
|
-
this.runExperiment(experiment.
|
|
26
|
+
this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation);
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -27,7 +27,7 @@ export class StratifiedKFoldRunSeparateTest extends KFoldRunSeparateTest{
|
|
|
27
27
|
let instanceList = experiment.getDataSet().getInstanceList();
|
|
28
28
|
let partition = new Partition(instanceList, 0.25, true);
|
|
29
29
|
let crossValidation = new StratifiedKFoldCrossValidation<Instance>(new Partition(partition.get(1)).getLists(), this.K, experiment.getParameter().getSeed());
|
|
30
|
-
this.runExperiment(experiment.
|
|
30
|
+
this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -27,7 +27,7 @@ export class StratifiedMxKFoldRun extends MxKFoldRun{
|
|
|
27
27
|
for (let j = 0; j < this.M; j++) {
|
|
28
28
|
let crossValidation = new StratifiedKFoldCrossValidation<Instance>(experiment.getDataSet().getClassInstances(),
|
|
29
29
|
this.K, experiment.getParameter().getSeed());
|
|
30
|
-
this.runExperiment(experiment.
|
|
30
|
+
this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation);
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
@@ -28,12 +28,12 @@ export class StratifiedMxKFoldRunSeparateTest extends StratifiedKFoldRunSeparate
|
|
|
28
28
|
*/
|
|
29
29
|
execute(experiment: Experiment): ExperimentPerformance {
|
|
30
30
|
let result = new ExperimentPerformance();
|
|
31
|
+
let instanceList = experiment.getDataSet().getInstanceList();
|
|
32
|
+
let partition = new Partition(instanceList, 0.25, true);
|
|
31
33
|
for (let j = 0; j < this.M; j++) {
|
|
32
|
-
let instanceList = experiment.getDataSet().getInstanceList();
|
|
33
|
-
let partition = new Partition(instanceList, 0.25, true);
|
|
34
34
|
let crossValidation = new StratifiedKFoldCrossValidation<Instance>(new Partition(partition.get(1)).getLists(),
|
|
35
35
|
this.K, experiment.getParameter().getSeed());
|
|
36
|
-
this.runExperiment(experiment.
|
|
36
|
+
this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
|
|
37
37
|
}
|
|
38
38
|
return result;
|
|
39
39
|
}
|
|
@@ -28,6 +28,6 @@ export class StratifiedSingleRunWithK {
|
|
|
28
28
|
this.K, experiment.getParameter().getSeed());
|
|
29
29
|
let trainSet = new InstanceList(crossValidation.getTrainFold(0));
|
|
30
30
|
let testSet = new InstanceList(crossValidation.getTestFold(0));
|
|
31
|
-
return experiment.
|
|
31
|
+
return experiment.getmodel().singleRun(experiment.getParameter(), trainSet, testSet);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -10,7 +10,7 @@ export abstract class LaryFilter extends FeatureFilter{
|
|
|
10
10
|
/**
|
|
11
11
|
* Constructor that sets the dataSet and all the attributes distributions.
|
|
12
12
|
*
|
|
13
|
-
* @param dataSet DataSet that will
|
|
13
|
+
* @param dataSet DataSet that will be used.
|
|
14
14
|
*/
|
|
15
15
|
constructor(dataSet: DataSet) {
|
|
16
16
|
super(dataSet);
|
|
@@ -8,7 +8,7 @@ export abstract class TrainedFeatureFilter extends FeatureFilter{
|
|
|
8
8
|
/**
|
|
9
9
|
* Constructor that sets the dataSet.
|
|
10
10
|
*
|
|
11
|
-
* @param dataSet DataSet that will
|
|
11
|
+
* @param dataSet DataSet that will be used.
|
|
12
12
|
*/
|
|
13
13
|
constructor(dataSet: DataSet) {
|
|
14
14
|
super(dataSet);
|
|
@@ -10,81 +10,141 @@ export class Partition {
|
|
|
10
10
|
|
|
11
11
|
private multiList: Array<InstanceList> = new Array<InstanceList>()
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Divides the instances in the instance list into partitions so that all instances of a class are grouped in a
|
|
15
|
+
* single partition.
|
|
16
|
+
* @param instanceList Instance list for which partition will be created.
|
|
17
|
+
*/
|
|
18
|
+
constructor1(instanceList: InstanceList){
|
|
19
|
+
let classLabels = instanceList.getDistinctClassLabels();
|
|
20
|
+
for (let classLabel of classLabels){
|
|
21
|
+
this.add(new InstanceListOfSameClass(classLabel));
|
|
22
|
+
}
|
|
23
|
+
for (let instance of instanceList.getInstances()) {
|
|
24
|
+
this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a partition depending on the distinct values of a discrete attribute. If the discrete attribute has 4
|
|
30
|
+
* distinct values, the resulting partition will have 4 groups, where each group contain instance whose
|
|
31
|
+
* values of that discrete attribute are the same.
|
|
32
|
+
*
|
|
33
|
+
* @param instanceList Instance list for which partition will be created.
|
|
34
|
+
* @param attributeIndex Index of the discrete attribute.
|
|
35
|
+
*/
|
|
36
|
+
constructor2(instanceList: InstanceList, attributeIndex: number){
|
|
37
|
+
let valueList = instanceList.getAttributeValueList(attributeIndex);
|
|
38
|
+
for (let value of valueList) {
|
|
39
|
+
this.add(new InstanceList());
|
|
40
|
+
}
|
|
41
|
+
for (let instance of instanceList.getInstances()) {
|
|
42
|
+
this.get(valueList.indexOf((<DiscreteAttribute> instance.getAttribute(attributeIndex)).getValue())).add(instance);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates a stratified partition of the current instance list. In a stratified partition, the percentage of each
|
|
48
|
+
* class is preserved. For example, let's say there are three classes in the instance list, and let the percentages of
|
|
49
|
+
* these classes be %20, %30, and %50; then the percentages of these classes in the stratified partitions are the
|
|
50
|
+
* same, that is, %20, %30, and %50.
|
|
51
|
+
*
|
|
52
|
+
* @param instanceList Instance list for which partition will be created.
|
|
53
|
+
* @param ratio Ratio of the stratified partition. Ratio is between 0 and 1. If the ratio is 0.2, then 20 percent
|
|
54
|
+
* of the instances are put in the first group, 80 percent of the instances are put in the second group.
|
|
55
|
+
* @param random random is used as a random number.
|
|
56
|
+
* @param stratified If true, stratified partition is obtained.
|
|
57
|
+
*/
|
|
58
|
+
constructor3(instanceList: InstanceList, ratio: number, random: Random, stratified: boolean){
|
|
59
|
+
this.add(new InstanceList());
|
|
60
|
+
this.add(new InstanceList());
|
|
61
|
+
if (stratified){
|
|
62
|
+
let distribution = instanceList.classDistribution();
|
|
63
|
+
let counts = new Array<number>(distribution.size).fill(0)
|
|
64
|
+
let randomArray = new Array<number>()
|
|
65
|
+
for (let i = 0; i < instanceList.size(); i++){
|
|
66
|
+
randomArray.push(i);
|
|
67
|
+
}
|
|
68
|
+
if (random != undefined){
|
|
69
|
+
random.shuffle(randomArray)
|
|
70
|
+
}
|
|
71
|
+
for (let i = 0; i < instanceList.size(); i++) {
|
|
72
|
+
let instance = instanceList.get(randomArray[i]);
|
|
73
|
+
let classIndex = distribution.getIndex(instance.getClassLabel());
|
|
74
|
+
if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
|
|
75
|
+
this.get(0).add(instance);
|
|
76
|
+
} else {
|
|
77
|
+
this.get(1).add(instance);
|
|
78
|
+
}
|
|
79
|
+
counts[classIndex]++;
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
instanceList.shuffle(random)
|
|
83
|
+
for (let i = 0; i < instanceList.size(); i++) {
|
|
84
|
+
let instance = instanceList.get(i);
|
|
85
|
+
if (i < instanceList.size() * ratio) {
|
|
86
|
+
this.get(0).add(instance);
|
|
87
|
+
} else {
|
|
88
|
+
this.get(1).add(instance);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Creates a partition depending on the distinct values of a discrete indexed attribute.
|
|
96
|
+
*
|
|
97
|
+
* @param instanceList Instance list for which partition will be created.
|
|
98
|
+
* @param attributeIndex Index of the discrete indexed attribute.
|
|
99
|
+
* @param attributeValue Value of the attribute.
|
|
100
|
+
*/
|
|
101
|
+
constructor4(instanceList: InstanceList, attributeIndex: number, attributeValue: number){
|
|
102
|
+
this.add(new InstanceList());
|
|
103
|
+
this.add(new InstanceList());
|
|
104
|
+
for (let instance of instanceList.getInstances()) {
|
|
105
|
+
if ((<DiscreteIndexedAttribute> instance.getAttribute(attributeIndex)).getIndex() == attributeValue) {
|
|
106
|
+
this.get(0).add(instance);
|
|
107
|
+
} else {
|
|
108
|
+
this.get(1).add(instance);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Creates a two group partition depending on the values of a continuous attribute. If the value of the attribute is
|
|
115
|
+
* less than splitValue, the instance is forwarded to the first group, else it is forwarded to the second group.
|
|
116
|
+
*
|
|
117
|
+
* @param instanceList Instance list for which partition will be created.
|
|
118
|
+
* @param attributeIndex Index of the continuous attribute
|
|
119
|
+
* @param splitValue Threshold to divide instances
|
|
120
|
+
*/
|
|
121
|
+
constructor5(instanceList: InstanceList, attributeIndex: number, splitValue: number){
|
|
122
|
+
this.add(new InstanceList());
|
|
123
|
+
this.add(new InstanceList());
|
|
124
|
+
for (let instance of instanceList.getInstances()) {
|
|
125
|
+
if ((<ContinuousAttribute> instance.getAttribute(attributeIndex)).getValue() <= splitValue) {
|
|
126
|
+
this.get(0).add(instance);
|
|
127
|
+
} else {
|
|
128
|
+
this.get(1).add(instance);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
13
133
|
constructor(instanceList?: InstanceList, attributeIndex?: number, stratifiedOrValue?: any, random?: Random) {
|
|
14
134
|
if (instanceList != undefined){
|
|
15
135
|
if (attributeIndex == undefined){
|
|
16
|
-
|
|
17
|
-
for (let classLabel of classLabels){
|
|
18
|
-
this.add(new InstanceListOfSameClass(classLabel));
|
|
19
|
-
}
|
|
20
|
-
for (let instance of instanceList.getInstances()) {
|
|
21
|
-
this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
|
|
22
|
-
}
|
|
136
|
+
this.constructor1(instanceList);
|
|
23
137
|
} else {
|
|
24
138
|
if (stratifiedOrValue == undefined){
|
|
25
|
-
|
|
26
|
-
for (let value of valueList) {
|
|
27
|
-
this.add(new InstanceList());
|
|
28
|
-
}
|
|
29
|
-
for (let instance of instanceList.getInstances()) {
|
|
30
|
-
this.get(valueList.indexOf((<DiscreteAttribute> instance.getAttribute(attributeIndex)).getValue())).add(instance);
|
|
31
|
-
}
|
|
139
|
+
this.constructor2(instanceList, attributeIndex)
|
|
32
140
|
} else {
|
|
33
141
|
if (typeof stratifiedOrValue == "boolean"){
|
|
34
|
-
this.
|
|
35
|
-
this.add(new InstanceList());
|
|
36
|
-
if (stratifiedOrValue){
|
|
37
|
-
let distribution = instanceList.classDistribution();
|
|
38
|
-
let counts = new Array<number>(distribution.size).fill(0)
|
|
39
|
-
let randomArray = new Array<number>()
|
|
40
|
-
for (let i = 0; i < instanceList.size(); i++){
|
|
41
|
-
randomArray.push(i);
|
|
42
|
-
}
|
|
43
|
-
if (random != undefined){
|
|
44
|
-
random.shuffle(randomArray)
|
|
45
|
-
}
|
|
46
|
-
for (let i = 0; i < instanceList.size(); i++) {
|
|
47
|
-
let instance = instanceList.get(randomArray[i]);
|
|
48
|
-
let classIndex = distribution.getIndex(instance.getClassLabel());
|
|
49
|
-
let ratio = attributeIndex
|
|
50
|
-
if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
|
|
51
|
-
this.get(0).add(instance);
|
|
52
|
-
} else {
|
|
53
|
-
this.get(1).add(instance);
|
|
54
|
-
}
|
|
55
|
-
counts[classIndex]++;
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
instanceList.shuffle(random)
|
|
59
|
-
for (let i = 0; i < instanceList.size(); i++) {
|
|
60
|
-
let instance = instanceList.get(i);
|
|
61
|
-
let ratio = attributeIndex
|
|
62
|
-
if (i < instanceList.size() * ratio) {
|
|
63
|
-
this.get(0).add(instance);
|
|
64
|
-
} else {
|
|
65
|
-
this.get(1).add(instance);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
142
|
+
this.constructor3(instanceList, attributeIndex, random, stratifiedOrValue)
|
|
69
143
|
} else {
|
|
70
|
-
this.add(new InstanceList());
|
|
71
|
-
this.add(new InstanceList());
|
|
72
144
|
if (Number.isInteger(stratifiedOrValue)){
|
|
73
|
-
|
|
74
|
-
if ((<DiscreteIndexedAttribute> instance.getAttribute(attributeIndex)).getIndex() == stratifiedOrValue) {
|
|
75
|
-
this.get(0).add(instance);
|
|
76
|
-
} else {
|
|
77
|
-
this.get(1).add(instance);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
145
|
+
this.constructor4(instanceList, attributeIndex, stratifiedOrValue);
|
|
80
146
|
} else {
|
|
81
|
-
|
|
82
|
-
if ((<ContinuousAttribute> instance.getAttribute(attributeIndex)).getValue() <= stratifiedOrValue) {
|
|
83
|
-
this.get(0).add(instance);
|
|
84
|
-
} else {
|
|
85
|
-
this.get(1).add(instance);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
147
|
+
this.constructor5(instanceList, attributeIndex, stratifiedOrValue);
|
|
88
148
|
}
|
|
89
149
|
}
|
|
90
150
|
}
|
|
@@ -23,10 +23,18 @@ export class DecisionCondition {
|
|
|
23
23
|
this.value = value;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Accessor for the attribute index.
|
|
28
|
+
* @return Attribute index.
|
|
29
|
+
*/
|
|
26
30
|
getAttributeIndex(): number{
|
|
27
31
|
return this.attributeIndex
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Accessor for the value.
|
|
36
|
+
* @return Value.
|
|
37
|
+
*/
|
|
30
38
|
getValue(): Attribute{
|
|
31
39
|
return this.value
|
|
32
40
|
}
|
|
@@ -16,19 +16,40 @@ export class DecisionNode {
|
|
|
16
16
|
|
|
17
17
|
children: Array<DecisionNode> = undefined
|
|
18
18
|
private EPSILON: number = 0.0000000001;
|
|
19
|
-
private data : InstanceList = undefined
|
|
20
19
|
private classLabel : string = undefined
|
|
21
20
|
leaf: boolean = false
|
|
22
21
|
private condition: DecisionCondition = undefined
|
|
23
22
|
private classLabelsDistribution: DiscreteDistribution
|
|
24
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The DecisionNode method takes {@link InstanceList} data as input and then it sets the class label parameter by finding
|
|
26
|
+
* the most occurred class label of given data, it then gets distinct class labels as class labels ArrayList. Later, it adds ordered
|
|
27
|
+
* indices to the indexList and shuffles them randomly. Then, it gets the class distribution of given data and finds the best entropy value
|
|
28
|
+
* of these class distribution.
|
|
29
|
+
* <p>
|
|
30
|
+
* If an attribute of given data is {@link DiscreteIndexedAttribute}, it creates a Distribution according to discrete indexed attribute class distribution
|
|
31
|
+
* 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
|
|
32
|
+
* the newly founded best entropy's index. At the end, it also add new distribution to the class distribution .
|
|
33
|
+
* <p>
|
|
34
|
+
* If an attribute of given data is {@link DiscreteAttribute}, it directly finds the entropy. If it is better than the last best entropy it
|
|
35
|
+
* reassigns the best entropy, best attribute and best split value according to the newly founded best entropy's index.
|
|
36
|
+
* <p>
|
|
37
|
+
* If an attribute of given data is {@link ContinuousAttribute}, it creates two distributions; left and right according to class distribution
|
|
38
|
+
* and discrete distribution respectively, and finds the entropy. If it is better than the last best entropy it reassigns the best entropy,
|
|
39
|
+
* best attribute and best split value according to the newly founded best entropy's index. At the end, it also add new distribution to
|
|
40
|
+
* the right distribution and removes from left distribution .
|
|
41
|
+
*
|
|
42
|
+
* @param data {@link InstanceList} input.
|
|
43
|
+
* @param condition {@link DecisionCondition} to check.
|
|
44
|
+
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
45
|
+
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
46
|
+
*/
|
|
25
47
|
constructor1(data: InstanceList, condition?: DecisionCondition | number, parameter?: RandomForestParameter, isStump?: boolean){
|
|
26
48
|
let bestAttribute = -1
|
|
27
49
|
let bestSplitValue = 0
|
|
28
50
|
if (condition instanceof DecisionCondition){
|
|
29
51
|
this.condition = condition;
|
|
30
52
|
}
|
|
31
|
-
this.data = data
|
|
32
53
|
this.classLabelsDistribution = new DiscreteDistribution()
|
|
33
54
|
let labels = data.getClassLabels()
|
|
34
55
|
for (let label of labels){
|
|
@@ -75,7 +96,7 @@ export class DecisionNode {
|
|
|
75
96
|
}
|
|
76
97
|
} else {
|
|
77
98
|
if (data.get(0).getAttribute(index) instanceof DiscreteAttribute) {
|
|
78
|
-
let entropy = this.entropyForDiscreteAttribute(index);
|
|
99
|
+
let entropy = this.entropyForDiscreteAttribute(data, index);
|
|
79
100
|
if (entropy + this.EPSILON < bestEntropy) {
|
|
80
101
|
bestEntropy = entropy;
|
|
81
102
|
bestAttribute = index;
|
|
@@ -112,19 +133,23 @@ export class DecisionNode {
|
|
|
112
133
|
if (bestAttribute != -1) {
|
|
113
134
|
this.leaf = false;
|
|
114
135
|
if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteIndexedAttribute) {
|
|
115
|
-
this.createChildrenForDiscreteIndexed(bestAttribute, bestSplitValue, parameter, isStump);
|
|
136
|
+
this.createChildrenForDiscreteIndexed(data, bestAttribute, bestSplitValue, parameter, isStump);
|
|
116
137
|
} else {
|
|
117
138
|
if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteAttribute) {
|
|
118
|
-
this.createChildrenForDiscrete(bestAttribute, parameter, isStump);
|
|
139
|
+
this.createChildrenForDiscrete(data, bestAttribute, parameter, isStump);
|
|
119
140
|
} else {
|
|
120
141
|
if (data.get(0).getAttribute(bestAttribute) instanceof ContinuousAttribute) {
|
|
121
|
-
this.createChildrenForContinuous(bestAttribute, bestSplitValue, parameter, isStump);
|
|
142
|
+
this.createChildrenForContinuous(data, bestAttribute, bestSplitValue, parameter, isStump);
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
145
|
}
|
|
125
146
|
}
|
|
126
147
|
}
|
|
127
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Reads the decision node model (as one line) from model file.
|
|
151
|
+
* @param contents Model file
|
|
152
|
+
*/
|
|
128
153
|
constructor2(contents: FileContents){
|
|
129
154
|
let items = contents.readLine().split(" ")
|
|
130
155
|
if (items[0] != "-1"){
|
|
@@ -191,14 +216,15 @@ export class DecisionNode {
|
|
|
191
216
|
* The entropyForDiscreteAttribute method takes an attributeIndex and creates an ArrayList of DiscreteDistribution.
|
|
192
217
|
* Then loops through the distributions and calculates the total entropy.
|
|
193
218
|
*
|
|
219
|
+
* @param data Instance list.
|
|
194
220
|
* @param attributeIndex Index of the attribute.
|
|
195
221
|
* @return Total entropy for the discrete attribute.
|
|
196
222
|
*/
|
|
197
|
-
private entropyForDiscreteAttribute(attributeIndex: number): number{
|
|
223
|
+
private entropyForDiscreteAttribute(data: InstanceList, attributeIndex: number): number{
|
|
198
224
|
let sum = 0.0;
|
|
199
|
-
let distributions =
|
|
225
|
+
let distributions = data.attributeClassDistribution(attributeIndex);
|
|
200
226
|
for (let distribution of distributions) {
|
|
201
|
-
sum += (distribution.getSum() /
|
|
227
|
+
sum += (distribution.getSum() / data.size()) * distribution.entropy();
|
|
202
228
|
}
|
|
203
229
|
return sum;
|
|
204
230
|
}
|
|
@@ -207,29 +233,31 @@ export class DecisionNode {
|
|
|
207
233
|
* The createChildrenForDiscreteIndexed method creates an ArrayList of DecisionNodes as children and a partition with respect to
|
|
208
234
|
* indexed attribute.
|
|
209
235
|
*
|
|
236
|
+
* @param data Instance list.
|
|
210
237
|
* @param attributeIndex Index of the attribute.
|
|
211
238
|
* @param attributeValue Value of the attribute.
|
|
212
239
|
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
213
240
|
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
214
241
|
*/
|
|
215
|
-
private createChildrenForDiscreteIndexed(attributeIndex: number, attributeValue: number, parameter: RandomForestParameter, isStump: boolean){
|
|
216
|
-
let childrenData = new Partition(
|
|
242
|
+
private createChildrenForDiscreteIndexed(data: InstanceList, attributeIndex: number, attributeValue: number, parameter: RandomForestParameter, isStump: boolean){
|
|
243
|
+
let childrenData = new Partition(data, attributeIndex, attributeValue);
|
|
217
244
|
this.children = new Array<DecisionNode>();
|
|
218
|
-
this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", attributeValue, (<DiscreteIndexedAttribute>
|
|
219
|
-
this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", -1, (<DiscreteIndexedAttribute>
|
|
245
|
+
this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", attributeValue, (<DiscreteIndexedAttribute> data.get(0).getAttribute(attributeIndex)).getMaxIndex())), parameter, isStump));
|
|
246
|
+
this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", -1, (<DiscreteIndexedAttribute> data.get(0).getAttribute(attributeIndex)).getMaxIndex())), parameter, isStump));
|
|
220
247
|
}
|
|
221
248
|
|
|
222
249
|
/**
|
|
223
250
|
* The createChildrenForDiscrete method creates an ArrayList of values, a partition with respect to attributes and an ArrayList
|
|
224
251
|
* of DecisionNodes as children.
|
|
225
252
|
*
|
|
253
|
+
* @param data Instance list.
|
|
226
254
|
* @param attributeIndex Index of the attribute.
|
|
227
255
|
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
228
256
|
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
229
257
|
*/
|
|
230
|
-
private createChildrenForDiscrete(attributeIndex: number, parameter: RandomForestParameter, isStump: boolean){
|
|
231
|
-
let valueList =
|
|
232
|
-
let childrenData = new Partition(
|
|
258
|
+
private createChildrenForDiscrete(data: InstanceList, attributeIndex: number, parameter: RandomForestParameter, isStump: boolean){
|
|
259
|
+
let valueList = data.getAttributeValueList(attributeIndex);
|
|
260
|
+
let childrenData = new Partition(data, attributeIndex);
|
|
233
261
|
this.children = new Array<DecisionNode>();
|
|
234
262
|
for (let i = 0; i < valueList.length; i++) {
|
|
235
263
|
this.children.push(new DecisionNode(childrenData.get(i), new DecisionCondition(attributeIndex, new DiscreteAttribute(valueList[i])), parameter, isStump));
|
|
@@ -240,13 +268,14 @@ export class DecisionNode {
|
|
|
240
268
|
* The createChildrenForContinuous method creates an ArrayList of DecisionNodes as children and a partition with respect to
|
|
241
269
|
* continuous attribute and the given split value.
|
|
242
270
|
*
|
|
271
|
+
* @param data Instance list.
|
|
243
272
|
* @param attributeIndex Index of the attribute.
|
|
244
273
|
* @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
|
|
245
274
|
* @param isStump Refers to decision trees with only 1 splitting rule.
|
|
246
275
|
* @param splitValue Split value is used for partitioning.
|
|
247
276
|
*/
|
|
248
|
-
private createChildrenForContinuous(attributeIndex: number, splitValue: number, parameter: RandomForestParameter, isStump: boolean){
|
|
249
|
-
let childrenData = new Partition(
|
|
277
|
+
private createChildrenForContinuous(data: InstanceList, attributeIndex: number, splitValue: number, parameter: RandomForestParameter, isStump: boolean){
|
|
278
|
+
let childrenData = new Partition(data, attributeIndex, splitValue + 0.0000001);
|
|
250
279
|
this.children = new Array<DecisionNode>();
|
|
251
280
|
this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition(attributeIndex, new ContinuousAttribute(splitValue), "<"), parameter, isStump));
|
|
252
281
|
this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition(attributeIndex, new ContinuousAttribute(splitValue), ">"), parameter, isStump));
|
|
@@ -262,7 +291,7 @@ export class DecisionNode {
|
|
|
262
291
|
predict(instance: Instance): string{
|
|
263
292
|
if (instance instanceof CompositeInstance) {
|
|
264
293
|
let possibleClassLabels = (<CompositeInstance> instance).getPossibleClassLabels();
|
|
265
|
-
let distribution = this.
|
|
294
|
+
let distribution = this.classLabelsDistribution;
|
|
266
295
|
let predictedClass = distribution.getMaxItem(possibleClassLabels);
|
|
267
296
|
if (this.leaf) {
|
|
268
297
|
return predictedClass;
|
|
@@ -293,6 +322,13 @@ export class DecisionNode {
|
|
|
293
322
|
}
|
|
294
323
|
}
|
|
295
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Recursive method that returns the posterior probability distribution of a given instance. If the node is a leaf
|
|
327
|
+
* node, it returns the class label distribution, otherwise it checks in which direction (child node) this instance
|
|
328
|
+
* is forwarded.
|
|
329
|
+
* @param instance Instance for which the posterior probability distribution is calculated.
|
|
330
|
+
* @return Posterior probability distribution for this instance.
|
|
331
|
+
*/
|
|
296
332
|
predictProbabilityDistribution(instance: Instance): Map<string, number>{
|
|
297
333
|
if (this.leaf) {
|
|
298
334
|
return this.classLabelsDistribution.getProbabilityDistribution();
|
|
@@ -302,7 +338,7 @@ export class DecisionNode {
|
|
|
302
338
|
return node.predictProbabilityDistribution(instance);
|
|
303
339
|
}
|
|
304
340
|
}
|
|
305
|
-
return this.
|
|
341
|
+
return this.classLabelsDistribution.getProbabilityDistribution();
|
|
306
342
|
}
|
|
307
343
|
}
|
|
308
344
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {DecisionTree} from "./DecisionTree";
|
|
2
|
+
import {InstanceList} from "../../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../../Parameter/Parameter";
|
|
4
|
+
import {DecisionNode} from "./DecisionNode";
|
|
5
|
+
|
|
6
|
+
export class DecisionStump extends DecisionTree {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Training algorithm for C4.5 Stump univariate decision tree classifier.
|
|
10
|
+
*
|
|
11
|
+
* @param trainSet Training data given to the algorithm.
|
|
12
|
+
* @param parameters -
|
|
13
|
+
*/
|
|
14
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
15
|
+
this.root = new DecisionNode(trainSet, undefined, undefined, true);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Loads the decision tree model from an input file.
|
|
20
|
+
* @param fileName File name of the decision tree model.
|
|
21
|
+
*/
|
|
22
|
+
loadModel(fileName: string): void{
|
|
23
|
+
this.constructor2(fileName)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|