[AstroPy] Intelligent averaging of time series data
Harry Warren
hpwarren at gmail.com
Sun Sep 30 05:16:25 EDT 2018
This seems like a good application for clustering algorithms (see below). Of course, the nuanced part is determining the number of clusters.
Harry Warren
import matplotlib.pyplot as plt
import numpy as np
from sklearn.cluster import KMeans
t = (5.13, 5.27, 5.40, 5.46, 190.99, 191.13, 191.267, 368.70, 368.83, 368.90, 368.93)
y = (17.17, 17.18, 17.014, 17.104, 16.981, 16.96, 16.85, 17.27, 17.66, 17.76, 18.01)
X = np.array(list(zip(t,y)))
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)
y_km = kmeans.fit_predict(X)
print(kmeans.cluster_centers_)
print(y_km)
plt.plot(X[y_km==0,0], X[y_km==0,1], 'o', c='red')
plt.plot(X[y_km==1,0], X[y_km==1,1], 'o', c='green')
plt.plot(X[y_km==2,0], X[y_km==2,1], 'o', c='blue')
plt.show()
More information about the AstroPy
mailing list