# Path: mla/linear_models.py
# class LinearRegression(BasicRegression):
#     """Linear regression with gradient descent optimizer."""
# 
#     def _loss(self, w):
#         loss = self.cost_func(self.y, np.dot(self.X, w))
#         return self._add_penalty(loss, w)
# 
#     def init_cost(self):
#         self.cost_func = mean_squared_error
# 
# class LogisticRegression(BasicRegression):
#     """Binary logistic regression with gradient descent optimizer."""
# 
#     def init_cost(self):
#         self.cost_func = binary_crossentropy
# 
#     def _loss(self, w):
#         loss = self.cost_func(self.y, self.sigmoid(np.dot(self.X, w)))
#         return self._add_penalty(loss, w)
# 
#     @staticmethod
#     def sigmoid(x):
#         return 0.5 * (np.tanh(0.5 * x) + 1)
# 
#     def _predict(self, X=None):
#         X = self._add_intercept(X)
#         return self.sigmoid(X.dot(self.theta))
# 
# Path: mla/metrics/metrics.py
# def mean_squared_error(actual, predicted):
#     return np.mean(squared_error(actual, predicted))
# 
# @unhot
# def accuracy(actual, predicted):
#     return 1.0 - classification_error(actual, predicted)


import logging
    from sklearn.model_selection import train_test_split
    from sklearn.cross_validation import train_test_split
from sklearn.datasets import make_classification
from sklearn.datasets import make_regression
from mla.linear_models import LinearRegression, LogisticRegression
from mla.metrics.metrics import mean_squared_error, accuracy

try:
except ImportError:


# Change to DEBUG to see convergence
logging.basicConfig(level=logging.ERROR)


def regression():
    # Generate a random regression problem
    X, y = make_regression(
        n_samples=10000, n_features=100, n_informative=75, n_targets=1, noise=0.05, random_state=1111, bias=0.5
    )
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=1111)

    model = LinearRegression(lr=0.01, max_iters=2000, penalty="l2", C=0.03)
    model.fit(X_train, y_train)
    predictions = model.predict(X_test)
    print("regression mse", mean_squared_error(y_test, predictions))


def classification():
    # Generate a random binary classification problem.
    X, y = make_classification(
        n_samples=1000, n_features=100, n_informative=75, random_state=1111, n_classes=2, class_sep=2.5
    )
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=1111)


# Path: mla/linear_models.py
# class LinearRegression(BasicRegression):
#     """Linear regression with gradient descent optimizer."""
# 
#     def _loss(self, w):
#         loss = self.cost_func(self.y, np.dot(self.X, w))
#         return self._add_penalty(loss, w)
# 
#     def init_cost(self):
#         self.cost_func = mean_squared_error
# 
# class LogisticRegression(BasicRegression):
#     """Binary logistic regression with gradient descent optimizer."""
# 
#     def init_cost(self):
#         self.cost_func = binary_crossentropy
# 
#     def _loss(self, w):
#         loss = self.cost_func(self.y, self.sigmoid(np.dot(self.X, w)))
#         return self._add_penalty(loss, w)
# 
#     @staticmethod
#     def sigmoid(x):
#         return 0.5 * (np.tanh(0.5 * x) + 1)
# 
#     def _predict(self, X=None):
#         X = self._add_intercept(X)
#         return self.sigmoid(X.dot(self.theta))
# 
# Path: mla/metrics/metrics.py
# def mean_squared_error(actual, predicted):
#     return np.mean(squared_error(actual, predicted))
# 
# @unhot
# def accuracy(actual, predicted):
#     return 1.0 - classification_error(actual, predicted)


# Path: examples/linear_models.py
import logging
    from sklearn.model_selection import train_test_split
    from sklearn.cross_validation import train_test_split
from sklearn.datasets import make_classification
from sklearn.datasets import make_regression
from mla.linear_models import LinearRegression, LogisticRegression
from mla.metrics.metrics import mean_squared_error, accuracy


try:
except ImportError:


# Change to DEBUG to see convergence
logging.basicConfig(level=logging.ERROR)


def regression():
    # Generate a random regression problem
    X, y = make_regression(
        n_samples=10000, n_features=100, n_informative=75, n_targets=1, noise=0.05, random_state=1111, bias=0.5
    )
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=1111)

    model = LinearRegression(lr=0.01, max_iters=2000, penalty="l2", C=0.03)
    model.fit(X_train, y_train)
    predictions = model.predict(X_test)
    print("regression mse", mean_squared_error(y_test, predictions))


def classification():
    # Generate a random binary classification problem.
    X, y = make_classification(
        n_samples=1000, n_features=100, n_informative=75, random_state=1111, n_classes=2, class_sep=2.5
    )
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=1111)


    model = LogisticRegression(lr=0.01, max_iters=500, penalty="l1", C=0.01)