# Path: mla/ensemble/random_forest.py
# class RandomForestClassifier(RandomForest):
#     def __init__(self, n_estimators=10, max_features=None, min_samples_split=10, max_depth=None, criterion="entropy"):
#         super(RandomForestClassifier, self).__init__(
#             n_estimators=n_estimators,
#             max_features=max_features,
#             min_samples_split=min_samples_split,
#             max_depth=max_depth,
#             criterion=criterion,
#         )
# 
#         if criterion == "entropy":
#             self.criterion = information_gain
#         else:
#             raise ValueError()
# 
#         # Initialize empty trees
#         for _ in range(self.n_estimators):
#             self.trees.append(Tree(criterion=self.criterion))
# 
#     def _predict(self, X=None):
#         y_shape = np.unique(self.y).shape[0]
#         predictions = np.zeros((X.shape[0], y_shape))
# 
#         for i in range(X.shape[0]):
#             row_pred = np.zeros(y_shape)
#             for tree in self.trees:
#                 row_pred += tree.predict_row(X[i, :])
# 
#             row_pred /= self.n_estimators
#             predictions[i, :] = row_pred
#         return predictions
# 
# Path: mla/pca.py
# class PCA(BaseEstimator):
#     y_required = False
# 
#     def __init__(self, n_components, solver="svd"):
#         """Principal component analysis (PCA) implementation.
# 
#         Transforms a dataset of possibly correlated values into n linearly
#         uncorrelated components. The components are ordered such that the first
#         has the largest possible variance and each following component as the
#         largest possible variance given the previous components. This causes
#         the early components to contain most of the variability in the dataset.
# 
#         Parameters
#         ----------
#         n_components : int
#         solver : str, default 'svd'
#             {'svd', 'eigen'}
#         """
#         self.solver = solver
#         self.n_components = n_components
#         self.components = None
#         self.mean = None
# 
#     def fit(self, X, y=None):
#         self.mean = np.mean(X, axis=0)
#         self._decompose(X)
# 
#     def _decompose(self, X):
#         # Mean centering
#         X = X.copy()
#         X -= self.mean
# 
#         if self.solver == "svd":
#             _, s, Vh = svd(X, full_matrices=True)
#         elif self.solver == "eigen":
#             s, Vh = np.linalg.eig(np.cov(X.T))
#             Vh = Vh.T
# 
#         s_squared = s ** 2
#         variance_ratio = s_squared / s_squared.sum()
#         logging.info("Explained variance ratio: %s" % (variance_ratio[0: self.n_components]))
#         self.components = Vh[0: self.n_components]
# 
#     def transform(self, X):
#         X = X.copy()
#         X -= self.mean
#         return np.dot(X, self.components.T)
# 
#     def _predict(self, X=None):
#         return self.transform(X)


import pytest
from sklearn.datasets import make_classification
from sklearn.metrics import roc_auc_score
    from sklearn.model_selection import train_test_split
    from sklearn.cross_validation import train_test_split
from mla.ensemble import RandomForestClassifier
from mla.pca import PCA
# coding=utf-8

try:
except ImportError:



@pytest.fixture
def dataset():
    # Generate a random binary classification problem.
    return make_classification(
        n_samples=1000, n_features=100, n_informative=75, random_state=1111, n_classes=2, class_sep=2.5
    )


# TODO: fix
@pytest.mark.skip()
def test_PCA(dataset):
    X, y = dataset
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=1111)
    p = PCA(50, solver="eigen")

    # fit PCA with training set, not the entire dataset
    p.fit(X_train)
    X_train_reduced = p.transform(X_train)
    X_test_reduced = p.transform(X_test)


# Path: mla/ensemble/random_forest.py
# class RandomForestClassifier(RandomForest):
#     def __init__(self, n_estimators=10, max_features=None, min_samples_split=10, max_depth=None, criterion="entropy"):
#         super(RandomForestClassifier, self).__init__(
#             n_estimators=n_estimators,
#             max_features=max_features,
#             min_samples_split=min_samples_split,
#             max_depth=max_depth,
#             criterion=criterion,
#         )
# 
#         if criterion == "entropy":
#             self.criterion = information_gain
#         else:
#             raise ValueError()
# 
#         # Initialize empty trees
#         for _ in range(self.n_estimators):
#             self.trees.append(Tree(criterion=self.criterion))
# 
#     def _predict(self, X=None):
#         y_shape = np.unique(self.y).shape[0]
#         predictions = np.zeros((X.shape[0], y_shape))
# 
#         for i in range(X.shape[0]):
#             row_pred = np.zeros(y_shape)
#             for tree in self.trees:
#                 row_pred += tree.predict_row(X[i, :])
# 
#             row_pred /= self.n_estimators
#             predictions[i, :] = row_pred
#         return predictions
# 
# Path: mla/pca.py
# class PCA(BaseEstimator):
#     y_required = False
# 
#     def __init__(self, n_components, solver="svd"):
#         """Principal component analysis (PCA) implementation.
# 
#         Transforms a dataset of possibly correlated values into n linearly
#         uncorrelated components. The components are ordered such that the first
#         has the largest possible variance and each following component as the
#         largest possible variance given the previous components. This causes
#         the early components to contain most of the variability in the dataset.
# 
#         Parameters
#         ----------
#         n_components : int
#         solver : str, default 'svd'
#             {'svd', 'eigen'}
#         """
#         self.solver = solver
#         self.n_components = n_components
#         self.components = None
#         self.mean = None
# 
#     def fit(self, X, y=None):
#         self.mean = np.mean(X, axis=0)
#         self._decompose(X)
# 
#     def _decompose(self, X):
#         # Mean centering
#         X = X.copy()
#         X -= self.mean
# 
#         if self.solver == "svd":
#             _, s, Vh = svd(X, full_matrices=True)
#         elif self.solver == "eigen":
#             s, Vh = np.linalg.eig(np.cov(X.T))
#             Vh = Vh.T
# 
#         s_squared = s ** 2
#         variance_ratio = s_squared / s_squared.sum()
#         logging.info("Explained variance ratio: %s" % (variance_ratio[0: self.n_components]))
#         self.components = Vh[0: self.n_components]
# 
#     def transform(self, X):
#         X = X.copy()
#         X -= self.mean
#         return np.dot(X, self.components.T)
# 
#     def _predict(self, X=None):
#         return self.transform(X)


# Path: mla/tests/test_reduction.py
import pytest
from sklearn.datasets import make_classification
from sklearn.metrics import roc_auc_score
    from sklearn.model_selection import train_test_split
    from sklearn.cross_validation import train_test_split
from mla.ensemble import RandomForestClassifier
from mla.pca import PCA

# coding=utf-8

try:
except ImportError:



@pytest.fixture
def dataset():
    # Generate a random binary classification problem.
    return make_classification(
        n_samples=1000, n_features=100, n_informative=75, random_state=1111, n_classes=2, class_sep=2.5
    )


# TODO: fix
@pytest.mark.skip()
def test_PCA(dataset):
    X, y = dataset
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=1111)
    p = PCA(50, solver="eigen")

    # fit PCA with training set, not the entire dataset
    p.fit(X_train)
    X_train_reduced = p.transform(X_train)
    X_test_reduced = p.transform(X_test)


    model = RandomForestClassifier(n_estimators=25, max_depth=5)