【问题标题】:could not convert string to float: '19:40:00'无法将字符串转换为浮点数:'19:40:00'
【发布时间】:2020-05-03 23:10:25
【问题描述】:

我正在编写 Python 代码来预测纽约市的出租车需求。我的数据如下图enter image description here

在我使用 SVR 预测出租车需求之后。我有以下错误:无法将字符串转换为浮点数:'19:40:00'

我的代码:

x_names = ['pickup_cluster','pickup_datetime','dayofyear','average temperature',       'precipitation','snow fall']
x = taxi_data[x_names]
y= taxi_data['Count']

xtrain, xtest, ytrain, ytest=sklearn.model_selection.train_test_split(x, y, test_size=0.1)

regressor = SVR(kernel='rbf', gamma='auto', C=0.1, epsilon=2)
regressor.fit(xtrain, ytrain)
acc = regressor.score(xtest, ytest)
print("Accuracy for SVR: ", acc)

【问题讨论】:

标签: python


【解决方案1】:

可以在这里找到答案:Convert python datetime to timestamp in milliseconds

该错误表示您无法将字符串转换为浮点数,因为其中包含“:”,不允许将其直接转换为浮点数。因此,使用提供的链接格式化时间并以浮点数形式获取时间

【讨论】:

    猜你喜欢
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 1970-01-01
    相关资源
    最近更新 更多