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,18 @@
|
|
|
1
|
+
export enum AttributeType {
|
|
2
|
+
/**
|
|
3
|
+
* Continuous Attribute
|
|
4
|
+
*/
|
|
5
|
+
CONTINUOUS,
|
|
6
|
+
/**
|
|
7
|
+
* Discrete Attribute
|
|
8
|
+
*/
|
|
9
|
+
DISCRETE,
|
|
10
|
+
/**
|
|
11
|
+
* Binary Attribute
|
|
12
|
+
*/
|
|
13
|
+
BINARY,
|
|
14
|
+
/**
|
|
15
|
+
* Discrete Indexed Attribute is used to store the indices.
|
|
16
|
+
*/
|
|
17
|
+
DISCRETE_INDEXED
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {DiscreteAttribute} from "./DiscreteAttribute";
|
|
2
|
+
|
|
3
|
+
export class BinaryAttribute extends DiscreteAttribute{
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Constructor for a binary discrete attribute. The attribute can take only two values "True" or "False".
|
|
7
|
+
*
|
|
8
|
+
* @param value Value of the attribute. Can be true or false.
|
|
9
|
+
*/
|
|
10
|
+
constructor(value: boolean) {
|
|
11
|
+
super(value == true ? "1" : "0");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {Attribute} from "./Attribute";
|
|
2
|
+
|
|
3
|
+
export class ContinuousAttribute extends Attribute{
|
|
4
|
+
|
|
5
|
+
private value: number
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Constructor for a continuous attribute.
|
|
9
|
+
*
|
|
10
|
+
* @param value Value of the attribute.
|
|
11
|
+
*/
|
|
12
|
+
constructor(value: number) {
|
|
13
|
+
super();
|
|
14
|
+
this.value = value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Accessor method for value.
|
|
19
|
+
*
|
|
20
|
+
* @return value
|
|
21
|
+
*/
|
|
22
|
+
getValue(): number{
|
|
23
|
+
return this.value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Mutator method for value
|
|
28
|
+
*
|
|
29
|
+
* @param value New value of value.
|
|
30
|
+
*/
|
|
31
|
+
setValue(value: number){
|
|
32
|
+
this.value = value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Converts value to {@link String}.
|
|
37
|
+
*
|
|
38
|
+
* @return String representation of value.
|
|
39
|
+
*/
|
|
40
|
+
toString(): string{
|
|
41
|
+
return this.value.toString()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
continuousAttributeSize(): number {
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
continuousAttributes(): Array<number> {
|
|
49
|
+
let result = new Array<number>();
|
|
50
|
+
result.push(this.value)
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {Attribute} from "./Attribute";
|
|
2
|
+
|
|
3
|
+
export class DiscreteAttribute extends Attribute{
|
|
4
|
+
|
|
5
|
+
private value: string = "NULL"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Constructor for a discrete attribute.
|
|
9
|
+
*
|
|
10
|
+
* @param value Value of the attribute.
|
|
11
|
+
*/
|
|
12
|
+
constructor(value: string) {
|
|
13
|
+
super();
|
|
14
|
+
this.value = value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Accessor method for value.
|
|
19
|
+
*
|
|
20
|
+
* @return value
|
|
21
|
+
*/
|
|
22
|
+
getValue(): string{
|
|
23
|
+
return this.value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Converts value to {@link String}.
|
|
28
|
+
*
|
|
29
|
+
* @return String representation of value.
|
|
30
|
+
*/
|
|
31
|
+
toString(): string{
|
|
32
|
+
if (this.value == ","){
|
|
33
|
+
return "comma";
|
|
34
|
+
}
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
continuousAttributeSize(): number {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
continuousAttributes(): Array<number> {
|
|
43
|
+
return new Array<number>();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {DiscreteAttribute} from "./DiscreteAttribute";
|
|
2
|
+
|
|
3
|
+
export class DiscreteIndexedAttribute extends DiscreteAttribute{
|
|
4
|
+
|
|
5
|
+
private index: number
|
|
6
|
+
private maxIndex: number
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Constructor for a discrete attribute.
|
|
10
|
+
*
|
|
11
|
+
* @param value Value of the attribute.
|
|
12
|
+
* @param index Index of the attribute.
|
|
13
|
+
* @param maxIndex Maximum index of the attribute.
|
|
14
|
+
*/
|
|
15
|
+
constructor(value: string, index: number, maxIndex: number) {
|
|
16
|
+
super(value);
|
|
17
|
+
this.index = index
|
|
18
|
+
this.maxIndex = maxIndex
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Accessor method for index.
|
|
23
|
+
*
|
|
24
|
+
* @return index.
|
|
25
|
+
*/
|
|
26
|
+
getIndex(): number{
|
|
27
|
+
return this.index
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Accessor method for maxIndex.
|
|
32
|
+
*
|
|
33
|
+
* @return maxIndex.
|
|
34
|
+
*/
|
|
35
|
+
getMaxIndex(): number{
|
|
36
|
+
return this.maxIndex
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
continuousAttributeSize(): number {
|
|
40
|
+
return this.maxIndex
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
continuousAttributes(): Array<number> {
|
|
44
|
+
let result = new Array<number>()
|
|
45
|
+
for (let i = 0; i < this.maxIndex; i++) {
|
|
46
|
+
if (i != this.index) {
|
|
47
|
+
result.push(0.0);
|
|
48
|
+
} else {
|
|
49
|
+
result.push(1.0);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {BaggingParameter} from "../Parameter/BaggingParameter";
|
|
5
|
+
import {DecisionTree} from "../Model/DecisionTree/DecisionTree";
|
|
6
|
+
import {DecisionNode} from "../Model/DecisionTree/DecisionNode";
|
|
7
|
+
import {TreeEnsembleModel} from "../Model/TreeEnsembleModel";
|
|
8
|
+
|
|
9
|
+
export class Bagging extends Classifier{
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Bagging bootstrap ensemble method that creates individuals for its ensemble by training each classifier on a random
|
|
13
|
+
* redistribution of the training set.
|
|
14
|
+
* This training method is for a bagged decision tree classifier. 20 percent of the instances are left aside for pruning of the trees
|
|
15
|
+
* 80 percent of the instances are used for training the trees. The number of trees (forestSize) is a parameter, and basically
|
|
16
|
+
* the method will learn an ensemble of trees as a model.
|
|
17
|
+
*
|
|
18
|
+
* @param trainSet Training data given to the algorithm.
|
|
19
|
+
* @param parameters Parameters of the bagging trees algorithm. ensembleSize returns the number of trees in the bagged forest.
|
|
20
|
+
*/
|
|
21
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
22
|
+
let forestSize = (<BaggingParameter> parameters).getEnsembleSize();
|
|
23
|
+
let forest = new Array<DecisionTree>();
|
|
24
|
+
for (let i = 0; i < forestSize; i++) {
|
|
25
|
+
let bootstrap = trainSet.bootstrap(i);
|
|
26
|
+
let tree = new DecisionTree(new DecisionNode(new InstanceList(bootstrap.getSample()), undefined, undefined, false));
|
|
27
|
+
forest.push(tree);
|
|
28
|
+
}
|
|
29
|
+
this.model = new TreeEnsembleModel(forest);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {C45Parameter} from "../Parameter/C45Parameter";
|
|
5
|
+
import {Partition} from "../InstanceList/Partition";
|
|
6
|
+
import {DecisionTree} from "../Model/DecisionTree/DecisionTree";
|
|
7
|
+
import {DecisionNode} from "../Model/DecisionTree/DecisionNode";
|
|
8
|
+
|
|
9
|
+
export class C45 extends Classifier{
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Training algorithm for C4.5 univariate decision tree classifier. 20 percent of the data are left aside for pruning
|
|
13
|
+
* 80 percent of the data is used for constructing the tree.
|
|
14
|
+
*
|
|
15
|
+
* @param trainSet Training data given to the algorithm.
|
|
16
|
+
* @param parameters -
|
|
17
|
+
*/
|
|
18
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
19
|
+
let tree: DecisionTree
|
|
20
|
+
if ((<C45Parameter> parameters).isPrune()) {
|
|
21
|
+
let partition = new Partition(trainSet, (<C45Parameter> parameters).getCrossValidationRatio(), true);
|
|
22
|
+
tree = new DecisionTree(new DecisionNode(partition.get(1), undefined, undefined, false));
|
|
23
|
+
tree.prune(partition.get(0));
|
|
24
|
+
} else {
|
|
25
|
+
tree = new DecisionTree(new DecisionNode(trainSet, undefined, undefined, false));
|
|
26
|
+
}
|
|
27
|
+
this.model = tree;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {DecisionTree} from "../Model/DecisionTree/DecisionTree";
|
|
5
|
+
import {DecisionNode} from "../Model/DecisionTree/DecisionNode";
|
|
6
|
+
|
|
7
|
+
export class C45Stump extends Classifier{
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Training algorithm for C4.5 Stump univariate decision tree classifier.
|
|
11
|
+
*
|
|
12
|
+
* @param trainSet Training data given to the algorithm.
|
|
13
|
+
* @param parameters -
|
|
14
|
+
*/
|
|
15
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
16
|
+
this.model = new DecisionTree(new DecisionNode(trainSet, undefined, undefined, true));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {Model} from "../Model/Model";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {Instance} from "../Instance/Instance";
|
|
5
|
+
import {DiscreteAttribute} from "../Attribute/DiscreteAttribute";
|
|
6
|
+
import {DiscreteIndexedAttribute} from "../Attribute/DiscreteIndexedAttribute";
|
|
7
|
+
import {ConfusionMatrix} from "../Performance/ConfusionMatrix";
|
|
8
|
+
import {Performance} from "../Performance/Performance";
|
|
9
|
+
import {DetailedClassificationPerformance} from "../Performance/DetailedClassificationPerformance";
|
|
10
|
+
|
|
11
|
+
export abstract class Classifier {
|
|
12
|
+
|
|
13
|
+
protected model: Model
|
|
14
|
+
|
|
15
|
+
abstract train(trainSet: InstanceList, parameters: Parameter):void
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks given instance's attribute and returns true if it is a discrete indexed attribute, false otherwise.
|
|
19
|
+
*
|
|
20
|
+
* @param instance Instance to check.
|
|
21
|
+
* @return True if instance is a discrete indexed attribute, false otherwise.
|
|
22
|
+
*/
|
|
23
|
+
discreteCheck(instance: Instance): boolean{
|
|
24
|
+
for (let i = 0; i < instance.attributeSize(); i++) {
|
|
25
|
+
if (instance.getAttribute(i) instanceof DiscreteAttribute &&
|
|
26
|
+
!(instance.getAttribute(i) instanceof DiscreteIndexedAttribute)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* TestClassification an instance list with the current model.
|
|
35
|
+
*
|
|
36
|
+
* @param testSet Test data (list of instances) to be tested.
|
|
37
|
+
* @return The accuracy (and error) of the model as an instance of Performance class.
|
|
38
|
+
*/
|
|
39
|
+
test(testSet: InstanceList): Performance{
|
|
40
|
+
let classLabels = testSet.getUnionOfPossibleClassLabels();
|
|
41
|
+
let confusion = new ConfusionMatrix(classLabels);
|
|
42
|
+
for (let i = 0; i < testSet.size(); i++) {
|
|
43
|
+
let instance = testSet.get(i);
|
|
44
|
+
confusion.classify(instance.getClassLabel(), this.model.predict(instance));
|
|
45
|
+
}
|
|
46
|
+
return new DetailedClassificationPerformance(confusion);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Runs current classifier with the given train and test data.
|
|
51
|
+
*
|
|
52
|
+
* @param parameter Parameter of the classifier to be trained.
|
|
53
|
+
* @param trainSet Training data to be used in training the classifier.
|
|
54
|
+
* @param testSet Test data to be tested after training the model.
|
|
55
|
+
* @return The accuracy (and error) of the trained model as an instance of Performance class.
|
|
56
|
+
* @throws DiscreteFeaturesNotAllowed Exception for discrete features.
|
|
57
|
+
*/
|
|
58
|
+
singleRun(parameter: Parameter, trainSet: InstanceList, testSet: InstanceList): Performance{
|
|
59
|
+
this.train(trainSet, parameter);
|
|
60
|
+
return this.test(testSet);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Accessor for the model.
|
|
65
|
+
*
|
|
66
|
+
* @return Model.
|
|
67
|
+
*/
|
|
68
|
+
getModel(): Model{
|
|
69
|
+
return this.model
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {Partition} from "../InstanceList/Partition";
|
|
5
|
+
import {DeepNetworkParameter} from "../Parameter/DeepNetworkParameter";
|
|
6
|
+
import {DeepNetworkModel} from "../Model/DeepNetworkModel";
|
|
7
|
+
|
|
8
|
+
export class DeepNetwork extends Classifier{
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Training algorithm for deep network classifier.
|
|
12
|
+
*
|
|
13
|
+
* @param trainSet Training data given to the algorithm.
|
|
14
|
+
* @param parameters Parameters of the deep network algorithm. crossValidationRatio and seed are used as parameters.
|
|
15
|
+
* @throws DiscreteFeaturesNotAllowed Exception for discrete features.
|
|
16
|
+
*/
|
|
17
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
18
|
+
let partition = new Partition(trainSet, (<DeepNetworkParameter> parameters).getCrossValidationRatio(), true);
|
|
19
|
+
this.model = new DeepNetworkModel(partition.get(1), partition.get(0), <DeepNetworkParameter> parameters);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {DummyModel} from "../Model/DummyModel";
|
|
5
|
+
|
|
6
|
+
export class Dummy extends Classifier{
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Training algorithm for the dummy classifier. Actually dummy classifier returns the maximum occurring class in
|
|
10
|
+
* the training data, there is no training.
|
|
11
|
+
*
|
|
12
|
+
* @param trainSet Training data given to the algorithm.
|
|
13
|
+
* @param parameters -
|
|
14
|
+
*/
|
|
15
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
16
|
+
this.model = new DummyModel(trainSet);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {Partition} from "../InstanceList/Partition";
|
|
5
|
+
import {KMeansModel} from "../Model/KMeansModel";
|
|
6
|
+
import {KMeansParameter} from "../Parameter/KMeansParameter";
|
|
7
|
+
|
|
8
|
+
export class KMeans extends Classifier{
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Training algorithm for K-Means classifier. K-Means finds the mean of each class for training.
|
|
12
|
+
*
|
|
13
|
+
* @param trainSet Training data given to the algorithm.
|
|
14
|
+
* @param parameters distanceMetric: distance metric used to calculate the distance between two instances.
|
|
15
|
+
*/
|
|
16
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
17
|
+
let priorDistribution = trainSet.classDistribution();
|
|
18
|
+
let classMeans = new InstanceList();
|
|
19
|
+
let classLists = new Partition(trainSet);
|
|
20
|
+
for (let i = 0; i < classLists.size(); i++) {
|
|
21
|
+
classMeans.add(classLists.get(i).average());
|
|
22
|
+
}
|
|
23
|
+
this.model = new KMeansModel(priorDistribution, classMeans, (<KMeansParameter> parameters).getDistanceMetric());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {KnnModel} from "../Model/KnnModel";
|
|
5
|
+
import {KnnParameter} from "../Parameter/KnnParameter";
|
|
6
|
+
|
|
7
|
+
export class Knn extends Classifier{
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Training algorithm for K-nearest neighbor classifier.
|
|
12
|
+
*
|
|
13
|
+
* @param trainSet Training data given to the algorithm.
|
|
14
|
+
* @param parameters K: k parameter of the K-nearest neighbor algorithm
|
|
15
|
+
* distanceMetric: distance metric used to calculate the distance between two instances.
|
|
16
|
+
*/
|
|
17
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
18
|
+
this.model = new KnnModel(trainSet, (<KnnParameter> parameters).getK(), (<KnnParameter> parameters).getDistanceMetric());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {Vector} from "nlptoolkit-math/dist/Vector";
|
|
5
|
+
import {Partition} from "../InstanceList/Partition";
|
|
6
|
+
import {Matrix} from "nlptoolkit-math/dist/Matrix";
|
|
7
|
+
import {InstanceListOfSameClass} from "../InstanceList/InstanceListOfSameClass";
|
|
8
|
+
import {LdaModel} from "../Model/LdaModel";
|
|
9
|
+
|
|
10
|
+
export class Lda extends Classifier{
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Training algorithm for the linear discriminant analysis classifier (Introduction to Machine Learning, Alpaydin, 2015).
|
|
14
|
+
*
|
|
15
|
+
* @param trainSet Training data given to the algorithm.
|
|
16
|
+
* @param parameters -
|
|
17
|
+
*/
|
|
18
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
19
|
+
let w0 = new Map<string, number>();
|
|
20
|
+
let w = new Map<string, Vector>();
|
|
21
|
+
let priorDistribution = trainSet.classDistribution();
|
|
22
|
+
let classLists = new Partition(trainSet);
|
|
23
|
+
let covariance = new Matrix(trainSet.get(0).continuousAttributeSize(), trainSet.get(0).continuousAttributeSize());
|
|
24
|
+
for (let i = 0; i < classLists.size(); i++) {
|
|
25
|
+
let averageVector = new Vector(classLists.get(i).continuousAttributeAverage());
|
|
26
|
+
let classCovariance = classLists.get(i).covariance(averageVector);
|
|
27
|
+
classCovariance.multiplyWithConstant(classLists.get(i).size() - 1);
|
|
28
|
+
covariance.add(classCovariance);
|
|
29
|
+
}
|
|
30
|
+
covariance.divideByConstant(trainSet.size() - classLists.size());
|
|
31
|
+
covariance.inverse();
|
|
32
|
+
for (let i = 0; i < classLists.size(); i++) {
|
|
33
|
+
let Ci = (<InstanceListOfSameClass> classLists.get(i)).getClassLabel();
|
|
34
|
+
let averageVector = new Vector(classLists.get(i).continuousAttributeAverage());
|
|
35
|
+
let wi = covariance.multiplyWithVectorFromRight(averageVector);
|
|
36
|
+
w.set(Ci, wi);
|
|
37
|
+
let w0i = -0.5 * wi.dotProduct(averageVector) + Math.log(priorDistribution.getProbability(Ci));
|
|
38
|
+
w0.set(Ci, w0i);
|
|
39
|
+
}
|
|
40
|
+
this.model = new LdaModel(priorDistribution, w, w0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {Partition} from "../InstanceList/Partition";
|
|
5
|
+
import {LinearPerceptronParameter} from "../Parameter/LinearPerceptronParameter";
|
|
6
|
+
import {LinearPerceptronModel} from "../Model/LinearPerceptronModel";
|
|
7
|
+
|
|
8
|
+
export class LinearPerceptron extends Classifier{
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Training algorithm for the linear perceptron algorithm. 20 percent of the data is separated as cross-validation
|
|
12
|
+
* data used for selecting the best weights. 80 percent of the data is used for training the linear perceptron with
|
|
13
|
+
* gradient descent.
|
|
14
|
+
*
|
|
15
|
+
* @param trainSet Training data given to the algorithm
|
|
16
|
+
* @param parameters Parameters of the linear perceptron.
|
|
17
|
+
*/
|
|
18
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
19
|
+
let partition = new Partition(trainSet, (<LinearPerceptronParameter> parameters).getCrossValidationRatio(), true);
|
|
20
|
+
this.model = new LinearPerceptronModel(partition.get(1), partition.get(0), <LinearPerceptronParameter> parameters);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {Partition} from "../InstanceList/Partition";
|
|
5
|
+
import {MultiLayerPerceptronParameter} from "../Parameter/MultiLayerPerceptronParameter";
|
|
6
|
+
import {MultiLayerPerceptronModel} from "../Model/MultiLayerPerceptronModel";
|
|
7
|
+
|
|
8
|
+
export class MultiLayerPerceptron extends Classifier{
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Training algorithm for the multilayer perceptron algorithm. 20 percent of the data is separated as cross-validation
|
|
12
|
+
* data used for selecting the best weights. 80 percent of the data is used for training the multilayer perceptron with
|
|
13
|
+
* gradient descent.
|
|
14
|
+
*
|
|
15
|
+
* @param trainSet Training data given to the algorithm
|
|
16
|
+
* @param parameters Parameters of the multilayer perceptron.
|
|
17
|
+
*/
|
|
18
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
19
|
+
let partition = new Partition(trainSet, (<MultiLayerPerceptronParameter> parameters).getCrossValidationRatio(), true);
|
|
20
|
+
this.model = new MultiLayerPerceptronModel(partition.get(1), partition.get(0), <MultiLayerPerceptronParameter> parameters);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {DiscreteDistribution} from "nlptoolkit-math/dist/DiscreteDistribution";
|
|
5
|
+
import {Partition} from "../InstanceList/Partition";
|
|
6
|
+
import {Vector} from "nlptoolkit-math/dist/Vector";
|
|
7
|
+
import {InstanceListOfSameClass} from "../InstanceList/InstanceListOfSameClass";
|
|
8
|
+
import {NaiveBayesModel} from "../Model/NaiveBayesModel";
|
|
9
|
+
import {DiscreteAttribute} from "../Attribute/DiscreteAttribute";
|
|
10
|
+
|
|
11
|
+
export class NaiveBayes extends Classifier{
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Training algorithm for Naive Bayes algorithm with a continuous data set.
|
|
15
|
+
*
|
|
16
|
+
* @param priorDistribution Probability distribution of classes P(C_i)
|
|
17
|
+
* @param classLists Instances are divided into K lists, where each list contains only instances from a single class
|
|
18
|
+
*/
|
|
19
|
+
private trainContinuousVersion(priorDistribution: DiscreteDistribution, classLists: Partition){
|
|
20
|
+
let classMeans = new Map<string, Vector>();
|
|
21
|
+
let classDeviations = new Map<string, Vector>();
|
|
22
|
+
for (let i = 0; i < classLists.size(); i++){
|
|
23
|
+
let classLabel = (<InstanceListOfSameClass> classLists.get(i)).getClassLabel();
|
|
24
|
+
let averageVector = classLists.get(i).average().toVector();
|
|
25
|
+
classMeans.set(classLabel, averageVector);
|
|
26
|
+
let standardDeviationVector = classLists.get(i).standardDeviation().toVector();
|
|
27
|
+
classDeviations.set(classLabel, standardDeviationVector);
|
|
28
|
+
}
|
|
29
|
+
this.model = new NaiveBayesModel(priorDistribution, classMeans, classDeviations);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Training algorithm for Naive Bayes algorithm with a discrete data set.
|
|
34
|
+
* @param priorDistribution Probability distribution of classes P(C_i)
|
|
35
|
+
* @param classLists Instances are divided into K lists, where each list contains only instances from a single class
|
|
36
|
+
*/
|
|
37
|
+
private trainDiscreteVersion(priorDistribution: DiscreteDistribution, classLists: Partition){
|
|
38
|
+
let classAttributeDistributions = new Map<String, Array<DiscreteDistribution>>();
|
|
39
|
+
for (let i = 0; i < classLists.size(); i++){
|
|
40
|
+
classAttributeDistributions.set((<InstanceListOfSameClass> classLists.get(i)).getClassLabel(),
|
|
41
|
+
classLists.get(i).allAttributesDistribution());
|
|
42
|
+
}
|
|
43
|
+
this.model = new NaiveBayesModel(priorDistribution, classAttributeDistributions);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Training algorithm for Naive Bayes algorithm. It basically calls trainContinuousVersion for continuous data sets,
|
|
48
|
+
* trainDiscreteVersion for discrete data sets.
|
|
49
|
+
* @param trainSet Training data given to the algorithm
|
|
50
|
+
* @param parameters -
|
|
51
|
+
*/
|
|
52
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
53
|
+
let priorDistribution = trainSet.classDistribution();
|
|
54
|
+
let classLists = new Partition(trainSet);
|
|
55
|
+
if (classLists.get(0).get(0).getAttribute(0) instanceof DiscreteAttribute){
|
|
56
|
+
this.trainDiscreteVersion(priorDistribution, classLists);
|
|
57
|
+
} else {
|
|
58
|
+
this.trainContinuousVersion(priorDistribution, classLists);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
3
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
4
|
+
import {Vector} from "nlptoolkit-math/dist/Vector";
|
|
5
|
+
import {Matrix} from "nlptoolkit-math/dist/Matrix";
|
|
6
|
+
import {Partition} from "../InstanceList/Partition";
|
|
7
|
+
import {InstanceListOfSameClass} from "../InstanceList/InstanceListOfSameClass";
|
|
8
|
+
import {QdaModel} from "../Model/QdaModel";
|
|
9
|
+
|
|
10
|
+
export class Qda extends Classifier{
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Training algorithm for the quadratic discriminant analysis classifier (Introduction to Machine Learning, Alpaydin, 2015).
|
|
14
|
+
*
|
|
15
|
+
* @param trainSet Training data given to the algorithm.
|
|
16
|
+
* @param parameters -
|
|
17
|
+
*/
|
|
18
|
+
train(trainSet: InstanceList, parameters: Parameter) {
|
|
19
|
+
let determinant = 0
|
|
20
|
+
let w0 = new Map<string, number>();
|
|
21
|
+
let w = new Map<string, Vector>();
|
|
22
|
+
let W = new Map<string, Matrix>();
|
|
23
|
+
let classLists = new Partition(trainSet);
|
|
24
|
+
let priorDistribution = trainSet.classDistribution();
|
|
25
|
+
for (let i = 0; i < classLists.size(); i++) {
|
|
26
|
+
let Ci = (<InstanceListOfSameClass> classLists.get(i)).getClassLabel();
|
|
27
|
+
let averageVector = new Vector(classLists.get(i).continuousAttributeAverage());
|
|
28
|
+
let classCovariance = classLists.get(i).covariance(averageVector);
|
|
29
|
+
determinant = classCovariance.determinant();
|
|
30
|
+
classCovariance.inverse();
|
|
31
|
+
let Wi = classCovariance.clone();
|
|
32
|
+
Wi.multiplyWithConstant(-0.5);
|
|
33
|
+
W.set(Ci, Wi);
|
|
34
|
+
let wi = classCovariance.multiplyWithVectorFromLeft(averageVector);
|
|
35
|
+
w.set(Ci, wi);
|
|
36
|
+
let w0i = -0.5 * (wi.dotProduct(averageVector) + Math.log(determinant)) + Math.log(priorDistribution.getProbability(Ci));
|
|
37
|
+
w0.set(Ci, w0i);
|
|
38
|
+
}
|
|
39
|
+
this.model = new QdaModel(priorDistribution, W, w, w0);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {Classifier} from "./Classifier";
|
|
2
|
+
import {InstanceList} from "../InstanceList/InstanceList";
|
|
3
|
+
import {Parameter} from "../Parameter/Parameter";
|
|
4
|
+
import {RandomModel} from "../Model/RandomModel";
|
|
5
|
+
|
|
6
|
+
export class RandomClassifier extends Classifier{
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Training algorithm for random classifier.
|
|
10
|
+
*
|
|
11
|
+
* @param trainSet Training data given to the algorithm.
|
|
12
|
+
* @param parameters -
|
|
13
|
+
*/
|
|
14
|
+
train(trainSet: InstanceList, parameters: Parameter): void {
|
|
15
|
+
let result = new Array<string>()
|
|
16
|
+
for (let s of trainSet.classDistribution().keys()){
|
|
17
|
+
result.push(s)
|
|
18
|
+
}
|
|
19
|
+
this.model = new RandomModel(result, parameters.getSeed());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|