Options
All
  • Public
  • Public/Protected
  • All
Menu

class creating sparse matrices from a corpus

memberof

nlp

Hierarchy

  • ColumnVectorizer

Index

Constructors

constructor

  • new ColumnVectorizer(options?: { data?: string[]; maxFeatures?: number }): ColumnVectorizer
  • creates a new instance for classifying text data for machine learning

    example

    const dataset = new ms.nlp.ColumnVectorizer(csvData);

    prop

    {Object[]} this.data - Array of strings

    prop

    {Set} this.tokens - Unique collection of all tokenized strings

    prop

    {Object[]} this.vectors - Array of tokenized words with value of count of appreance in string

    prop

    {Object} this.wordMap - Object of all unique words, with value of 0

    prop

    {Object} this.wordCountMap - Object of all unique words, with value as total count of appearances

    prop

    {number} this.maxFeatures - max number of features

    prop

    {String[]} this.sortedWordCount - list of words as tokens sorted by total appearances

    prop

    {String[]} this.limitedFeatures - subset list of maxFeatures words as tokens sorted by total appearances

    prop

    {Array[]} this.matrix - words in sparse matrix

    prop

    {Function} this.replacer - clean string function

    Parameters

    • Default value options: { data?: string[]; maxFeatures?: number } = {}
      • Optional data?: string[]
      • Optional maxFeatures?: number

    Returns ColumnVectorizer

Properties

data

data: string[]

limitedFeatures

limitedFeatures: string[][]

matrix

matrix: Matrix

Optional maxFeatures

maxFeatures: number

replacer

replacer: (value: string) => string

Type declaration

    • (value: string): string
    • Parameters

      • value: string

      Returns string

sortedWordCount

sortedWordCount: string[]

tokens

tokens: Set<string>

vectors

vectors: WordMap[]

wordCountMap

wordCountMap: WordMap

wordMap

wordMap: WordMap

Methods

evaluate

  • evaluate(testString?: string, options: { maxFeatures?: number }): any
  • returns new matrix of words with counts in columns

    example

    ColumnVectorizer.evaluate('I would rate everything Great, views Great, food Great') => [ [ 0, 1, 3, 0, 0, 0, 0, 0, 1 ] ]

    Parameters

    • Default value testString: string = ""
    • options: { maxFeatures?: number }
      • Optional maxFeatures?: number

    Returns any

    sparse matrix row for new classification predictions

evaluateString

  • evaluateString(testString?: string): WordMap
  • returns word map with counts

    example

    ColumnVectorizer.evaluateString('I would rate everything Great, views Great, food Great') => { realli: 0, good: 0, definit: 0, recommend: 0, wait: 0, staff: 0, rude: 0, great: 3, view: 1, food: 1, not: 0, cold: 0, took: 0, forev: 0, seat: 0, time: 0, prompt: 0, attent: 0, bland: 0, flavor: 0, kind: 0 }

    Parameters

    • Default value testString: string = ""

    Returns WordMap

    object of corpus words with accounts

fit_transform

  • fit_transform(options?: { data?: string[]; maxFeatures?: number }): number[][]
  • Fits and transforms data by creating column vectors (a sparse matrix where each row has every word in the corpus as a column and the count of appearances in the corpus)

    Parameters

    • Default value options: { data?: string[]; maxFeatures?: number } = {}
      • Optional data?: string[]

        array of corpus data

      • Optional maxFeatures?: number

    Returns number[][]

get_limited_features

  • get_limited_features(options?: { maxFeatures?: number }): string[][]
  • Returns limited sets of dependent features or all dependent features sorted by word count

    Parameters

    • Default value options: { maxFeatures?: number } = {}
      • Optional maxFeatures?: number

        max number of features

    Returns string[][]

get_tokens

  • get_tokens(): string[]
  • Returns a distinct array of all tokens

    Returns string[]

    returns a distinct array of all tokens

get_vector_array

  • get_vector_array(): string[][]
  • Returns array of arrays of strings for dependent features from sparse matrix word map

    Returns string[][]

    returns array of dependent features for DataSet column matrics