<s> import sys <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> import unittest <EOL> import numpy as np <EOL> import pandas as pd <EOL> from pandas import DataFrame , Series , Index <EOL> from pandas . util . testing import assert_almost_equal <EOL> from ramp . builders import * <EOL> from ramp . estimators . base import Probabilities <EOL> from ramp . features . base import F , Map <EOL> from ramp . features . trained import Predictions <EOL> from ramp . model_definition import ModelDefinition <EOL> from ramp . selectors import BinaryFeatureSelector <EOL> from ramp . tests . test_features import make_data <EOL> class TestSelectors ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data = make_data ( <NUM_LIT:100> ) <EOL> def test_binary_selectors ( self ) : <EOL> d = self . data <EOL> d [ '<STR_LIT:target>' ] = [ <NUM_LIT:0> ] * <NUM_LIT:50> + [ <NUM_LIT:1> ] * <NUM_LIT:50> <EOL> d [ '<STR_LIT>' ] = [ <NUM_LIT:0> ] * <NUM_LIT> + [ <NUM_LIT:1> ] * <NUM_LIT> <EOL> d [ '<STR_LIT>' ] = d [ '<STR_LIT:target>' ] <EOL> features = map ( F , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> selector = BinaryFeatureSelector ( ) <EOL> x , ffs = build_featureset_safe ( features , self . data ) <EOL> y , ff = build_target_safe ( F ( '<STR_LIT:target>' ) , self . data ) <EOL> cols = selector . select ( x , y , <NUM_LIT:2> ) <EOL> feature_rank = [ F ( '<STR_LIT>' ) , F ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( cols , [ f . unique_name for f in feature_rank ] ) <EOL> def test_binary_selectors_multiclass ( self ) : <EOL> d = self . data <EOL> d [ '<STR_LIT:target>' ] = [ <NUM_LIT:0> ] * <NUM_LIT:50> + [ <NUM_LIT:1> ] * <NUM_LIT> + [ <NUM_LIT:2> ] * <NUM_LIT> <EOL> d [ '<STR_LIT>' ] = [ <NUM_LIT:0> ] * <NUM_LIT> + [ <NUM_LIT:1> ] * <NUM_LIT> <EOL> d [ '<STR_LIT>' ] = d [ '<STR_LIT:target>' ] <EOL> features = map ( F , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> selector = BinaryFeatureSelector ( ) <EOL> x , ffs = build_featureset_safe ( features , self . data ) <EOL> y , ff = build_target_safe ( F ( '<STR_LIT:target>' ) , self . data ) <EOL> cols = selector . select ( x , y , <NUM_LIT:2> ) <EOL> feature_rank = [ F ( '<STR_LIT>' ) , F ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( cols , [ f . unique_name for f in feature_rank ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
