c

com.johnsnowlabs.nlp.annotators.classification

DocumentLogRegClassifierApproach

class DocumentLogRegClassifierApproach extends AnnotatorApproach[DocumentLogRegClassifierModel] with CheckLicense

Trains a model to classify documents with a Logarithmic Regression algorithm. Training data requires columns for text and their label. The result is a trained DocumentLogRegClassifierModel.

Example

Define pipeline stages to prepare the data

val document_assembler = new DocumentAssembler()
  .setInputCol("text")
  .setOutputCol("document")

val tokenizer = new Tokenizer()
  .setInputCols("document")
  .setOutputCol("token")

val normalizer = new Normalizer()
  .setInputCols("token")
  .setOutputCol("normalized")

val stopwords_cleaner = new StopWordsCleaner()
  .setInputCols("normalized")
  .setOutputCol("cleanTokens")
  .setCaseSensitive(false)

val stemmer = new Stemmer()
  .setInputCols("cleanTokens")
  .setOutputCol("stem")

Define the document classifier and fit training data to it

val logreg = new DocumentLogRegClassifierApproach()
  .setInputCols("stem")
  .setLabelCol("category")
  .setOutputCol("prediction")

val pipeline = new Pipeline().setStages(Array(
  document_assembler,
  tokenizer,
  normalizer,
  stopwords_cleaner,
  stemmer,
  logreg
))

val model = pipeline.fit(trainingData)
See also

DocumentLogRegClassifierModel for instantiated models

Linear Supertypes
CheckLicense, AnnotatorApproach[DocumentLogRegClassifierModel], CanBeLazy, DefaultParamsWritable, MLWritable, HasOutputAnnotatorType, HasOutputAnnotationCol, HasInputAnnotationCols, Estimator[DocumentLogRegClassifierModel], PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. DocumentLogRegClassifierApproach
  2. CheckLicense
  3. AnnotatorApproach
  4. CanBeLazy
  5. DefaultParamsWritable
  6. MLWritable
  7. HasOutputAnnotatorType
  8. HasOutputAnnotationCol
  9. HasInputAnnotationCols
  10. Estimator
  11. PipelineStage
  12. Logging
  13. Params
  14. Serializable
  15. Serializable
  16. Identifiable
  17. AnyRef
  18. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new DocumentLogRegClassifierApproach()
  2. new DocumentLogRegClassifierApproach(uid: String)

    uid

    a unique identifier for the instantiated AnnotatorModel

Type Members

  1. type AnnotatorType = String
    Definition Classes
    HasOutputAnnotatorType

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def $[T](param: Param[T]): T
    Attributes
    protected
    Definition Classes
    Params
  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. def _fit(dataset: Dataset[_], recursiveStages: Option[PipelineModel]): DocumentLogRegClassifierModel
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def beforeTraining(spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  8. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  9. def checkValidEnvironment(spark: Option[SparkSession], scopes: Seq[String], metadata: Option[Map[String, Value]]): Unit
    Definition Classes
    CheckLicense
  10. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  11. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkSession], checkLp: Boolean, metadata: Option[Map[String, Value]]): Unit
    Definition Classes
    CheckLicense
  12. def checkValidScopesAndEnvironment(scopes: Seq[String], spark: Option[SparkSession], checkLp: Boolean, metadata: Option[Map[String, Value]]): Unit
    Definition Classes
    CheckLicense
  13. val classificationModelPath: Param[String]

    specify the classification model if it has been already trained.

  14. final def clear(param: Param[_]): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    Params
  15. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  16. final def copy(extra: ParamMap): Estimator[DocumentLogRegClassifierModel]
    Definition Classes
    AnnotatorApproach → Estimator → PipelineStage → Params
  17. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  18. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  19. val description: String
    Definition Classes
    DocumentLogRegClassifierApproach → AnnotatorApproach
  20. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  22. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  23. def explainParams(): String
    Definition Classes
    Params
  24. final val extraInputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  25. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  26. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  27. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  28. final def fit(dataset: Dataset[_]): DocumentLogRegClassifierModel
    Definition Classes
    AnnotatorApproach → Estimator
  29. def fit(dataset: Dataset[_], paramMaps: Seq[ParamMap]): Seq[DocumentLogRegClassifierModel]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  30. def fit(dataset: Dataset[_], paramMap: ParamMap): DocumentLogRegClassifierModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  31. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DocumentLogRegClassifierModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  32. val fitIntercept: Param[Boolean]

    whether to fit an intercept term (Default: true)

  33. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  34. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  35. def getClassificationModelPath: String

    specify the classification model if it has been already trained.

  36. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  37. def getFitIntercept: Boolean

    whether to fit an intercept term (Default: true)

  38. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  39. def getLabelCol: String

    column with the value result we are trying to predict.

  40. def getLabels: Array[String]

    array to output the label in the original form.

  41. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  42. def getMaxIter: Int

    maximum number of iterations (Default: 10)

  43. def getMergeChunks: Boolean

    whether to merge all chunks in a document or not (Default: false)

  44. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  45. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  46. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  47. def getTol: Double

    convergence tolerance after each iteration (Default: 1e-6)

  48. def getVectorizationModelPath: String

    specify the vectorization model if it has been already trained.

  49. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  50. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  51. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  52. lazy val idf: IDF
  53. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  54. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  55. val inputAnnotatorTypes: Array[AnnotatorType]

    Input annotator types: TOKEN

    Input annotator types: TOKEN

    Definition Classes
    DocumentLogRegClassifierApproach → HasInputAnnotationCols
  56. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  57. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  58. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  59. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  60. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  61. val labelCol: Param[String]

    column with the value result we are trying to predict.

  62. lazy val labelEncodedCol: String
  63. lazy val labelPredictedCol: String
  64. lazy val labelRawCol: String
  65. val labels: StringArrayParam

    array to output the label in the original form.

  66. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  67. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  68. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  69. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  70. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  71. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  72. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  73. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  74. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  75. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  76. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  77. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  78. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  79. lazy val lrClassifier: LogisticRegression
  80. val maxIter: Param[Int]

    maximum number of iterations (Default: 10)

  81. val mergeChunks: BooleanParam

    whether to merge all chunks in a document or not (Default: false)

  82. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  83. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  84. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  85. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  86. def onTrained(model: DocumentLogRegClassifierModel, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  87. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  88. val outputAnnotatorType: AnnotatorType

    Output annotator types: CATEGORY

    Output annotator types: CATEGORY

    Definition Classes
    DocumentLogRegClassifierApproach → HasOutputAnnotatorType
  89. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  90. lazy val ovrClassifier: OneVsRest
  91. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  92. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  93. final def set(paramPair: ParamPair[_]): DocumentLogRegClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  94. final def set(param: String, value: Any): DocumentLogRegClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  95. final def set[T](param: Param[T], value: T): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    Params
  96. def setClassificationModelPath(value: String): DocumentLogRegClassifierApproach.this.type

    specify the classification model if it has been already trained.

  97. final def setDefault(paramPairs: ParamPair[_]*): DocumentLogRegClassifierApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  98. final def setDefault[T](param: Param[T], value: T): DocumentLogRegClassifierApproach.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  99. def setExtraInputCols(value: Array[String]): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  100. def setFitIntercept(value: Boolean): DocumentLogRegClassifierApproach.this.type

    whether to fit an intercept term (Default: true)

  101. final def setInputCols(value: String*): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  102. def setInputCols(value: Array[String]): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  103. def setLabelCol(value: String): DocumentLogRegClassifierApproach.this.type

    column with the value result we are trying to predict.

  104. def setLabels(value: Array[String]): DocumentLogRegClassifierApproach.this.type

    array to output the label in the original form.

  105. def setLazyAnnotator(value: Boolean): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    CanBeLazy
  106. def setMaxIter(value: Int): DocumentLogRegClassifierApproach.this.type

    maximum number of iterations (Default: 10)

  107. def setMergeChunks(value: Boolean): DocumentLogRegClassifierApproach.this.type

    whether to merge all chunks in a document or not (Default: false)

  108. final def setOutputCol(value: String): DocumentLogRegClassifierApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  109. def setTol(value: Double): DocumentLogRegClassifierApproach.this.type

    convergence tolerance after each iteration (Default: 1e-6)

  110. def setVectorizationModelPath(value: String): DocumentLogRegClassifierApproach.this.type

    specify the vectorization model if it has been already trained.

  111. lazy val sidx: StringIndexer
  112. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  113. lazy val tf: HashingTF
  114. lazy val tfCol: String
  115. lazy val tfidfCol: String
  116. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  117. lazy val tokenAnnotationCol: String
  118. lazy val tokenRawCol: String
  119. val tol: Param[Double]

    convergence tolerance after each iteration (Default: 1e-6)

  120. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): DocumentLogRegClassifierModel
    Definition Classes
    DocumentLogRegClassifierApproach → AnnotatorApproach
  121. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  122. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  123. val uid: String
    Definition Classes
    DocumentLogRegClassifierApproach → Identifiable
  124. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  125. val vectorizationModelPath: Param[String]

    specify the vectorization model if it has been already trained.

  126. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  127. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  128. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  129. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from CheckLicense

Inherited from AnnotatorApproach[DocumentLogRegClassifierModel]

Inherited from CanBeLazy

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from HasOutputAnnotatorType

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from Estimator[DocumentLogRegClassifierModel]

Inherited from PipelineStage

Inherited from Logging

Inherited from Params

Inherited from Serializable

Inherited from Serializable

Inherited from Identifiable

Inherited from AnyRef

Inherited from Any

Parameters

Annotator types

Required input and expected output annotator types

Members

Parameter setters

Parameter getters