1- import * as tf from "@tensorflow/tfjs" ;
1+ import { tensor , moments } from "@tensorflow/tfjs" ;
22import { Series } from "../core/series" ;
33import { DataFrame } from "../core/frame" ;
44import { Utils } from "../core/utils" ;
@@ -14,12 +14,12 @@ export class MinMaxScaler {
1414 fit ( data ) {
1515 let tensor_data = null ;
1616 if ( Array . isArray ( data ) ) {
17- tensor_data = tf . tensor ( data ) ;
17+ tensor_data = tensor ( data ) ;
1818 } else if ( data instanceof DataFrame || data instanceof Series ) {
1919 if ( data . dtypes . includes ( "string" ) ) {
2020 throw Error ( "Dtype Error: Cannot perform operation on string dtypes" ) ;
2121 }
22- tensor_data = tf . tensor ( data . values ) ;
22+ tensor_data = tensor ( data . values ) ;
2323 } else {
2424 throw new Error ( "data must either be an Array, DataFrame or Series" ) ;
2525 }
@@ -49,14 +49,14 @@ export class MinMaxScaler {
4949 if ( data . dtypes . includes ( "string" ) ) {
5050 throw Error ( "Dtype Error: Cannot perform operation on string dtypes" ) ;
5151 }
52- let tensor_data = tf . tensor ( data . values ) ;
52+ let tensor_data = tensor ( data . values ) ;
5353 let output_data = tensor_data
5454 . sub ( this . min )
5555 . div ( this . max . sub ( this . min ) )
5656 . arraySync ( ) ;
5757 return new Series ( output_data ) ;
5858 } else if ( Array . isArray ( data ) ) {
59- let tensor_data = tf . tensor ( data ) ;
59+ let tensor_data = tensor ( data ) ;
6060 let output_data = tensor_data
6161 . sub ( this . min )
6262 . div ( this . max . sub ( this . min ) )
@@ -70,7 +70,7 @@ export class MinMaxScaler {
7070 if ( data . dtypes . includes ( "string" ) ) {
7171 throw Error ( "Dtype Error: Cannot perform operation on string dtypes" ) ;
7272 }
73- let tensor_data = tf . tensor ( data . values ) ;
73+ let tensor_data = tensor ( data . values ) ;
7474 let output_data = tensor_data
7575 . sub ( this . min )
7676 . div ( this . max . sub ( this . min ) )
@@ -91,17 +91,17 @@ export class StandardScaler {
9191 fit ( data ) {
9292 let tensor_data = null ;
9393 if ( Array . isArray ( data ) ) {
94- tensor_data = tf . tensor ( data ) ;
94+ tensor_data = tensor ( data ) ;
9595 } else if ( data instanceof DataFrame || data instanceof Series ) {
9696 if ( data . dtypes . includes ( "string" ) ) {
9797 throw Error ( "Dtype Error: Cannot perform operation on string dtypes" ) ;
9898 }
99- tensor_data = tf . tensor ( data . values ) ;
99+ tensor_data = tensor ( data . values ) ;
100100 } else {
101101 throw new Error ( "data must either be an Array, DataFrame or Series" ) ;
102102 }
103103
104- this . std = tf . moments ( tensor_data , 0 ) . variance . sqrt ( ) ;
104+ this . std = moments ( tensor_data , 0 ) . variance . sqrt ( ) ;
105105 this . mean = tensor_data . mean ( 0 ) ;
106106 let output_data = tensor_data . sub ( this . mean ) . div ( this . std ) . arraySync ( ) ;
107107
@@ -121,11 +121,11 @@ export class StandardScaler {
121121 if ( data . dtypes . includes ( "string" ) ) {
122122 throw Error ( "Dtype Error: Cannot perform operation on string dtypes" ) ;
123123 }
124- let tensor_data = tf . tensor ( data . values ) ;
124+ let tensor_data = tensor ( data . values ) ;
125125 let output_data = tensor_data . sub ( this . mean ) . div ( this . std ) . arraySync ( ) ;
126126 return new Series ( output_data ) ;
127127 } else if ( Array . isArray ( data ) ) {
128- let tensor_data = tf . tensor ( data ) ;
128+ let tensor_data = tensor ( data ) ;
129129 let output_data = tensor_data . sub ( this . mean ) . div ( this . std ) . arraySync ( ) ;
130130 if ( utils . __is_1D_array ( data ) ) {
131131 return new Series ( output_data ) ;
@@ -136,7 +136,7 @@ export class StandardScaler {
136136 if ( data . dtypes . includes ( "string" ) ) {
137137 throw Error ( "Dtype Error: Cannot perform operation on string dtypes" ) ;
138138 }
139- let tensor_data = tf . tensor ( data . values ) ;
139+ let tensor_data = tensor ( data . values ) ;
140140 let output_data = tensor_data . sub ( this . mean ) . div ( this . std ) . arraySync ( ) ;
141141 return new DataFrame ( output_data ) ;
142142 } else {
@@ -245,21 +245,21 @@ export class StandardScaler {
245245// let tensor_data = null
246246// let isTensor = false;
247247// if(Array.isArray(data)){
248- // tensor_data = tf. tensor(data)
248+ // tensor_data = tensor(data)
249249// }
250250// else if((data instanceof DataFrame)){
251- // tensor_data = tf. tensor(data.values)
251+ // tensor_data = tensor(data.values)
252252// isTensor = true;
253253// }
254254// else if((data instanceof Series)){
255- // tensor_data = tf. tensor(data.values)
255+ // tensor_data = tensor(data.values)
256256// }
257257// else{
258258// throw new Error("data must either be an Array, DataFrame or Series")
259259// }
260260
261261// let [q1, q3, median] = this.quantile(data,isTensor)
262- // let q3_tensor = tf. tensor(q3)
262+ // let q3_tensor = tensor(q3)
263263// let output_data = tensor_data.sub(median).div(q3_tensor.sub(q1)).arraySync()
264264
265265// return output_data;
0 commit comments