I am trying to implement Logistic Regression using pySpark Here is my code
from pyspark.mllib.classification import LogisticRegressionWithLBFGS
from time import time
from pyspark.mllib.regression import LabeledPoint
from numpy import array
RES_DIR="/home/shaahmed115/Pet_Projects/DA/TwitterStream_US_Elections/Features/"
sc= SparkContext('local','pyspark')
data_file = RES_DIR + "training.txt"
raw_data = sc.textFile(data_file)
print "Train data size is {}".format(raw_data.count())
test_data_file = RES_DIR + "testing.txt"
test_raw_data = sc.textFile(test_data_file)
print "Test data size is {}".format(test_raw_data.count())
def parse_interaction(line):
line_split = line.split(",")
return LabeledPoint(float(line_split[0]), array([float(x) for x in line_split]))
training_data = raw_data.map(parse_interaction)
logit_model = LogisticRegressionWithLBFGS.train(training_data,iterations=10, numClasses=3)
This is throwing an error : Currently, LogisticRegression with ElasticNet in ML package only supports binary classification. Found 3 in the input dataset
Below is a sample of my dataset: 2 , 1.0 , 1.0 , 1.0 0 , 1.0 , 1.0 , 1.0 1 , 0.0 , 0.0 , 0.0
The first element is the class while the rest is the vector.As you can see there are three classes. Is there a workaround that can make multinomial classification work with this?