Reputation: 179
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=0)
log=LogisticRegression()
print (x_train.shape) --(5, 13)
print (x_test.shape) --(3, 13)
print(y_train.shape) --(5,)
print(y_test.shape) --(3,)
log.fit(x_train,y_train)
please see the below I have followed from youtube and internet sources for the code and with the above code it is giving following error .Please help me out error :
ValueError Traceback (most recent call last)
<ipython-input-16-86c1075a1e93> in <module>
----> 1 log.fit(x_train,y_train)
/srv/conda/lib/python3.6/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight)
1287 X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
1288 accept_large_sparse=solver != 'liblinear')
-> 1289 check_classification_targets(y)
1290 self.classes_ = np.unique(y)
1291 n_samples, n_features = X.shape
/srv/conda/lib/python3.6/site-packages/sklearn/utils/multiclass.py in check_classification_targets(y)
169 if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
170 'multilabel-indicator', 'multilabel-sequences']:
--> 171 raise ValueError("Unknown label type: %r" % y_type)
172
173
ValueError: Unknown label type: 'continuous'
Upvotes: 0
Views: 1425
Reputation: 1261
Logistic regression is a statistical method for predicting binary classes. The dependent variable or target variable must be binary. In your case, you have "continuous" targets.
Types of Logistic Regression:
Binary Logistic Regression: The target variable has only two possible outcomes.
Multinomial Logistic Regression: The target variable has three or more nominal categories
Ordinal Logistic Regression: the target variable has three or more ordinal categories (Example: product rating from 1 to 5)
Upvotes: 2