Question: rror Traceback ( most recent call last ) Cell In [ 5 8 ] , line 4 2 model 1 = LogisticRegression ( ) 3

rror Traceback (most recent call last)
Cell In[58], line 4
2 model1= LogisticRegression()
3 # Fitting the model for the 80% training data
---->4 model1.fit(X_train1, y_train1)
5 #Predict the outcomes for the 20% testing set
6 y_pred1= model1.predict(X_test1)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/sklearn/base.py:1151, in _fit_context..decorator..wrapper(estimator,*args,**kwargs)
1144 estimator._validate_params()
1146 with config_context(
1147 skip_parameter_validation=(
1148 prefer_skip_nested_validation or global_skip_validation
1149)
1150):
->1151 return fit_method(estimator,*args,**kwargs)
File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/sklearn/linear_model/_logistic.py:1252, in LogisticRegression.fit(self, X, y, sample_weight)
1250 classes_= self.classes_
1251 if n_classes <2:
->1252 raise ValueError(
1253 "This solver needs samples of at least 2 classes"
1254" in the data, but the data contains only one"
1255" class: %r"
1256% classes_[0]
1257)
1259 if len(self.classes_)==2:
1260 n_classes =1
ValueError: This solver needs samples of at least 2 classes in the data, but the data contains only one class: 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!