You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by aditya1702 <ad...@gmail.com> on 2016/10/21 15:39:26 UTC

Plotting decision boundary in non-linear logistic regression

Hello,
I am working with Logistic Regression on a non linear data and I want to
plot a decision boundary using the data. I dont know how do I do it using
the contour plot. Could someone help me out please. This is the code I have
written:

from pyspark.ml.classification import LogisticRegression


lr=LogisticRegression(maxIter=1000,regParam=0.3,elasticNetParam=0.20)
model=lr.fit(data_train_df)

prediction = model.transform(data_test_df)
prediction.select(col('label'),col('prediction'))
final_pred_df=prediction.select(col('label'),col('prediction'))
ans=final_pred_df.where(col('label')==col('prediction')).count()
final_pred_df.show()
accuracy=ans/float(final_pred_df.count())
print accuracy*100

This gives the following output:

+-----+----------+
|label|prediction|
+-----+----------+
|  1.0|       1.0|
|  1.0|       1.0|
|  1.0|       1.0|
|  1.0|       1.0|
|  1.0|       1.0|
|  0.0|       0.0|
|  0.0|       0.0|
|  0.0|       1.0|
|  0.0|       1.0|
|  0.0|       1.0|
|  0.0|       1.0|
|  0.0|       1.0|
|  0.0|       0.0|
|  0.0|       0.0|
|  0.0|       0.0|
|  0.0|       0.0|
|  0.0|       0.0|
+-----+----------+

70.5882352941

Now how do I visualize this. The data plot is somewhat like this:

<http://apache-spark-user-list.1001560.n3.nabble.com/file/n27937/pic1.png> 



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/Plotting-decision-boundary-in-non-linear-logistic-regression-tp27937.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org