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

metrics.confusion_matrix

▸ confusion_matrix(y_true: `object`, y_pred: `object`, labels: `object`)

Usage

import { confusion_matrix } from 'machinelearn/metrics';

const matrix1 = confusion_matrix([1, 2, 3], [1, 2, 3]);
console.log(matrix1); // [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]

const matrix2 = confusion_matrix(
  ['cat', 'ant', 'cat', 'cat', 'ant', 'bird'],
  ['ant', 'ant', 'cat', 'cat', 'ant', 'cat']
);
console.log(matrix2); // [ [ 1, 2, 0 ], [ 2, 0, 0 ], [ 0, 1, 0 ] ]

Defined in metrics/classification.ts:189

Parameters:

ParamTypeDefaultDescription
y_truestring[] or number[]nullGround truth (correct) target values.
y_predstring[] or number[]nullEstimated targets as returned by a classifier.
options.labelsany[]null

Returns:

number[]

Prev
accuracyScore
Next
mean_absolute_error