public class NaiveBayes extends ProbabilisticClassifier<Vector,NaiveBayes,NaiveBayesModel> implements DefaultParamsWritable
http://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html
)
which can handle finitely supported discrete data. For example, by converting documents into
TF-IDF vectors, it can be used for document classification. By making every vector a
binary (0/1) data, it can also be used as Bernoulli NB
(http://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
).
The input feature values must be nonnegative.Constructor and Description |
---|
NaiveBayes() |
NaiveBayes(String uid) |
Modifier and Type | Method and Description |
---|---|
static Params |
clear(Param<?> param) |
NaiveBayes |
copy(ParamMap extra)
Creates a copy of this instance with the same UID and some extra params.
|
static String |
explainParam(Param<?> param) |
static String |
explainParams() |
static ParamMap |
extractParamMap() |
static ParamMap |
extractParamMap(ParamMap extra) |
static Param<String> |
featuresCol() |
Param<String> |
featuresCol()
Param for features column name.
|
static M |
fit(Dataset<?> dataset) |
static M |
fit(Dataset<?> dataset,
ParamMap paramMap) |
static scala.collection.Seq<M> |
fit(Dataset<?> dataset,
ParamMap[] paramMaps) |
static M |
fit(Dataset<?> dataset,
ParamPair<?> firstParamPair,
ParamPair<?>... otherParamPairs) |
static M |
fit(Dataset<?> dataset,
ParamPair<?> firstParamPair,
scala.collection.Seq<ParamPair<?>> otherParamPairs) |
static <T> scala.Option<T> |
get(Param<T> param) |
static <T> scala.Option<T> |
getDefault(Param<T> param) |
static String |
getFeaturesCol() |
String |
getFeaturesCol() |
static String |
getLabelCol() |
String |
getLabelCol() |
static String |
getModelType() |
String |
getModelType() |
static <T> T |
getOrDefault(Param<T> param) |
static Param<Object> |
getParam(String paramName) |
static String |
getPredictionCol() |
String |
getPredictionCol() |
static String |
getProbabilityCol() |
static String |
getRawPredictionCol() |
String |
getRawPredictionCol() |
static double |
getSmoothing() |
double |
getSmoothing() |
static double[] |
getThresholds() |
static <T> boolean |
hasDefault(Param<T> param) |
static boolean |
hasParam(String paramName) |
static boolean |
isDefined(Param<?> param) |
static boolean |
isSet(Param<?> param) |
static Param<String> |
labelCol() |
Param<String> |
labelCol()
Param for label column name.
|
static NaiveBayes |
load(String path) |
static Param<String> |
modelType() |
Param<String> |
modelType()
The model type which is a string (case-sensitive).
|
static Param<?>[] |
params() |
static Param<String> |
predictionCol() |
Param<String> |
predictionCol()
Param for prediction column name.
|
static Param<String> |
probabilityCol() |
static Param<String> |
rawPredictionCol() |
Param<String> |
rawPredictionCol()
Param for raw prediction (a.k.a.
|
static void |
save(String path) |
static <T> Params |
set(Param<T> param,
T value) |
static Learner |
setFeaturesCol(String value) |
static Learner |
setLabelCol(String value) |
NaiveBayes |
setModelType(String value)
Set the model type using a string (case-sensitive).
|
static Learner |
setPredictionCol(String value) |
static E |
setProbabilityCol(String value) |
static E |
setRawPredictionCol(String value) |
NaiveBayes |
setSmoothing(double value)
Set the smoothing parameter.
|
static E |
setThresholds(double[] value) |
static DoubleParam |
smoothing() |
DoubleParam |
smoothing()
The smoothing parameter.
|
static DoubleArrayParam |
thresholds() |
static String |
toString() |
static StructType |
transformSchema(StructType schema) |
String |
uid()
An immutable unique ID for the object and its derivatives.
|
StructType |
validateAndTransformSchema(StructType schema,
boolean fitting,
DataType featuresDataType) |
StructType |
validateAndTransformSchema(StructType schema,
boolean fitting,
DataType featuresDataType)
Validates and transforms the input schema with the provided param map.
|
static void |
validateParams() |
static MLWriter |
write() |
setProbabilityCol, setThresholds
setRawPredictionCol
fit, setFeaturesCol, setLabelCol, setPredictionCol, transformSchema
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
write
save
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn, validateParams
toString
public static NaiveBayes load(String path)
public static String toString()
public static Param<?>[] params()
public static void validateParams()
public static String explainParam(Param<?> param)
public static String explainParams()
public static final boolean isSet(Param<?> param)
public static final boolean isDefined(Param<?> param)
public static boolean hasParam(String paramName)
public static Param<Object> getParam(String paramName)
public static final <T> scala.Option<T> get(Param<T> param)
public static final <T> T getOrDefault(Param<T> param)
public static final <T> scala.Option<T> getDefault(Param<T> param)
public static final <T> boolean hasDefault(Param<T> param)
public static final ParamMap extractParamMap()
public static M fit(Dataset<?> dataset, ParamPair<?> firstParamPair, scala.collection.Seq<ParamPair<?>> otherParamPairs)
public static M fit(Dataset<?> dataset, ParamPair<?> firstParamPair, ParamPair<?>... otherParamPairs)
public static final Param<String> labelCol()
public static final String getLabelCol()
public static final Param<String> featuresCol()
public static final String getFeaturesCol()
public static final Param<String> predictionCol()
public static final String getPredictionCol()
public static Learner setLabelCol(String value)
public static Learner setFeaturesCol(String value)
public static Learner setPredictionCol(String value)
public static M fit(Dataset<?> dataset)
public static StructType transformSchema(StructType schema)
public static final Param<String> rawPredictionCol()
public static final String getRawPredictionCol()
public static E setRawPredictionCol(String value)
public static final Param<String> probabilityCol()
public static final String getProbabilityCol()
public static final DoubleArrayParam thresholds()
public static double[] getThresholds()
public static E setProbabilityCol(String value)
public static E setThresholds(double[] value)
public static final DoubleParam smoothing()
public static final double getSmoothing()
public static final Param<String> modelType()
public static final String getModelType()
public static void save(String path) throws java.io.IOException
java.io.IOException
public static MLWriter write()
public String uid()
Identifiable
uid
in interface Identifiable
public NaiveBayes setSmoothing(double value)
value
- (undocumented)public NaiveBayes setModelType(String value)
value
- (undocumented)public NaiveBayes copy(ParamMap extra)
Params
defaultCopy()
.copy
in interface Params
copy
in class Predictor<Vector,NaiveBayes,NaiveBayesModel>
extra
- (undocumented)public DoubleParam smoothing()
public double getSmoothing()
public Param<String> modelType()
public String getModelType()
public StructType validateAndTransformSchema(StructType schema, boolean fitting, DataType featuresDataType)
public Param<String> rawPredictionCol()
public String getRawPredictionCol()
public StructType validateAndTransformSchema(StructType schema, boolean fitting, DataType featuresDataType)
schema
- input schemafitting
- whether this is in fittingfeaturesDataType
- SQL DataType for FeaturesType.
E.g., VectorUDT
for vector features.public Param<String> labelCol()
public String getLabelCol()
public Param<String> featuresCol()
public String getFeaturesCol()
public Param<String> predictionCol()
public String getPredictionCol()