 |
Forecast using polynomial regression
Source code name: "openf_poly_regression.py"
Programming language: Python
Topic: Data mining/Regression
DMelt Version 2.4. Last modified: 02/01/1973. License: Pro
https://datamelt.org/code/cache/openf_poly_regression_5032.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Polynomial Regression model using open forecast
from net.sourceforge.openforecast import DataPoint,DataSet,ForecastingModel
from net.sourceforge.openforecast import Observation
from net.sourceforge.openforecast.models import PolynomialRegressionModel
from java.lang import Math
from java.util import Random
from jhplot import *
import time
c1 = SPlot()
c1.visible()
c1.setAutoRange()
c1.setMarksStyle('various')
c1.setConnected(1, 1)
c1.setNameX('Time')
c1.setNameY('Data')
observedData = DataSet();
for x in xrange(50):
y = 10.6 + 3.5*x + 0.5*Math.pow(x,3)
dp = Observation( y )
dp.setIndependentValue( "x1", x )
#Fill x2 with random data - it should be ignored
dp.setIndependentValue( "x2", (Math.random()-0.5)*100 );
observedData.add( dp );
c1.addPoint(0,x,y,1)
c1.update()
model = PolynomialRegressionModel( "x1", 5 );
model.init( observedData );
fcValues = DataSet();
for x in xrange(50,100):
y = 10.6 + 3.5*x + 0.5*Math.pow(x,3)
dp = Observation( y )
dp.setIndependentValue( "x1", x )
# Fill x2 with random data - it should be ignored
dp.setIndependentValue( "x2", (Math.random()-0.5)*100 );
fcValues.add( dp );
print "Predictions.."
results = model.forecast( fcValues );
for dp in results:
xx=dp.getIndependentValue( "x1" )
yy=dp. getDependentValue()
c1.addPoint(1,xx,yy,1)
c1.update()
You see the box below because you did not login.