'use strict';

var OnlineSGDRegression = require( './../lib' );
var randu = require( '@stdlib/math/base/random/randu' );
var x1;
var x2;
var y;
var i;

// Create model:
var model = new OnlineSGDRegression({
	'lambda': 1e-4,
	'loss': 'squaredError',
	'intercept': true
});

// Update model as data comes in...
for ( i = 0; i < 100000; i++ ) {
	x1 = randu();
	x2 = randu();
	y = 3.0 * x1 + -3.0 * x2 + 2.0;
	model.update( [ x1, x2 ], y );
}

// Extract model coefficients:
console.log( model.coefs );

// Predict new observations:
console.log( 'y_hat = %d; x1 = %d; x2 = %d', model.predict( [0.9,0.1] ), 0.9, 0.1 );
console.log( 'y_hat = %d; x1 = %d; x2 = %d', model.predict( [0.1,0.9] ), 0.1, 0.9 );
console.log( 'y_hat = %d; x1 = %d; x2 = %d', model.predict( [0.9,0.9] ), 0.9, 0.9 );

'use strict';

var randu = require( '@stdlib/math/base/random/randu' );
var OnlineSGDRegression = require( './../lib' );
var x1;
var x2;
var y;
var i;

// Create model:
var model = new OnlineSGDRegression({
	'lambda': 1e-4,
	'loss': 'squaredError',
	'intercept': true
});

// Update model as data comes in...
for ( i = 0; i < 100000; i++ ) {
	x1 = randu();
	x2 = randu();
	y = 3.0 * x1 + -3.0 * x2 + 2.0;
	model.update( [ x1, x2 ], y );
}

// Extract model coefficients:
console.log( model.coefs );

// Predict new observations:
console.log( 'y_hat = %d; x1 = %d; x2 = %d', model.predict( [0.9,0.1] ), 0.9, 0.1 );
console.log( 'y_hat = %d; x1 = %d; x2 = %d', model.predict( [0.1,0.9] ), 0.1, 0.9 );
console.log( 'y_hat = %d; x1 = %d; x2 = %d', model.predict( [0.9,0.9] ), 0.9, 0.9 );

Reorder require statements