scikit-learn-contrib / py-earth

A Python implementation of Jerome Friedman's Multivariate Adaptive Regression Splines
http://contrib.scikit-learn.org/py-earth/
BSD 3-Clause "New" or "Revised" License
457 stars 122 forks source link

Pyearth stuck in fitting #44

Closed jcrudy closed 11 years ago

jcrudy commented 11 years ago

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

jcrudy commented 11 years ago

Should be fixed in master as of commit 402e6da9a57fb0509812184c1b4f63a22f99a548.