Could you please tell me how can I use Elastic-Net, Lasso and Ridge regression in Pyspark? Actually I chose Linear, Elastic-Net, Lasso and Ridge regression these 4 algorithms according to machine learning cheatsheet. However, I don't know how to import Elastic-Net, Lasso and Ridge regression in Pyspark and cannot google the right answers. I just know using the Linear Regression in Pyspark.
Apr 5, 2022 799 views

## 1 answer to this question.

Use the code and also refer to the documentation of apache spark.

```from pyspark.ml.regression import LinearRegression
from pyspark.mllib.regression import LabeledPoint
from pyspark.mllib.util import MLUtils

lr = LinearRegression(maxIter=10, regParam=0.3, elasticNetParam=0.8)

# Fit the model
linear_Model = lr.fit(training)

# Print the weights and intercept for linear regression
print("Weights: " + str(linear_Model.weights))
print("Intercept: " + str(linear_Model.intercept))```

If you look closely at the configuration, you'll notice that:

Elastic net includes both L1 and L2 regularisation as special instances when set properly. For example, a Lasso model is created by training a linear regression model with the elastic net parameter α set to 1. If α set to 0, on the other hand, the trained model is reduced to a ridge regression model.

Where:

elasticNetParam is equivalent to α and regParam is equivalent to λ.

• 6,000 points

## Related Questions In Machine Learning

I am working on a chatbot for ...READ MORE

## How can I train a model and calculate the accuracy of CBR algorithm?

Hi@Abubakar, You can find lots of documents on ...READ MORE

## How do I create a linear regression model in Weka without training?

Weka is a classification algorithm. This is ...READ MORE

## Python code for basic linear regression

Hi @Dipti, you could try something like ...READ MORE

## Show python implementation of Lasso class - regression

Hey @Tanmay, try something like this: >>> from ...READ MORE

## What is LassoLars? - Linear regression

LassoLars is a lasso model implemented using ...READ MORE

## Can you give LassoLars python example?

Hey @Vivek, Try something like this: >>> from ...READ MORE