11import { tf } from '../shared/globals'
22import { SimpleImputer } from './SimpleImputer'
3-
3+ import { toObject , fromObject } from '../simpleSerializer'
44describe ( 'SimpleImputer' , function ( ) {
55 it ( 'Imputes with "constant" strategy 2D one column. In this strategy, we give the fill value' , function ( ) {
66 const imputer = new SimpleImputer ( { strategy : 'constant' , fillValue : 3 } )
@@ -119,7 +119,7 @@ describe('SimpleImputer', function () {
119119 expect ( returned . arraySync ( ) ) . toEqual ( expected )
120120 expect ( imputer . transform ( [ [ NaN , NaN ] ] ) . arraySync ( ) ) . toEqual ( [ [ 4 , 3 ] ] )
121121 } )
122- it ( 'Should serialized Imputer' , function ( ) {
122+ it ( 'Should serialized Imputer' , async function ( ) {
123123 const imputer = new SimpleImputer ( { strategy : 'mostFrequent' } )
124124
125125 const data = [
@@ -129,21 +129,21 @@ describe('SimpleImputer', function () {
129129 [ 4 , 2 ] ,
130130 [ 6 , NaN ]
131131 ]
132-
133132 const expected = {
134133 name : 'SimpleImputer' ,
135- missingValues : null ,
134+ missingValues : NaN ,
135+ fillValue : undefined ,
136136 strategy : 'mostFrequent' ,
137137 statistics : {
138- type : 'Tensor' ,
138+ name : 'Tensor' ,
139139 value : [ 4 , 3 ]
140140 }
141141 }
142142
143- const returned = imputer . fitTransform ( data )
144- expect ( JSON . parse ( imputer . toJson ( ) as string ) ) . toEqual ( expected )
143+ imputer . fitTransform ( data )
144+ expect ( await toObject ( imputer ) ) . toEqual ( expected )
145145 } )
146- it ( 'Should load serialized Imputer' , function ( ) {
146+ it ( 'Should load serialized Imputer' , async function ( ) {
147147 const imputer = new SimpleImputer ( { strategy : 'mostFrequent' } )
148148
149149 const data = [
@@ -162,8 +162,9 @@ describe('SimpleImputer', function () {
162162 [ 6 , 3 ]
163163 ]
164164
165- const returned = imputer . fitTransform ( data )
166- const newImputer = new SimpleImputer ( ) . fromJson ( imputer . toJson ( ) as string )
165+ imputer . fitTransform ( data )
166+ const thing = await toObject ( imputer )
167+ const newImputer = await fromObject ( thing )
167168 const newReturned = newImputer . transform ( data )
168169 expect ( newReturned . arraySync ( ) ) . toEqual ( expected )
169170 expect ( newImputer . transform ( [ [ NaN , NaN ] ] ) . arraySync ( ) ) . toEqual ( [ [ 4 , 3 ] ] )
0 commit comments