def linreg_fit(input_dict): from discomll.regression import linear_regression fitmodel_url = linear_regression.fit(input_dict["dataset"], save_results=True) return {"fitmodel_url": fitmodel_url}
def test_lin_reg(self): # python -m unittest tests_regression.Tests_Regression.test_lin_reg from sklearn import linear_model from discomll.regression import linear_regression x_train, y_train, x_test, y_test = datasets.ex3() train_data, test_data = datasets.ex3_discomll() lin_reg = linear_model.LinearRegression() # Create linear regression object lin_reg.fit(x_train, y_train) # Train the model using the training sets thetas1 = [lin_reg.intercept_] + lin_reg.coef_[1:].tolist() prediction1 = lin_reg.predict(x_test) thetas_url = linear_regression.fit(train_data) thetas2 = [v for k, v in result_iterator(thetas_url["linreg_fitmodel"])] results = linear_regression.predict(test_data, thetas_url) prediction2 = [v[0] for k, v in result_iterator(results)] self.assertTrue(np.allclose(thetas1, thetas2)) self.assertTrue(np.allclose(prediction1, prediction2))
def test_lin_reg(self): # python -m unittest tests_regression.Tests_Regression.test_lin_reg from sklearn import linear_model from discomll.regression import linear_regression x_train, y_train, x_test, y_test = datasets.ex3() train_data, test_data = datasets.ex3_discomll() lin_reg = linear_model.LinearRegression( ) # Create linear regression object lin_reg.fit(x_train, y_train) # Train the model using the training sets thetas1 = [lin_reg.intercept_] + lin_reg.coef_[1:].tolist() prediction1 = lin_reg.predict(x_test) thetas_url = linear_regression.fit(train_data) thetas2 = [ v for k, v in result_iterator(thetas_url["linreg_fitmodel"]) ] results = linear_regression.predict(test_data, thetas_url) prediction2 = [v[0] for k, v in result_iterator(results)] self.assertTrue(np.allclose(thetas1, thetas2)) self.assertTrue(np.allclose(prediction1, prediction2))
from discomll import dataset from discomll.regression import linear_regression train = dataset.Data( data_tag=["http://ropot.ijs.si/data/fraction/train/xaaaaa.gz", "http://ropot.ijs.si/data/fraction/train/xaaabj.gz"], data_type="gzip", generate_urls=True, X_indices=range(1, 14), id_index=0, y_index=14, delimiter=",") test = dataset.Data( data_tag=["http://ropot.ijs.si/data/fraction/test/xaaaaa.gz", "http://ropot.ijs.si/data/fraction/test/xaaabj.gz"], data_type="gzip", generate_urls=True, X_indices=range(1, 14), id_index=0, y_index=14, delimiter=",") fit_model = linear_regression.fit(train) predictions = linear_regression.predict(test, fit_model) print predictions
from discomll import dataset from discomll.regression import linear_regression from discomll.utils import model_view # define training dataset train = dataset.Data(data_tag=["test:ex3"], data_type="chunk", X_indices=[0, 1], y_index=2) # define test dataset test = dataset.Data(data_tag=["test:ex3_test"], data_type="chunk", X_indices=[0, 1], y_index=2) # fit model on training dataset fit_model = linear_regression.fit(train) # output model model = model_view.output_model(fit_model) print model # predict test dataset predictions = linear_regression.predict(test, fit_model) # output results for k, v in result_iterator(predictions): print k, v[0]