I wrote an ML script with sklearn in Python that you get the specifications of a car and the address of its place of sale and it predicts the price of the car.
my_code:
from sklearn import preprocessing, tree
ls = [['Toyota RAV4', 'XLE FWD', '36,280 miles', 'Stafford, TX'], ['Toyota Camry', 'SE I4 Automatic', '36,233 miles', 'Norco, CA']]
x = []
y = ['$19,480','$17,399']
c = preprocessing.LabelEncoder()
clf = tree.DecisionTreeClassifier()
for k in ls:
c.fit(k)
b = list(c.classes_)
n = c.transform(k)
x.append(list(n))
clf.fit(x,y)
bmi = [list(c.fit_transform(input().split()))]
answer = clf.predict(bmi)
print(answer[0])
My input:
Toyota RAV4 XLE FWD 36,280 miles Stafford, TX
I encoded the strings well but I got an error:
ValueError: X has 6 features, but DecisionTreeClassifier is expecting 4 features as input.
How can I solve this problem?
Thanks a lot
question from:
https://stackoverflow.com/questions/65858857/how-do-fix-valueerror-x-has-6-features-but-decisiontreeclassifier-is-expecti 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…