Advertisement
Guest User

MARS

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import numpy
  2. from pyearth import Earth
  3. from matplotlib import pyplot
  4.  
  5. #Create some fake data
  6. numpy.random.seed(0)
  7. m = 1000
  8. n = 10
  9. X = 80*numpy.random.uniform(size=(m,n)) - 40
  10. y = numpy.abs(X[:,6] - 4.0) + 1*numpy.random.normal(size=m)
  11.  
  12. #Fit an Earth model
  13. model = Earth()
  14. model.fit(X,y)
  15.  
  16. #Print the model
  17. print(model.trace())
  18. print(model.summary())
  19.  
  20. #Plot the model
  21. y_hat = model.predict(X)
  22. pyplot.figure()
  23. pyplot.plot(X[:,6],y,'r.')
  24. pyplot.plot(X[:,6],y_hat,'b.')
  25. pyplot.xlabel('x_6')
  26. pyplot.ylabel('y')
  27. pyplot.title('Simple Earth Example')
  28. pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement