feat: fixed tests · javascriptdata/scikit.js@3f6654d · GitHub
Skip to content

Commit 3f6654d

Browse files
committed
feat: fixed tests
1 parent 3251738 commit 3f6654d

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

‎src/neighbors/kNeighborsClassifier.test.ts‎

Lines changed: 21 additions & 17 deletions

‎src/neighbors/kNeighborsRegressor.test.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import { KNeighborsRegressor } from './kNeighborsRegressor'
1717
import { KNeighborsParams } from './kNeighborsBase'
18-
import { fetchCaliforniaHousing, loadDiabetes } from '../datasets/datasets'
18+
import { dataUrls } from '../datasets/datasets'
1919
import { arrayEqual } from '../utils'
2020
import { crossValScore } from '../model_selection/crossValScore'
2121
import { KFold } from '../model_selection/kFold'
@@ -28,15 +28,16 @@ type Tensor1D = tf.Tensor1D
2828
type Tensor2D = tf.Tensor2D
2929

3030
function testWithDataset(
31-
loadData: () => string,
31+
loadDataUrl: string,
32+
loadDataName: string,
3233
params: KNeighborsParams,
3334
referenceError: number
3435
) {
3536
it(
36-
`matches sklearn fitting ${loadData.name}`.padEnd(48) +
37+
`matches sklearn fitting ${loadDataName}`.padEnd(48) +
3738
JSON.stringify(params),
3839
async () => {
39-
const df = await dfd.readCSV(loadData())
40+
const df = await dfd.readCSV(loadDataUrl)
4041

4142
const Xy = df.tensor as unknown as Tensor2D
4243
let [nSamples, nFeatures] = Xy.shape
@@ -70,32 +71,37 @@ for (const algorithm of [
7071
]) {
7172
describe(`KNeighborsRegressor({ algorithm: ${algorithm} })`, function () {
7273
testWithDataset(
73-
loadDiabetes,
74+
dataUrls.loadDiabetes,
75+
'loadDiabetes',
7476
{ nNeighbors: 5, weights: 'distance', algorithm },
7577
3570
7678
)
7779
testWithDataset(
78-
loadDiabetes,
80+
dataUrls.loadDiabetes,
81+
'loadDiabetes',
7982
{ nNeighbors: 3, weights: 'uniform', algorithm },
8083
3833
8184
)
8285
if ('kdTree' === algorithm) {
8386
testWithDataset(
84-
fetchCaliforniaHousing,
87+
dataUrls.fetchCaliforniaHousing,
88+
'fetchCaliforniaHousing',
8589
{ nNeighbors: 3, weights: 'distance', algorithm },
8690
1.31
8791
)
8892
}
8993
if ('auto' === algorithm) {
9094
testWithDataset(
91-
fetchCaliforniaHousing,
95+
dataUrls.fetchCaliforniaHousing,
96+
'fetchCaliforniaHousing',
9297
{ nNeighbors: 4, weights: 'uniform', algorithm, p: 1 },
9398
1.19
9499
)
95100
}
96101
if (undefined === algorithm) {
97102
testWithDataset(
98-
fetchCaliforniaHousing,
103+
dataUrls.fetchCaliforniaHousing,
104+
'fetchCaliforniaHousing',
99105
{ nNeighbors: 4, weights: 'uniform', algorithm, p: Infinity },
100106
1.32
101107
)

‎src/tree/decisiontree.test.ts‎

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)