I just tried a couple of fitting examples on which to apply pyearth.
This is the code:
import numpy
from pyearth import Earth
from matplotlib import pyplot
Create some fake data
numpy.random.seed(seed = 0)
N = 100
X = numpy.linspace(-10, 10, N)
numpy.random.shuffle(X)
y = numpy.zeros(X.shape)
sigma = 1
for i in range(y.size):
r = numpy.random.normal(1, sigma)
y[i] = numpy.sin(X[i]) + r
Fit an Earth model
model = Earth()
print 'fitting'
model.fit(X,y)
print 'done'
It generates a noisy sin function and tries to fit it. There an issue I'd like to point out. If the number of samples is not large enough, e.g. N = 100, the algorithm may crash, and raise a segmentation fault. Its success depends on the data. If I do not set the random seed, then sometimes it crashes and sometimes it does not.
Dear Jason,
I just tried a couple of fitting examples on which to apply pyearth.
This is the code: import numpy from pyearth import Earth from matplotlib import pyplot
Create some fake data
numpy.random.seed(seed = 0)
N = 100 X = numpy.linspace(-10, 10, N) numpy.random.shuffle(X) y = numpy.zeros(X.shape) sigma = 1 for i in range(y.size): r = numpy.random.normal(1, sigma) y[i] = numpy.sin(X[i]) + r
Fit an Earth model
model = Earth() print 'fitting' model.fit(X,y) print 'done'
print "\n* SUMMARY *"
print model.summary()
Plot the model
y_hat = model.predict(X) pyplot.figure() pyplot.plot(X,y,'r.') pyplot.plot(X,y_hat,'b.') pyplot.show()
It generates a noisy sin function and tries to fit it. There an issue I'd like to point out. If the number of samples is not large enough, e.g. N = 100, the algorithm may crash, and raise a segmentation fault. Its success depends on the data. If I do not set the random seed, then sometimes it crashes and sometimes it does not.
I hope this information may help you!
Best,
Marco