Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用scikit学习python中的机器学习_Python - Fatal编程技术网

使用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