I was currently working on one of the assignments from the IBM Machine learning course. I ended up getting one error multiple times while training the model even when I set penalty = 'elasticnet'. I know that the elastic net model needs an L1 ratio and I am not even sure that I need to set the l1_ratio at all or where should I set the L1_ratio. The code I was working on is below:
#defining Logistic Regression with Elastic Net penalty
l1_ratio=0.5
#elastic net penalty to shrink coefficients without removing any features from the model
penalty= 'elasticnet'
# Our classification problem is multinomial
multi_class = 'multinomial'
#Use saga for elastic net penalty and multinomial classes. sklearn only support saga for elastic net
solver = 'saga'
#setting max iteration to 1000
max_iter = 1000
#Initiating the LogisticRegression and training the model
e_net_model = LogisticRegression(random_state=rs, penalty=penalty, multi_class=multi_class, solver=solver, max_iter = 1000)
#training
e_net_model.fit(X_train, y_train)
Error I was having while fitting the model:
TypeError Traceback (most recent call last)
Input In [60], in <cell line: 2>()
1 # Type your code here
----> 2 e_net_model.fit(X_train, y_train)
File ~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py:1291, in LogisticRegression.fit(self, X, y, sample_weight)
Try this code:
Also, make sure that your training data doesn't have missing values.