Search code examples
pythonpandasdecision-tree

DecisionTreeClassifier model.fit(X, y) command is returning an error


I am coding a model to predict travel times based of a distance. I am getting

ValueError: Unknown label type: 'continuous' error when I run this code:

import pandas as pd

from sklearn.tree import DecisionTreeClassifier
times = pd.read_csv('SC.csv')
X = times.drop(columns=['Time'])
y = times.drop(columns=['distance'])

model = DecisionTreeClassifier()
model.fit(X, y)

Solution

  • This is because your targets are float values, not integers. You might be trying to classify continuous targets.

    Maybe try DecisionTreeRegressor(), or convert your targets to integers if your labels mistakenly got converted to float. Or double check you're using the right columns.