codingutf8 generate a random binary classification problem todo fix fit pca with training set not the entire dataset coding utf 8 generate a random binary classification problem todo fix fit pca with training set not the entire dataset
import pytest
from sklearn.datasets import make_classification
from sklearn.metrics import roc_auc_score

try:
    from sklearn.model_selection import train_test_split
except ImportError:
    from sklearn.cross_validation import train_test_split

from mla.ensemble import RandomForestClassifier
from mla.pca import PCA


@pytest.fixture
def dataset():
    
    return make_classification(
        n_samples=1000, n_features=100, n_informative=75, random_state=1111, n_classes=2, class_sep=2.5
    )



@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")

    
    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)
    model.fit(X_train_reduced, y_train)
    predictions = model.predict(X_test_reduced)[:, 1]
    score = roc_auc_score(y_test, predictions)
    assert score >= 0.75