<s> import sys <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> import unittest <EOL> import numpy as np <EOL> import pandas as pd <EOL> from sklearn import linear_model <EOL> from ramp . estimators import ( Probabilities , <EOL> BinaryProbabilities , <EOL> wrap_sklearn_like_estimator ) <EOL> from ramp import shortcuts <EOL> from ramp . tests . test_features import make_data <EOL> class DummyProbEstimator ( object ) : <EOL> def __init__ ( self , n_clses ) : <EOL> self . n_clses = n_clses <EOL> self . _coefs = "<STR_LIT>" <EOL> def fit ( self , x , y ) : <EOL> pass <EOL> def predict_proba ( self , x ) : <EOL> return np . zeros ( ( len ( x ) , self . n_clses ) ) <EOL> class TestEstimators ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data = make_data ( <NUM_LIT:10> ) <EOL> def test_probabilities ( self ) : <EOL> inner_est = DummyProbEstimator ( <NUM_LIT:3> ) <EOL> est = wrap_sklearn_like_estimator ( inner_est ) <EOL> self . assertEqual ( est . _coefs , inner_est . _coefs ) <EOL> self . assertRaises ( AttributeError , getattr , est , '<STR_LIT>' ) <EOL> preds = est . predict ( self . data . values ) <EOL> self . assertEqual ( preds . shape , ( <NUM_LIT:10> , <NUM_LIT:3> ) ) <EOL> def test_binary_probabilities ( self ) : <EOL> inner_est = DummyProbEstimator ( <NUM_LIT:2> ) <EOL> est = wrap_sklearn_like_estimator ( inner_est ) <EOL> self . assertEqual ( est . _coefs , inner_est . _coefs ) <EOL> preds = est . predict ( self . data . values ) <EOL> self . assertEqual ( preds . shape , ( <NUM_LIT:10> , ) ) <EOL> def test_sklearn_probabilities ( self ) : <EOL> self . data [ '<STR_LIT:target>' ] = [ <NUM_LIT:0> ] * <NUM_LIT:5> + [ <NUM_LIT:1> ] * <NUM_LIT:3> + [ <NUM_LIT:2> ] * <NUM_LIT:2> <EOL> inner_est = linear_model . LogisticRegression ( ) <EOL> est = wrap_sklearn_like_estimator ( inner_est ) <EOL> x = self . data [ [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ] <EOL> est . fit ( x , self . data . target ) <EOL> preds = est . predict ( x ) <EOL> self . assertEqual ( preds . shape , ( <NUM_LIT:10> , <NUM_LIT:3> ) ) <EOL> self . data [ '<STR_LIT:target>' ] = [ <NUM_LIT:0> ] * <NUM_LIT:5> + [ <NUM_LIT:1> ] * <NUM_LIT:5> <EOL> est = BinaryProbabilities ( inner_est ) <EOL> x = self . data [ [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ] <EOL> est . fit ( x , self . data . target ) <EOL> preds = est . predict ( x ) <EOL> self . assertEqual ( preds . shape , ( <NUM_LIT:10> , ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
