使用scikit学习python中的机器学习
我制作了关于汽车信息的数据库,包括,汽车品牌,里程,年份,价格,如下:使用scikit学习python中的机器学习,python,Python,我制作了关于汽车信息的数据库,包括,汽车品牌,里程,年份,价格,如下: [[('Volkswagen Polo', 82000, 2010, 43000)], [('Porsche 911', 2500, 2018, 349000)], [('Volvo S60', 89000, 2015, 98000)], [('BMW 1', 127467, 2012, 97000)] 我正在学习机器学习,我想使用决策树 我想知道汽车的品牌、里程数和年份,并预测价格。我已经尝试了很多方法,每次我都会遇到
[[('Volkswagen Polo', 82000, 2010, 43000)], [('Porsche 911', 2500, 2018, 349000)], [('Volvo S60', 89000, 2015, 98000)], [('BMW 1', 127467, 2012, 97000)]
我正在学习机器学习,我想使用决策树
我想知道汽车的品牌、里程数和年份,并预测价格。我已经尝试了很多方法,每次我都会遇到错误。
例如:
ValueError: could not convert string to float: 'Volkswagen Polo'
or
ValueError: Found array with dim 3. Estimator expected <= 2.
or
TypeError: fit() takes 2 positional arguments but 3 were given
或
LabelEncoder
仅在目标类上运行,因此不应将x
传递给它(请参阅)。此外,您似乎对目标类使用了错误的索引:
y.append([item[4]])
应该是y.append([item[0]])
为什么不直接从db查询汽车品牌、里程和年份?
cursor = cnx.cursor()
cursor.execute('SELECT * FROM cars_2')
my_result = cursor.fetchall()
x = []
y = []
for item in my_result:
x.append([item[1:4]])
y.append([item[4]])
le = preprocessing.LabelEncoder()
le.fit(x, y)
cursor = cnx.cursor()
cursor.execute('SELECT * FROM cars_2')
my_result = cursor.fetchall()
x = []
y = []
for item in my_result:
x.append([item[1:4]])
y.append([item[4]])
clf = tree.DecisionTreeClassifier()
clf = clf.fit(x, y