<commit_before>import sys
sys.path.insert(1,"../../")
import h2o
from tests import pyunit_utils
from h2o.estimators.gbm import H2OGradientBoostingEstimator


def mycomp(l,r):
    assert len(l) == len(r)
    for i in range(len(l)):
        z = [li == ri for li,ri in zip(l[i],r[i])]
        assert all(z), str(i) + ":" +  str(z)

def pubdev_2118():
    df = h2o.import_file(pyunit_utils.locate("smalldata/prostate/prostate.csv"))
    df["CAPSULE"]=df["CAPSULE"].asfactor()

    m = H2OGradientBoostingEstimator()
    m.train(x=df.names,y="CAPSULE", training_frame=df, validation_frame=df)

    t = m.gains_lift()
    #print t.cell_values
    exp = [(u'', 1, 0.9409068479230197, 0.05, 1.0, 1.0, 0.12418300653594772, 0.12418300653594772, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 2, 0.913233550021648, 0.1, 1.0, 1.0, 0.12418300653594772, 0.24836601307189543, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 3, 0.8530775788448136, 0.15, 1.0, 1.0, 0.12418300653594772, 0.37254901960784315, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 4, 0.7764798505313826, 0.2, 1.0, 1.0, 0.12418300653594772, 0.49673202614379086, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 5, 0.7315405555429344, 0.25, 0.9473684210526315, 0.9894736842105263, 0.11764705882352941, 0.6143790849673203, 2.3529411764705883, 2.457516339869281, 135.29411764705884, 145.7516339869281), (u'', 6, 0.6625334258596751, 0.3, 0.9473684210526315, 0.9824561403508771, 0.11764705882352941, 0.7320261437908496, 2.3529411764705883, 2.440087145969499, 135.29411764705884, 144.0087145969499), (u'', 7, 0.542319049046372, 0.35, 0.8947368421052632, 0.9699248120300752, 0.1111111111111111, 0.8431372549019608, 2.2222222222222223, 2.408963585434174, 122.22222222222223, 140.8963585434174), (u'', 8, 0.44550968201310875, 0.4, 0.5789473684210527, 0.9210526315789473, 0.0718954248366013, 0.9150326797385621, 1.4379084967320264, 2.287581699346405, 43.790849673202636, 128.7581699346405), (u'', 9, 0.34999222436374683, 0.45, 0.47368421052631576, 0.8713450292397661, 0.058823529411764705, 0.9738562091503268, 1.1764705882352942, 2.1641249092229486, 17.647058823529417, 116.41249092229486), (u'', 10, 0.28522566882364025, 0.5, 0.10526315789473684, 0.7947368421052632, 0.013071895424836602, 0.9869281045751634, 0.26143790849673204, 1.973856209150327, -73.8562091503268, 97.38562091503269), (u'', 11, 0.23218966960340387, 0.55, 0.05263157894736842, 0.7272727272727273, 0.006535947712418301, 0.9934640522875817, 0.13071895424836602, 1.8062982768865123, -86.9281045751634, 80.62982768865123), (u'', 12, 0.1936995396749589, 0.6, 0.05263157894736842, 0.6710526315789473, 0.006535947712418301, 1.0, 0.13071895424836602, 1.6666666666666667, -86.9281045751634, 66.66666666666667), (u'', 13, 0.15082401964976863, 0.65, 0.0, 0.6194331983805668, 0.0, 1.0, 0.0, 1.5384615384615385, -100.0, 53.846153846153854), (u'', 14, 0.1329892269711336, 0.7, 0.0, 0.575187969924812, 0.0, 1.0, 0.0, 1.4285714285714286, -100.0, 42.85714285714286), (u'', 15, 0.11199972606419058, 0.75, 0.0, 0.5368421052631579, 0.0, 1.0, 0.0, 1.3333333333333335, -100.0, 33.33333333333335), (u'', 16, 0.08814323266873904, 0.8, 0.0, 0.5032894736842105, 0.0, 1.0, 0.0, 1.25, -100.0, 25.0), (u'', 17, 0.06637277381422949, 0.85, 0.0, 0.47368421052631576, 0.0, 1.0, 0.0, 1.1764705882352942, -100.0, 17.647058823529417), (u'', 18, 0.05213844307920567, 0.9, 0.0, 0.4473684210526316, 0.0, 1.0, 0.0, 1.1111111111111112, -100.0, 11.111111111111116), (u'', 19, 0.03508091722329987, 0.95, 0.0, 0.42382271468144045, 0.0, 1.0, 0.0, 1.0526315789473686, -100.0, 5.2631578947368585), (u'', 20, 0.012507127666986435, 1.0, 0.0, 0.4026315789473684, 0.0, 1.0, 0.0, 1.0, -100.0, 0.0)]
    mycomp(exp, t.cell_values)

    t = m.gains_lift(valid=True)
    mycomp(exp, t.cell_values)

    p = m.model_performance(df)
    t = p.gains_lift()
    mycomp(exp, t.cell_values)


    m = H2OGradientBoostingEstimator(nfolds=3, seed=1234)
    m.train(x=df.names,y="CAPSULE", training_frame=df, validation_frame=df, seed = 1234)
    t = m.gains_lift(xval=True)

    #print t.cell_values
    exp2 = [(u'', 1, 0.927872822385609, 0.05, 0.7894736842105263, 0.7894736842105263, 0.09803921568627451, 0.09803921568627451, 1.9607843137254903, 1.9607843137254903, 96.07843137254903, 96.07843137254903), (u'', 2, 0.8516301891008856, 0.1, 0.9473684210526315, 0.868421052631579, 0.11764705882352941, 0.21568627450980393, 2.3529411764705883, 2.1568627450980395, 135.29411764705884, 115.68627450980395), (u'', 3, 0.8046106844759681, 0.15, 0.5789473684210527, 0.7719298245614035, 0.0718954248366013, 0.2875816993464052, 1.4379084967320264, 1.9172113289760349, 43.790849673202636, 91.72113289760348), (u'', 4, 0.7284369896198815, 0.2, 0.631578947368421, 0.7368421052631579, 0.0784313725490196, 0.3660130718954248, 1.5686274509803921, 1.8300653594771241, 56.86274509803921, 83.00653594771241), (u'', 5, 0.6444460926934387, 0.25, 0.7368421052631579, 0.7368421052631579, 0.0915032679738562, 0.45751633986928103, 1.8300653594771241, 1.8300653594771241, 83.00653594771241, 83.00653594771241), (u'', 6, 0.5692906465516154, 0.3, 0.5789473684210527, 0.7105263157894737, 0.0718954248366013, 0.5294117647058824, 1.4379084967320264, 1.7647058823529413, 43.790849673202636, 76.47058823529413), (u'', 7, 0.5020420880521753, 0.35, 0.5263157894736842, 0.6842105263157895, 0.06535947712418301, 0.5947712418300654, 1.3071895424836601, 1.6993464052287583, 30.718954248366014, 69.93464052287584), (u'', 8, 0.4300841468675116, 0.4, 0.631578947368421, 0.6776315789473685, 0.0784313725490196, 0.673202614379085, 1.5686274509803921, 1.6830065359477127, 56.86274509803921, 68.30065359477126), (u'', 9, 0.36198965947188116, 0.45, 0.3157894736842105, 0.6374269005847953, 0.0392156862745098, 0.7124183006535948, 0.7843137254901961, 1.5831517792302108, -21.568627450980394, 58.315177923021075), (u'', 10, 0.3173814560872434, 0.5, 0.42105263157894735, 0.6157894736842106, 0.05228758169934641, 0.7647058823529411, 1.0457516339869282, 1.5294117647058825, 4.575163398692816, 52.941176470588246), (u'', 11, 0.27117774075107115, 0.55, 0.42105263157894735, 0.5980861244019139, 0.05228758169934641, 0.8169934640522876, 1.0457516339869282, 1.4854426619132504, 4.575163398692816, 48.544266191325036), (u'', 12, 0.23053675494928735, 0.6, 0.2631578947368421, 0.5701754385964912, 0.032679738562091505, 0.8496732026143791, 0.6535947712418301, 1.4161220043572986, -34.64052287581699, 41.61220043572986), (u'', 13, 0.18868430686508345, 0.65, 0.3684210526315789, 0.5546558704453441, 0.0457516339869281, 0.8954248366013072, 0.9150326797385621, 1.377576671694319, -8.496732026143794, 37.7576671694319), (u'', 14, 0.1508394962100898, 0.7, 0.15789473684210525, 0.5263157894736842, 0.0196078431372549, 0.9150326797385621, 0.39215686274509803, 1.3071895424836601, -60.7843137254902, 30.718954248366014), (u'', 15, 0.11331759903751726, 0.75, 0.10526315789473684, 0.4982456140350877, 0.013071895424836602, 0.9281045751633987, 0.26143790849673204, 1.2374727668845316, -73.8562091503268, 23.747276688453155), (u'', 16, 0.09224070528779757, 0.8, 0.21052631578947367, 0.48026315789473684, 0.026143790849673203, 0.954248366013072, 0.5228758169934641, 1.1928104575163399, -47.71241830065359, 19.281045751633986), (u'', 17, 0.07158852619001921, 0.85, 0.05263157894736842, 0.4551083591331269, 0.006535947712418301, 0.9607843137254902, 0.13071895424836602, 1.130334486735871, -86.9281045751634, 13.033448673587088), (u'', 18, 0.05078976895528707, 0.9, 0.10526315789473684, 0.43567251461988304, 0.013071895424836602, 0.9738562091503268, 0.26143790849673204, 1.0820624546114743, -73.8562091503268, 8.206245461147432), (u'', 19, 0.031178798922612643, 0.95, 0.10526315789473684, 0.4182825484764543, 0.013071895424836602, 0.9869281045751634, 0.26143790849673204, 1.038871689026488, -73.8562091503268, 3.8871689026487966), (u'', 20, 0.018192515651430492, 1.0, 0.10526315789473684, 0.4026315789473684, 0.013071895424836602, 1.0, 0.26143790849673204, 1.0, -73.8562091503268, 0.0)]
    mycomp(exp2, t.cell_values)


    p = m.model_performance(df)
    t = p.gains_lift()
    mycomp(exp, t.cell_values)


if __name__ == "__main__":
    pyunit_utils.standalone_test(pubdev_2118)
else:
    pubdev_2118()<commit_msg>PUBDEV-2118: Fix Python test for Gains/Lift.<commit_after>import sys
sys.path.insert(1,"../../")
import h2o
from tests import pyunit_utils
from h2o.estimators.gbm import H2OGradientBoostingEstimator


def mycomp(l,r):
    assert len(l) == len(r)
    for i in range(len(l)):
        z = [li == ri for li,ri in zip(l[i],r[i])]
        assert all(z), str(i) + ":" +  str(z)

def pubdev_2118():
    df = h2o.import_file(pyunit_utils.locate("smalldata/prostate/prostate.csv"))
    df["CAPSULE"]=df["CAPSULE"].asfactor()

    m = H2OGradientBoostingEstimator()
    m.train(x=df.names,y="CAPSULE", training_frame=df, validation_frame=df)

    t = m.gains_lift()
    #print t.cell_values
    exp = [(u'', 1, 0.9422446864324429, 0.05, 1.0, 1.0, 0.12418300653594772, 0.12418300653594772, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 2, 0.9140976950833801, 0.1, 1.0, 1.0, 0.12418300653594772, 0.24836601307189543, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 3, 0.8540393947078193, 0.15, 1.0, 1.0, 0.12418300653594772, 0.37254901960784315, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 4, 0.7771861468640092, 0.2, 1.0, 1.0, 0.12418300653594772, 0.49673202614379086, 2.4836601307189543, 2.4836601307189543, 148.36601307189542, 148.36601307189542), (u'', 5, 0.7319701639598197, 0.25, 0.9473684210526315, 0.9894736842105263, 0.11764705882352941, 0.6143790849673203, 2.3529411764705883, 2.457516339869281, 135.29411764705884, 145.7516339869281), (u'', 6, 0.662998245255539, 0.3, 0.9473684210526315, 0.9824561403508771, 0.11764705882352941, 0.7320261437908496, 2.3529411764705883, 2.440087145969499, 135.29411764705884, 144.0087145969499), (u'', 7, 0.5432526308373125, 0.35, 0.8947368421052632, 0.9699248120300752, 0.1111111111111111, 0.8431372549019608, 2.2222222222222223, 2.408963585434174, 122.22222222222223, 140.8963585434174), (u'', 8, 0.45008336775676805, 0.4, 0.5789473684210527, 0.9210526315789473, 0.0718954248366013, 0.9150326797385621, 1.4379084967320264, 2.287581699346405, 43.790849673202636, 128.7581699346405), (u'', 9, 0.35017173109204247, 0.45, 0.47368421052631576, 0.8713450292397661, 0.058823529411764705, 0.9738562091503268, 1.1764705882352942, 2.1641249092229486, 17.647058823529417, 116.41249092229486), (u'', 10, 0.29069575770252565, 0.5, 0.10526315789473684, 0.7947368421052632, 0.013071895424836602, 0.9869281045751634, 0.26143790849673204, 1.973856209150327, -73.8562091503268, 97.38562091503269), (u'', 11, 0.23311088428042476, 0.55, 0.05263157894736842, 0.7272727272727273, 0.006535947712418301, 0.9934640522875817, 0.13071895424836602, 1.8062982768865123, -86.9281045751634, 80.62982768865123), (u'', 12, 0.19436018674216024, 0.6, 0.05263157894736842, 0.6710526315789473, 0.006535947712418301, 1.0, 0.13071895424836602, 1.6666666666666667, -86.9281045751634, 66.66666666666667), (u'', 13, 0.1512222891837316, 0.65, 0.0, 0.6194331983805668, 0.0, 1.0, 0.0, 1.5384615384615385, -100.0, 53.846153846153854), (u'', 14, 0.13338744662416913, 0.7, 0.0, 0.575187969924812, 0.0, 1.0, 0.0, 1.4285714285714286, -100.0, 42.85714285714286), (u'', 15, 0.1120261104775509, 0.75, 0.0, 0.5368421052631579, 0.0, 1.0, 0.0, 1.3333333333333335, -100.0, 33.33333333333335), (u'', 16, 0.08829848624839703, 0.8, 0.0, 0.5032894736842105, 0.0, 1.0, 0.0, 1.25, -100.0, 25.0), (u'', 17, 0.06644003136140778, 0.85, 0.0, 0.47368421052631576, 0.0, 1.0, 0.0, 1.1764705882352942, -100.0, 17.647058823529417), (u'', 18, 0.05218767708316055, 0.9, 0.0, 0.4473684210526316, 0.0, 1.0, 0.0, 1.1111111111111112, -100.0, 11.111111111111116), (u'', 19, 0.035103630291161134, 0.95, 0.0, 0.42382271468144045, 0.0, 1.0, 0.0, 1.0526315789473686, -100.0, 5.2631578947368585), (u'', 20, 0.012507127666986435, 1.0, 0.0, 0.4026315789473684, 0.0, 1.0, 0.0, 1.0, -100.0, 0.0)]
    mycomp(exp, t.cell_values)

    t = m.gains_lift(valid=True)
    mycomp(exp, t.cell_values)

    p = m.model_performance(df)
    t = p.gains_lift()
    mycomp(exp, t.cell_values)


    m = H2OGradientBoostingEstimator(nfolds=3, seed=1234)
    m.train(x=df.names,y="CAPSULE", training_frame=df, validation_frame=df, seed = 1234)
    t = m.gains_lift(xval=True)

    #print t.cell_values
    exp2 = [(u'', 1, 0.9312498200486936, 0.05, 0.7894736842105263, 0.7894736842105263, 0.09803921568627451, 0.09803921568627451, 1.9607843137254903, 1.9607843137254903, 96.07843137254903, 96.07843137254903), (u'', 2, 0.8545351347274881, 0.1, 0.9473684210526315, 0.868421052631579, 0.11764705882352941, 0.21568627450980393, 2.3529411764705883, 2.1568627450980395, 135.29411764705884, 115.68627450980395), (u'', 3, 0.8054462064730099, 0.15, 0.5789473684210527, 0.7719298245614035, 0.0718954248366013, 0.2875816993464052, 1.4379084967320264, 1.9172113289760349, 43.790849673202636, 91.72113289760348), (u'', 4, 0.7288136701605376, 0.2, 0.631578947368421, 0.7368421052631579, 0.0784313725490196, 0.3660130718954248, 1.5686274509803921, 1.8300653594771241, 56.86274509803921, 83.00653594771241), (u'', 5, 0.6449152561308045, 0.25, 0.7368421052631579, 0.7368421052631579, 0.0915032679738562, 0.45751633986928103, 1.8300653594771241, 1.8300653594771241, 83.00653594771241, 83.00653594771241), (u'', 6, 0.5699185153099109, 0.3, 0.5789473684210527, 0.7105263157894737, 0.0718954248366013, 0.5294117647058824, 1.4379084967320264, 1.7647058823529413, 43.790849673202636, 76.47058823529413), (u'', 7, 0.5109394131462176, 0.35, 0.5263157894736842, 0.6842105263157895, 0.06535947712418301, 0.5947712418300654, 1.3071895424836601, 1.6993464052287583, 30.718954248366014, 69.93464052287584), (u'', 8, 0.43086214857802385, 0.4, 0.631578947368421, 0.6776315789473685, 0.0784313725490196, 0.673202614379085, 1.5686274509803921, 1.6830065359477127, 56.86274509803921, 68.30065359477126), (u'', 9, 0.365787311701332, 0.45, 0.3157894736842105, 0.6374269005847953, 0.0392156862745098, 0.7124183006535948, 0.7843137254901961, 1.5831517792302108, -21.568627450980394, 58.315177923021075), (u'', 10, 0.31865614624496985, 0.5, 0.42105263157894735, 0.6157894736842106, 0.05228758169934641, 0.7647058823529411, 1.0457516339869282, 1.5294117647058825, 4.575163398692816, 52.941176470588246), (u'', 11, 0.27160313517007467, 0.55, 0.42105263157894735, 0.5980861244019139, 0.05228758169934641, 0.8169934640522876, 1.0457516339869282, 1.4854426619132504, 4.575163398692816, 48.544266191325036), (u'', 12, 0.23101198964089953, 0.6, 0.2631578947368421, 0.5701754385964912, 0.032679738562091505, 0.8496732026143791, 0.6535947712418301, 1.4161220043572986, -34.64052287581699, 41.61220043572986), (u'', 13, 0.19045983139477088, 0.65, 0.3684210526315789, 0.5546558704453441, 0.0457516339869281, 0.8954248366013072, 0.9150326797385621, 1.377576671694319, -8.496732026143794, 37.7576671694319), (u'', 14, 0.15094564581772346, 0.7, 0.15789473684210525, 0.5263157894736842, 0.0196078431372549, 0.9150326797385621, 0.39215686274509803, 1.3071895424836601, -60.7843137254902, 30.718954248366014), (u'', 15, 0.11385697663037135, 0.75, 0.10526315789473684, 0.4982456140350877, 0.013071895424836602, 0.9281045751633987, 0.26143790849673204, 1.2374727668845316, -73.8562091503268, 23.747276688453155), (u'', 16, 0.09232448326224123, 0.8, 0.21052631578947367, 0.48026315789473684, 0.026143790849673203, 0.954248366013072, 0.5228758169934641, 1.1928104575163399, -47.71241830065359, 19.281045751633986), (u'', 17, 0.07170036559022148, 0.85, 0.05263157894736842, 0.4551083591331269, 0.006535947712418301, 0.9607843137254902, 0.13071895424836602, 1.130334486735871, -86.9281045751634, 13.033448673587088), (u'', 18, 0.05086288900209861, 0.9, 0.10526315789473684, 0.43567251461988304, 0.013071895424836602, 0.9738562091503268, 0.26143790849673204, 1.0820624546114743, -73.8562091503268, 8.206245461147432), (u'', 19, 0.031202138253460243, 0.95, 0.10526315789473684, 0.4182825484764543, 0.013071895424836602, 0.9869281045751634, 0.26143790849673204, 1.038871689026488, -73.8562091503268, 3.8871689026487966), (u'', 20, 0.018192515651430492, 1.0, 0.10526315789473684, 0.4026315789473684, 0.013071895424836602, 1.0, 0.26143790849673204, 1.0, -73.8562091503268, 0.0)]
    mycomp(exp2, t.cell_values)


    p = m.model_performance(df)
    t = p.gains_lift()
    mycomp(exp, t.cell_values)


if __name__ == "__main__":
    pyunit_utils.standalone_test(pubdev_2118)
else:
    pubdev_2118()
{'fraction_non_alphanumeric': 0.149919301811226, 'fraction_numerical': 0.659931854862813, 'mean_word_length': 6.0799830723656365, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 18, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7550311', 'n_tokens_mistral': 14982, 'n_tokens_neox': 8164, 'n_words': 1138}