Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@Zhenya's answer of manually setting knots in between datapoints was too rough to deliver good results in noisy data without being selective about how this technique is applied. However, inspired by his/her suggestion, I have had success with <a href="http://scikit-learn.sourceforge.net/dev/modules/generated/sklearn.cluster.MeanShift.html#sklearn.cluster.MeanShift" rel="nofollow noreferrer">Mean-Shift clustering</a> from the scikit-learn package. It performs auto-determination of the cluster count and seems to do a fairly good smoothing job (very smooth in fact).</p> <pre><code># Imports import numpy import pylab import scipy import sklearn.cluster # Set up original data - note that it's monotonically increasing by X value! data = {} data['original'] = {} data['original']['x'] = [0, 5024.2059124920379, 7933.1645067836089, 7990.4664106277542, 9879.9717114947653, 13738.60563208926, 15113.277958924193] data['original']['y'] = [0.0, 3072.5653360000988, 5477.2689107965398, 5851.6866463790966, 6056.3852496014106, 7895.2332350173638, 9154.2956175610598] # Cluster data, sort it and and save inputNumpy = numpy.array([[data['original']['x'][i], data['original']['y'][i]] for i in range(0, len(data['original']['x']))]) meanShift = sklearn.cluster.MeanShift() meanShift.fit(inputNumpy) clusteredData = [[pair[0], pair[1]] for pair in meanShift.cluster_centers_] clusteredData.sort(lambda pair1, pair2: cmp(pair1[0],pair2[0])) data['clustered'] = {} data['clustered']['x'] = [pair[0] for pair in clusteredData] data['clustered']['y'] = [pair[1] for pair in clusteredData] # Build a spline using the clustered data and predict mySpline = scipy.interpolate.UnivariateSpline(x=data['clustered']['x'], y=data['clustered']['y'], k=1) xi = range(0, round(max(data['original']['x']), -3) + 3000, 20) yi = mySpline(xi) # Plot the datapoints pylab.plot(data['clustered']['x'], data['clustered']['y'], "D", label="Datapoints (%s)" % 'clustered') pylab.plot(xi, yi, label="Predicted (%s)" % 'clustered') pylab.plot(data['original']['x'], data['original']['y'], "o", label="Datapoints (%s)" % 'original') # Show the plot pylab.grid(True) pylab.xticks(rotation=45) pylab.legend( loc="lower right" ) pylab.show() </code></pre> <p><img src="https://i.stack.imgur.com/KxIW9.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload