nlptoolkit-classification 1.0.5 → 1.0.7
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/dist/Model/DecisionTree/DecisionNode.d.ts +1 -0
- package/dist/Model/DecisionTree/DecisionNode.js +8 -2
- package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
- package/dist/Model/DeepNetworkModel.js +1 -1
- package/dist/Model/DeepNetworkModel.js.map +1 -1
- package/dist/Model/DummyModel.js +2 -12
- package/dist/Model/DummyModel.js.map +1 -1
- package/dist/Model/Model.d.ts +2 -0
- package/dist/Model/Model.js +15 -1
- package/dist/Model/Model.js.map +1 -1
- package/dist/Model/MultiLayerPerceptronModel.js +1 -1
- package/dist/Model/MultiLayerPerceptronModel.js.map +1 -1
- package/models/bagging-bupa.txt +10346 -0
- package/models/bagging-car.txt +40752 -0
- package/models/bagging-dermatology.txt +2990 -0
- package/models/bagging-iris.txt +1332 -0
- package/models/bagging-tictactoe.txt +29442 -0
- package/models/c45-bupa.txt +3 -0
- package/models/c45-car.txt +212 -0
- package/models/c45-carIndexed.txt +92 -0
- package/models/c45-dermatology.txt +22 -0
- package/models/c45-iris.txt +7 -0
- package/models/c45-tictactoe.txt +147 -0
- package/models/c45-tictactoeIndexed.txt +79 -0
- package/models/c45stump-bupa.txt +6 -0
- package/models/c45stump-car.txt +11 -0
- package/models/c45stump-chess.txt +35 -0
- package/models/c45stump-dermatology.txt +11 -0
- package/models/c45stump-iris.txt +5 -0
- package/models/c45stump-nursery.txt +10 -0
- package/models/c45stump-tictactoe.txt +9 -0
- package/models/deepNetwork-bupa.txt +1 -1
- package/models/deepNetwork-dermatology.txt +1 -1
- package/models/deepNetwork-iris.txt +1 -1
- package/models/multiLayerPerceptron-bupa.txt +1 -1
- package/models/multiLayerPerceptron-dermatology.txt +1 -1
- package/models/multiLayerPerceptron-iris.txt +1 -1
- package/models/randomforest-bupa.txt +10346 -0
- package/models/randomforest-car.txt +40752 -0
- package/models/randomforest-carIndexed.txt +15594 -0
- package/models/randomforest-dermatology.txt +2990 -0
- package/models/randomforest-iris.txt +1332 -0
- package/models/randomforest-tictactoe.txt +29442 -0
- package/package.json +1 -1
- package/source/Model/DecisionTree/DecisionNode.ts +10 -3
- package/source/Model/DecisionTree/DecisionTree.ts +0 -1
- package/source/Model/DeepNetworkModel.ts +1 -1
- package/source/Model/DummyModel.ts +1 -10
- package/source/Model/Model.ts +15 -0
- package/source/Model/MultiLayerPerceptronModel.ts +1 -1
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ export class DecisionNode {
|
|
|
20
20
|
private classLabel : string = undefined
|
|
21
21
|
leaf: boolean = false
|
|
22
22
|
private condition: DecisionCondition = undefined
|
|
23
|
+
private classLabelsDistribution: DiscreteDistribution
|
|
23
24
|
|
|
24
25
|
constructor1(data: InstanceList, condition?: DecisionCondition | number, parameter?: RandomForestParameter, isStump?: boolean){
|
|
25
26
|
let bestAttribute = -1
|
|
@@ -27,8 +28,13 @@ export class DecisionNode {
|
|
|
27
28
|
if (condition instanceof DecisionCondition){
|
|
28
29
|
this.condition = condition;
|
|
29
30
|
}
|
|
30
|
-
this.data = data
|
|
31
|
-
this.
|
|
31
|
+
this.data = data
|
|
32
|
+
this.classLabelsDistribution = new DiscreteDistribution()
|
|
33
|
+
let labels = data.getClassLabels()
|
|
34
|
+
for (let label of labels){
|
|
35
|
+
this.classLabelsDistribution.addItem(label)
|
|
36
|
+
}
|
|
37
|
+
this.classLabel = Model.getMaximum(labels)
|
|
32
38
|
this.leaf = true;
|
|
33
39
|
let classLabels = data.getDistinctClassLabels();
|
|
34
40
|
if (classLabels.length == 1) {
|
|
@@ -144,6 +150,7 @@ export class DecisionNode {
|
|
|
144
150
|
} else {
|
|
145
151
|
this.leaf = true
|
|
146
152
|
this.classLabel = contents.readLine()
|
|
153
|
+
this.classLabelsDistribution = Model.loadDiscreteDistribution(contents);
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
156
|
|
|
@@ -288,7 +295,7 @@ export class DecisionNode {
|
|
|
288
295
|
|
|
289
296
|
predictProbabilityDistribution(instance: Instance): Map<string, number>{
|
|
290
297
|
if (this.leaf) {
|
|
291
|
-
return this.
|
|
298
|
+
return this.classLabelsDistribution.getProbabilityDistribution();
|
|
292
299
|
} else {
|
|
293
300
|
for (let node of this.children) {
|
|
294
301
|
if (node.condition.satisfy(instance)) {
|
|
@@ -3,7 +3,6 @@ import {DecisionNode} from "./DecisionNode";
|
|
|
3
3
|
import {Instance} from "../../Instance/Instance";
|
|
4
4
|
import {CompositeInstance} from "../../Instance/CompositeInstance";
|
|
5
5
|
import {InstanceList} from "../../InstanceList/InstanceList";
|
|
6
|
-
import * as fs from "fs";
|
|
7
6
|
import {FileContents} from "nlptoolkit-util/dist/FileContents";
|
|
8
7
|
|
|
9
8
|
export class DecisionTree extends ValidatedModel{
|
|
@@ -125,13 +125,13 @@ export class DeepNetworkModel extends NeuralNetworkModel{
|
|
|
125
125
|
|
|
126
126
|
constructor2(fileName: string){
|
|
127
127
|
let input = new FileContents(fileName)
|
|
128
|
-
this.activationFunction = this.loadActivationFunction(input)
|
|
129
128
|
this.loadClassLabels(input)
|
|
130
129
|
this.hiddenLayerSize = parseInt(input.readLine())
|
|
131
130
|
this.weights = new Array<Matrix>()
|
|
132
131
|
for (let i = 0; i < this.hiddenLayerSize + 1; i++){
|
|
133
132
|
this.weights.push(this.loadMatrix(input))
|
|
134
133
|
}
|
|
134
|
+
this.activationFunction = this.loadActivationFunction(input)
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
@@ -20,16 +20,7 @@ export class DummyModel extends Model{
|
|
|
20
20
|
this.distribution = trainSet.classDistribution();
|
|
21
21
|
} else {
|
|
22
22
|
let input = new FileContents(trainSet)
|
|
23
|
-
this.distribution =
|
|
24
|
-
let size = parseInt(input.readLine())
|
|
25
|
-
for (let i = 0; i < size; i++){
|
|
26
|
-
let line = input.readLine()
|
|
27
|
-
let items = line.split(" ")
|
|
28
|
-
let count = parseInt(items[1])
|
|
29
|
-
for (let j = 0; j < count; j++){
|
|
30
|
-
this.distribution.addItem(items[0])
|
|
31
|
-
}
|
|
32
|
-
}
|
|
23
|
+
this.distribution = Model.loadDiscreteDistribution(input)
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
26
|
|
package/source/Model/Model.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {CounterHashMap} from "nlptoolkit-datastructure/dist/CounterHashMap";
|
|
|
3
3
|
import {FileContents} from "nlptoolkit-util/dist/FileContents";
|
|
4
4
|
import {InstanceList} from "../InstanceList/InstanceList";
|
|
5
5
|
import {Matrix} from "nlptoolkit-math/dist/Matrix";
|
|
6
|
+
import {DiscreteDistribution} from "nlptoolkit-math/dist/DiscreteDistribution";
|
|
6
7
|
|
|
7
8
|
export abstract class Model {
|
|
8
9
|
|
|
@@ -40,6 +41,20 @@ export abstract class Model {
|
|
|
40
41
|
return instance
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
static loadDiscreteDistribution(input: FileContents): DiscreteDistribution{
|
|
45
|
+
let distribution = new DiscreteDistribution()
|
|
46
|
+
let size = parseInt(input.readLine())
|
|
47
|
+
for (let i = 0; i < size; i++){
|
|
48
|
+
let line = input.readLine()
|
|
49
|
+
let items = line.split(" ")
|
|
50
|
+
let count = parseInt(items[1])
|
|
51
|
+
for (let j = 0; j < count; j++){
|
|
52
|
+
distribution.addItem(items[0])
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return distribution
|
|
56
|
+
}
|
|
57
|
+
|
|
43
58
|
loadInstanceList(input: FileContents): InstanceList{
|
|
44
59
|
let types = input.readLine().split(" ")
|
|
45
60
|
let instanceCount = parseInt(input.readLine())
|
|
@@ -80,10 +80,10 @@ export class MultiLayerPerceptronModel extends LinearPerceptronModel{
|
|
|
80
80
|
|
|
81
81
|
constructor2(fileName: string){
|
|
82
82
|
let input = new FileContents(fileName)
|
|
83
|
-
this.activationFunction = this.loadActivationFunction(input)
|
|
84
83
|
this.loadClassLabels(input)
|
|
85
84
|
this.W = this.loadMatrix(input)
|
|
86
85
|
this.V = this.loadMatrix(input)
|
|
86
|
+
this.activationFunction = this.loadActivationFunction(input)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|