是否可以使用列表来预测python中的数据?

2024-04-16 19:07:01 发布

您现在位置:Python中文网/ 问答频道 /正文

目前,我一直在使用列表来绘制数据,并希望找出一种预测模式。尝试使用数据帧对我没有帮助,也造成了极大的不适。是否可以使用python列表和机器学习或模式识别算法来预测数据?我是python新手:)


Tags: 数据算法机器列表模式绘制新手模式识别
1条回答
网友
1楼 · 发布于 2024-04-16 19:07:01

我需要一个程序,可以采取时间戳的输入,并使用它来预测未来的时间戳。在很长一段时间之后,对我有效的方法是只使用时间戳小时:分钟:秒格式并将其转换为浮点数。然后使用这些浮点数并将其与时间戳的条目号配对。所以我有一个二维列表,只是为了把数据整齐地收集到一堆。你知道吗

示例:时间戳1,0 时间戳2,1 时间戳3,2

然后分配两个变量,这两个变量将获取一列的数据。浮点数在y轴上,x轴是数字序列,例如0,1,2,3,。。。等等。你知道吗

然后使用svr_林菲特这是线性回归,我能画出一个匹配所有点的图,因为它将是一条线,因为x轴上的数字。最后,使用svr_林。预测我可以打印未来的数据点。希望这能帮助那些试图使用python获取“未来”时间戳的人。你知道吗

代码:

data = [[timestamp_1, 0],
        [timestamp_2, 1],
        [timestamp_3, 2],
        [timestamp_4, 3],
        #continues...
         ]]

list_time = []
list_numbers = []

list_time = [i[0] for i in data]
list_numbers = [i[1] for i in data]

list_numbers = np.reshape(list_number, (len(list_numbers), 1))

svr_lin = SVR(kernel='linear', C=1e3)

svr_lin.fit(list_numbers, list_time)

plt.scatter(list_numbers, list_time)
plt.plot(list_numbers, svr_lin.predict(list_numbers)) #in a different colour
plt.show

'''x is out of sample and starting point I have kept in sample however, starting 
point does not need to be the 0th element.'''

for i in range(0,x):
    print(svr_lin.predict(i))

Siraj Raval和stack overflow用户代码对我帮助很大。你知道吗

相关问题 更多 >