1515
1616import { KNeighborsRegressor } from './kNeighborsRegressor'
1717import { KNeighborsParams } from './kNeighborsBase'
18- import { fetchCaliforniaHousing , loadDiabetes } from '../datasets/datasets'
18+ import { dataUrls } from '../datasets/datasets'
1919import { arrayEqual } from '../utils'
2020import { crossValScore } from '../model_selection/crossValScore'
2121import { KFold } from '../model_selection/kFold'
@@ -28,15 +28,16 @@ type Tensor1D = tf.Tensor1D
2828type Tensor2D = tf . Tensor2D
2929
3030function 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 )
0 commit comments