/** * @license * Copyright 2021, JsData. All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================================== */ import { Scikit2D, Tensor2D, Tensor } from '../types'; import { TransformerMixin } from '../mixins'; export interface StandardScalerParams { /** Whether or not we should subtract the mean. **default = true** */ withMean?: boolean; /** Whether or not we should divide by the standard deviation. **default = true** */ withStd?: boolean; } /** * Standardize features by removing the mean and scaling to unit variance. * The standard score of a sample x is calculated as: $z = (x - u) / s$, * where $u$ is the mean of the training samples, and $s$ is the standard deviation of the training samples. * * @example * ```js * import { StandardScaler } from 'scikitjs' * * const data = [ [0, 0], [0, 0], [1, 1], [1, 1] ] const scaler = new StandardScaler() const expected = scaler.fitTransform(data) // const expected = [ // [-1, -1], // [-1, -1], // [1, 1], // [1, 1] // ] * ``` */ export declare class StandardScaler extends TransformerMixin { /** The per-feature scale that we see in the dataset. We divide by this number. */ scale: Tensor; /** The per-feature mean that we see in the dataset. We subtract by this number. */ mean: Tensor; /** Whether or not we should subtract the mean */ withMean: boolean; /** Whether or not we should divide by the standard deviation */ withStd: boolean; /** The number of features seen during fit */ nFeaturesIn: number; /** The number of samples processed by the Estimator. Will be reset on new calls to fit */ nSamplesSeen: number; /** Names of features seen during fit. Only stores feature names if input is a DataFrame */ featureNamesIn: Array; /** Useful for pipelines and column transformers to have a default name for transforms */ name: string; constructor({ withMean, withStd }?: StandardScalerParams); /** * Fit a StandardScaler to the data. */ fit(X: Scikit2D): StandardScaler; /** * Transform the data using the fitted scaler */ transform(X: Scikit2D): Tensor2D; /** * Inverse transform the data using the fitted scaler */ inverseTransform(X: Scikit2D): Tensor2D; }