예제 #1
0
    def test_linear_regression_persistence(self):
        model = LinearRegression(['a', 'b', 'c'], fit_intercept=False)
        model.fit(self.train_x, self.train_y)

        desc = model.save()
        new_model = LinearRegression.load(desc)

        calculated_y = new_model.predict(self.predict_x)
        expected_y = model.predict(self.predict_x)

        np.testing.assert_array_almost_equal(calculated_y, expected_y)
예제 #2
0
    def test_load_model(self):
        model = LinearRegression(['a', 'b', 'c'])
        model.fit(self.trained_x, self.trained_y)

        model_desc = model.save()
        new_model = load_model(model_desc)

        np.testing.assert_array_almost_equal(model.predict(self.predict_x),
                                             new_model.predict(self.predict_x))

        self.assertEqual(model.features, new_model.features)
        self.assertEqual(model.trained_time, new_model.trained_time)
예제 #3
0
import numpy as np
import pandas as pd
from alphamind.api import *
from alphamind.data.dbmodel.models import Models
from alphamind.model.linearmodel import LinearRegression

engine = SqlEngine(
    'postgresql+psycopg2://postgres:[email protected]/alpha')

x = np.random.randn(1000, 3)
y = np.random.randn(1000)

model = LinearRegression(['a', 'b', 'c'])
model.fit(x, y)

model_desc = model.save()

df = pd.DataFrame()

new_row = dict(trade_date='2017-09-05',
               portfolio_name='test',
               model_type='LinearRegression',
               version=1,
               model_desc=model_desc,
               update_time=arrow.now().format())

df = df.append([new_row])

df.to_sql(Models.__table__.name,
          engine.engine,
          if_exists='append',