Home
API
Examples
Github
Home
API
Examples
Github
  • API

    • cluster

      • KMeans
    • datasets

      • Boston
      • HeartDisease
      • Iris
    • decomposition

      • PCA
    • ensemble

      • BaggingClassifier
      • RandomForestClassifier
    • feature_extraction

      • CountVectorizer
    • linear_model

      • Lasso
      • LinearRegression
      • LogisticRegression
      • Ridge
      • SGDClassifier
      • SGDRegressor
    • metrics

      • accuracyScore
      • confusion_matrix
      • mean_absolute_error
      • mean_squared_error
      • mean_squared_log_error
      • zeroOneLoss
    • model_selection

      • KFold
      • train_test_split
    • naive_bayes

      • GaussianNB
      • MultinomialNB
    • neighbors

      • KNeighborsClassifier
    • preprocessing

      • Binarizer
      • Imputer
      • LabelEncoder
      • MinMaxScaler
      • OneHotEncoder
      • PolynomialFeatures
      • add_dummy_feature
      • normalize
    • svm

      • BaseSVM
      • NuSVC
      • NuSVR
      • OneClassSVM
      • SVC
      • SVR
    • tree

      • DecisionTreeClassifier

preprocessing.OneHotEncoder

Usage

const enc = new OneHotEncoder();
const planetList = [
 { planet: 'mars', isGasGiant: false, value: 10 },
 { planet: 'saturn', isGasGiant: true, value: 20 },
 { planet: 'jupiter', isGasGiant: true, value: 30 }
];
const encodeInfo = enc.encode(planetList, {
 dataKeys: ['value', 'isGasGiant'],
 labelKeys: ['planet']
});
// encodeInfo.data -> [ [ -1, 0, 1, 0, 0 ], [ 0, 1, 0, 1, 0 ], [ 1, 1, 0, 0, 1 ] ]
const decodedInfo = enc.decode(encodeInfo.data, encodeInfo.decoders);
// gives you back the original value, which is `planetList`

Constructors

  • constructor

Methods

  • decode

  • encode

Constructors


constructor

⊕ OneHotEncoder()

Defined in

Parameters:

ParamTypeDefaultDescription

Returns: OneHotEncoder

Methods


λ decode

Decode the encoded data back into its original format

Defined in preprocessing/data.ts:188

Parameters:

ParamTypeDefaultDescription
encodedany
decodersany

Returns:

any[]

λ encode

encode data according to dataKeys and labelKeys

Defined in preprocessing/data.ts:105

Parameters:

ParamTypeDefaultDescription
dataanynulllist of records to encode
dataKeysstring[]null
labelKeysstring[]null

Returns:

ParamTypeDescription
dataany[]Encoded data
decodersany[]Decoder
Prev
MinMaxScaler
Next
PolynomialFeatures