Reputation: 77
I am having trouble when using pandas and sklearn for machine learning. My problem is
ValueError: Unknown label type: 'continuous'
I tried
model = sklearn.tree.DecisionTreeClassifier()
model.fit(X, y)
and it returns this error:
ValueError Traceback (most recent call last)
<ipython-input-45-3caead2f350b> in <module>
----> 1 model.fit(ninp, out)
c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\sklearn\tree\_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
888 """
889
--> 890 super().fit(
891 X, y,
892 sample_weight=sample_weight,
c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\sklearn\tree\_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
179
180 if is_classification:
--> 181 check_classification_targets(y)
182 y = np.copy(y)
183
c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\sklearn\utils\multiclass.py in check_classification_targets(y)
170 if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
171 'multilabel-indicator', 'multilabel-sequences']:
--> 172 raise ValueError("Unknown label type: %r" % y_type)
173
174
ValueError: Unknown label type: 'continuous'
Upvotes: 0
Views: 2206
Reputation: 2422
A classifier classifies a set of examples into discrete classes (i.e. it assigns a label corresponding to one of K classes). If your target (the content of your y
variable) is continuous (for example a float ranging between 0 and 1), then the decision tree does not know what to do with it.
You have 2 solutions:
DecisionTreeRegressor
)Upvotes: 1