LinearSVC¶
-
class
snap_ml_spark.estimator.
LinearSVC
(featuresCol='features', labelCol='label', predictionCol='prediction', trainingHistory=0, maxIter=1000, regParam=1.0, tol=0.001, rawPredictionCol='rawPrediction', standardization=True, weightCol=None, useGpu=False, dual=True, balanced=False, nthreads=-1, gpuMemLimit=0, verbose=False)¶ -
>>> from pyspark.sql import Row >>> from pyspark.ml.linalg import Vectors >>> df = sc.parallelize([ ... Row(label=1.0, features=Vectors.dense(1.0, 1.0, 1.0)), ... Row(label=0.0, features=Vectors.dense(1.0, 2.0, 3.0))]).toDF() >>> svm = LinearSVC(maxIter=5, regParam=0.01) >>> model = svm.fit(df) >>> model.coefficients DenseVector([0.0, -0.2792, -0.1833]) >>> model.intercept 1.0206118982229047 >>> model.numClasses 2 >>> model.numFeatures 3 >>> test0 = sc.parallelize([Row(features=Vectors.dense(-1.0, -1.0, -1.0))]).toDF() >>> result = model.transform(test0).head() >>> result.prediction 1.0 >>> result.rawPrediction DenseVector([-1.4831, 1.4831]) >>> svm_path = temp_path + "/svm" >>> svm.save(svm_path) >>> svm2 = LinearSVC.load(svm_path) >>> svm2.getMaxIter() 5 >>> model_path = temp_path + "/svm_model" >>> model.save(model_path) >>> model2 = LinearSVCModel.load(model_path) >>> model.coefficients[0] == model2.coefficients[0] True >>> model.intercept == model2.intercept True
-
getBalanced
()¶ Gets the value of balanced or its default value.
-
getDual
()¶ Gets the value of dual or its default value.
-
getGpuMemLimit
()¶ Gets the value of gpuMemLimit or its default value.
-
getNthreads
()¶ Gets the value of nthreads or its default value.
-
getTrainingHistory
()¶ Gets the value of trainingHistory or its default value.
-
getUseGpu
()¶ Gets the value of useGpu or its default value.
-
getVerbose
()¶ Gets the value of verbose or its default value.
-
setBalanced
(value)¶ Sets the value of
balanced
.
-
setDual
(value)¶ Sets the value of
dual
.
-
setGpuMemLimit
(value)¶ Sets the value of
gpuMemLimit
.
-
setNthreads
(value)¶ Sets the value of
nthreads
.
-
setParams
(featuresCol='features', labelCol='label', predictionCol='prediction', trainingHistory=0, maxIter=1000, regParam=1.0, tol=0.001, rawPredictionCol='rawPrediction', standardization=True, weightCol=None, useGpu=False, dual=True, balanced=False, nthreads=-1, gpuMemLimit=0, verbose=False)¶ setParams(featuresCol=”features”, labelCol=”label”, predictionCol=”prediction”, trainingHistory=0, maxIter=1000, regParam=1.0, tol=1e-3, rawPredictionCol=”rawPrediction”, standardization=True, weightCol=None, useGpu=False, dual=True, balanced=False, nthreads=-1, gpuMemLimit=0, verbose=False): Sets params for Linear SVM Classifier.
-
setTrainingHistory
(value)¶ Sets the value of
trainingHistory
.
-
setUseGpu
(value)¶ Sets the value of
useGpu
.
-
setVerbose
(value)¶ Sets the value of
verbose
.
-