<p>我看不出你有什么问题。因为这是一个从epoch开始计算秒数的时间戳,所以您只需应用modulo运算符,其值就是感兴趣的范围。如果你训练一个分类器,你应该能够预测每一个即将到来的地方。主要的问题不是性能,因为学习只是偶尔完成,而是如何更新学习的数据集。
如前所述,您不必为此使用机器学习,但如果您想使用机器学习,这基本上可以使用1d数据集上的k近邻来完成。</p>
<p><strong>[编辑]:</strong>
把语言混在一起但又把它固定了下来:分类器是用来进行统计分类的算法。</p>
<blockquote>
<p><em>In machine learning and statistics, classification is the problem of identifying to which of a set of categories (sub-populations) a new observation belongs, on the basis of a training set of data containing observations (or instances) whose category membership is known.</em>[<a href="http://en.wikipedia.org/wiki/Statistical_classification" rel="nofollow">1</a>]</p>
</blockquote>
<p>由于我只使用sklearn来做这些事情,下面是一个极简的例子,说明如何使用k近邻分类器[<a href="http://scikit-learn.org/dev/modules/generated/sklearn.neighbors.KNeighborsClassifier.html" rel="nofollow">2</a>]。为了能够分类,您必须将字符串更改为数字,然后在给定的测试数据集上训练分类器,然后才能预测新的给定时间戳的位置。</p>
<pre><code>import numpy as np
from sklearn.neighbors import KNeighborsClassifier
data = [[1365650747255, 'san francisco'],
[1365650743354, 'san francisco'],
[1365650741349, 'san mateo'],
[1365650756324, 'mountain view'],
...
[1365650813354, 'menlo park']]
# Map location strings to integers and replace
location_mapping = {}
location_index = 0
for index, (time, location) in enumerate(data):
if(not location_mapping.has_key(location)):
location_mapping[location] = location_index
location_index += 1
data[index][1] = location_mapping[location]
inverse_location_mapping = {value:key for key, value in location_mapping.items()}
data = np.array(data)
week = 60 * 60 * 24 * 7
# Setup classifier
classifier = KNeighborsClassifier(n_neighbors=10)
# Train classifier on given data
classifier.fit(data[:, 0] % week, data[:, 1])
# Predict desired location
prediction = classifier.predict([[1365444444444 % week]]))
print(inverse_location_mapping[prediction])
</code></pre>
<p>[<a href="http://en.wikipedia.org/wiki/Statistical_classification" rel="nofollow">1</a>]:<a href="http://en.wikipedia.org/wiki/Statistical_classification" rel="nofollow">http://en.wikipedia.org/wiki/Statistical_classification</a></p>
<p>[<a href="http://scikit-learn.org/dev/modules/generated/sklearn.neighbors.KNeighborsClassifier.html" rel="nofollow">2</a>]:<a href="http://scikit-learn.org/dev/modules/generated/sklearn.neighbors.KNeighborsClassifier.html" rel="nofollow">http://scikit-learn.org/dev/modules/generated/sklearn.neighbors.KNeighborsClassifier.html</a></p>