def test_trim_spaces(self): self.set_up_file_content(" 2,3 ,2 \n 2, 5, 3\n4 ,7 ,6") actual = data_loader.parse_data("file_name") self.assertListEqual([[2, 3], [2, 5], [4, 7]], actual[0]) self.assertListEqual([2, 3, 6], actual[1])
from pylearn import high_order_model, visualizer, data_loader from pylearn.space_transform import full_polynomial_mapper # Polynomial regression example X, y = data_loader.parse_data('data/approx_data.txt') model = high_order_model.PolynomialRegression() model.learning_rate = 0.12 model.max_iterations = 300 mapper = full_polynomial_mapper(7, 2) predict = model.fit(X, y, mapper) visualizer.plot_1d_approximator_stats(model, X, y)
def test_complex_matrix_parse(self): self.set_up_file_content("1,1,3,6,2\n2,5,6,2,3\n4,4,5,5,6") actual = data_loader.parse_data("file_name") self.assertListEqual([[1, 1, 3, 6], [2, 5, 6, 2], [4, 4, 5, 5]], actual[0]) self.assertListEqual([2, 3, 6], actual[1])
from pylearn import high_order_model, linear_model, visualizer, data_loader from pylearn.space_transform import full_polynomial_mapper # Polynomial logistic regression example X_lo, y_lo = data_loader.parse_data('data/logistic_non_linear.txt') y_lo = [int(y) for y in y_lo] model = high_order_model.PolynomialLogisticRegression() model.learning_rate = 0.1 model.max_iterations = 400 mapper = full_polynomial_mapper(6, 2) predict = model.fit(X_lo, y_lo, mapper) visualizer.plot_2d_classifier_stats(model, X_lo, y_lo) exit() # Linear logistic regression example X_lo, y_lo = data_loader.parse_data('data/logistic_linear.txt') y_lo = [int(y) for y in y_lo] model = linear_model.LogisticRegression() predict = model.fit(X_lo, y_lo) visualizer.plot_2d_classifier_stats(model, X_lo, y_lo)