Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CherylCB committed Mar 29, 2019
1 parent b209d19 commit ec06b62
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 32 deletions.
4 changes: 3 additions & 1 deletion pyearth/_forward.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,11 @@ cdef class ForwardPasser:
else:
gcv_ = gcv_factor_k_plus_1 * mse_

if linear_variables[variable]:
if linear_variables[variable] and variable_can_be_linear:
mse = mse_
knot_idx = -1
elif linear_variables[variable] and not variable_can_be_linear:
continue
else:
# Find the valid knot candidates
candidates, candidates_idx = predictor.knot_candidates(p, self.endspan,
Expand Down
197 changes: 197 additions & 0 deletions pyearth/test/pathological_data/issue_195.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,y
0,576.80992,0,0,1,0,0,123,0,871,488.00827000000004,130.0,0,1306.9917300000004
1,488.00827000000004,0,0,0,0,0,108,1,872,497.00827000000004,154.0,0,943.27274
2,497.00827000000004,1,0,0,0,0,117,0,873,435.68599000000006,149.0,0,1090.1405100000004
3,435.68599000000006,0,0,0,0,0,92,0,874,430.68595,128.0,1,818.20663
4,430.68595,0,0,0,0,1,123,0,875,476.1405,137.0,0,1030.55374
5,476.1405,0,0,0,1,0,107,0,876,566.10744,129.0,0,1159.1570400000005
6,566.10744,0,1,0,0,0,101,0,877,625.5702600000002,128.0,0,938.69425
7,625.5702600000002,0,0,1,0,0,86,0,878,555.89255,178.0,0,1033.77687
8,555.89255,0,0,0,0,0,105,1,879,648.57027,108.0,0,704.43801
9,648.57027,1,0,0,0,0,98,0,880,514.05787,142.0,0,750.6776699999998
10,514.05787,0,0,0,0,0,98,0,881,353.54545999999993,140.0,1,807.1570200000001
11,353.54545999999993,0,0,0,0,1,79,0,882,326.09091,138.0,0,737.20657
12,326.09091,0,0,0,1,0,89,0,883,685.0826399999999,99.0,0,737.85948
13,685.0826399999999,0,1,0,0,0,138,0,884,410.68597,142.0,0,529.3884099999998
14,410.68597,0,0,1,0,0,101,0,885,658.14877,175.0,0,1105.28099
15,658.14877,0,0,0,0,0,134,1,886,715.6115900000001,132.0,0,737.9339
16,715.6115900000001,1,0,0,0,0,114,0,887,988.96698,152.0,0,1029.7438499999996
17,988.96698,0,0,0,0,0,119,0,888,840.1487600000003,180.0,1,993.9421199999999
18,840.1487600000003,0,0,0,0,1,175,0,889,929.9008,422.0,0,1316.1405200000004
19,929.9008,0,0,0,1,0,116,0,890,928.71072,268.0,0,971.4876400000003
20,928.71072,0,1,0,0,0,135,0,891,1372.5040799999995,255.0,0,1009.4793800000001
21,1372.5040799999995,0,0,1,0,0,123,0,892,1151.0082199999995,213.0,0,1049.34714
22,1151.0082199999995,0,0,0,0,0,129,1,893,1058.7851199999998,291.0,0,986.5289100000003
23,1058.7851199999998,1,0,0,0,0,132,0,894,999.8099,286.0,0,1219.7768400000002
24,999.8099,0,0,0,0,0,117,0,895,869.1073999999999,243.0,1,1064.7934200000002
25,869.1073999999999,0,0,0,0,1,112,0,896,724.1735500000002,224.0,0,957.06613
26,724.1735500000002,0,0,0,1,0,88,0,897,945.54542,209.0,0,509.14051
27,945.54542,0,1,0,0,0,146,0,898,1283.3884200000002,310.0,0,1517.6446400000007
28,1283.3884200000002,0,0,1,0,0,105,0,899,920.51239,244.0,0,1151.3223200000002
29,920.51239,0,0,0,0,0,90,1,900,1215.8925199999996,151.0,0,808.20661
30,1215.8925199999996,1,0,0,0,0,115,0,901,953.42973,149.0,0,1164.9504300000006
31,953.42973,0,0,0,0,0,76,0,902,982.5454800000001,173.0,1,991.405
32,982.5454800000001,0,0,0,0,1,108,0,903,970.9835099999999,186.0,0,1057.61159
33,970.9835099999999,0,0,0,1,0,68,0,904,863.9339099999999,146.0,0,806.3801599999998
34,863.9339099999999,0,1,0,0,0,116,0,905,1381.2231999999995,243.0,0,1143.71076
35,1381.2231999999995,0,0,1,0,0,115,0,906,1229.56194,259.0,0,1034.51241
36,1229.56194,0,0,0,0,0,112,1,907,980.99998,252.0,0,839.3553800000001
37,980.99998,1,0,0,0,0,134,0,908,1239.13225,284.0,0,1208.71906
38,1239.13225,0,0,0,0,0,124,0,909,756.2810000000003,241.0,1,1345.6281099999999
39,756.2810000000003,0,0,0,0,1,99,0,910,1100.87603,273.0,0,730.80164
40,1100.87603,0,0,0,1,0,95,0,911,838.4049200000003,201.0,0,918.52892
41,838.4049200000003,0,1,0,0,0,152,0,912,1483.55371,352.0,0,1368.3801400000002
42,1483.55371,0,0,1,0,0,129,0,913,1528.8098599999996,381.0,0,1485.21484
43,1528.8098599999996,0,0,0,0,0,119,1,914,1272.4545299999995,354.0,0,1211.5206700000006
44,1272.4545299999995,1,0,0,0,0,128,0,915,1587.51244,340.0,0,1234.8925099999994
45,1587.51244,0,0,0,0,0,114,0,916,1251.9090800000001,402.0,1,1289.0991800000004
46,1251.9090800000001,0,0,0,0,1,110,0,917,1205.46276,315.0,0,863.45455
47,1205.46276,0,0,0,1,0,77,0,918,558.0909300000002,175.0,0,600.3305799999999
48,558.0909300000002,0,1,0,0,0,70,0,919,255.80991000000003,107.0,0,456.90084
49,255.80991000000003,0,0,1,0,0,56,0,920,1022.6860199999999,78.0,0,399.71901
50,1022.6860199999999,0,0,0,0,0,74,1,921,848.12401,149.0,0,689.6611599999999
51,848.12401,1,0,0,0,0,150,0,922,1162.3306300000004,204.0,0,1100.7437799999998
52,1162.3306300000004,0,0,0,0,0,119,0,923,1479.9918500000006,189.0,1,1019.77685
53,1479.9918500000006,0,0,0,0,1,112,0,924,751.0413700000001,189.0,0,1350.7933599999994
54,751.0413700000001,0,0,0,1,0,83,0,925,419.02481,114.0,0,688.72728
55,419.02481,0,1,0,0,0,84,0,926,667.0579,84.0,0,724.57853
56,667.0579,0,0,1,0,0,105,0,927,921.19838,104.0,0,772.3636100000003
57,921.19838,0,0,0,0,0,120,1,928,1177.29755,133.0,0,1250.1983699999998
58,1177.29755,1,0,0,0,0,156,0,929,923.93387,150.0,0,1224.60332
59,923.93387,0,0,0,0,0,100,0,930,888.0165300000001,121.0,1,839.5371899999999
60,888.0165300000001,0,0,0,0,1,93,0,931,600.4462900000001,92.0,0,514.0826099999998
61,600.4462900000001,0,0,0,1,0,82,0,932,968.9090800000004,70.0,0,690.4793400000002
62,968.9090800000004,0,1,0,0,0,102,0,933,1131.5289399999995,95.0,0,527.8843
63,1131.5289399999995,0,0,1,0,0,92,0,934,1120.88432,83.0,0,554.85949
64,1120.88432,0,0,0,0,0,98,1,935,588.47108,112.0,0,567.23969
65,588.47108,1,0,0,0,0,94,0,936,714.8347600000003,101.0,0,629.0909100000001
66,714.8347600000003,0,0,0,0,0,82,0,937,1048.9339,105.0,1,757.52894
67,1048.9339,0,0,0,0,1,93,0,938,842.03306,108.0,0,842.5785099999997
68,842.03306,0,0,0,1,0,74,0,939,596.0578700000002,91.0,0,697.2644699999997
69,596.0578700000002,0,1,0,0,0,105,0,940,1000.37195,113.0,0,983.53718
70,1000.37195,0,0,1,0,0,105,0,941,692.8512800000002,136.0,0,974.31407
71,692.8512800000002,0,0,0,0,0,101,1,942,438.80995,125.0,0,579.5537400000001
72,438.80995,1,0,0,0,0,116,0,943,750.0826599999998,145.0,0,943.17357
73,750.0826599999998,0,0,0,0,0,71,0,944,529.281,101.0,1,625.2810000000002
74,529.281,0,0,0,0,1,66,0,945,718.9752199999998,127.0,0,528.9008299999999
75,718.9752199999998,0,0,0,1,0,88,0,946,745.4132699999999,123.0,0,707.23967
76,745.4132699999999,0,1,0,0,0,106,0,947,522.5206700000001,129.0,0,1065.2231499999998
77,522.5206700000001,0,0,1,0,0,96,0,948,861.85957,138.0,0,736.2892700000001
78,861.85957,0,0,0,0,0,105,1,949,678.3140599999999,116.0,0,893.8843199999999
79,678.3140599999999,1,0,0,0,0,106,0,950,951.32238,165.0,0,1015.3802
80,951.32238,0,0,0,0,0,94,0,951,1194.73558,160.0,1,905.1735800000001
81,1194.73558,0,0,0,0,1,83,0,952,802.6529000000003,124.0,0,663.53719
82,802.6529000000003,0,0,0,1,0,77,0,953,832.42152,155.0,0,800.32231
83,832.42152,0,1,0,0,0,90,0,954,940.5372199999999,170.0,0,1103.04136
84,940.5372199999999,0,0,1,0,0,86,0,955,808.35542,140.0,0,730.1653099999999
85,808.35542,0,0,0,0,0,85,1,956,882.5785299999999,130.0,0,584.23967
86,882.5785299999999,1,0,0,0,0,83,0,957,987.82654,118.0,0,823.6859900000003
87,987.82654,0,0,0,0,0,72,0,958,613.63637,124.0,1,974.50416
88,613.63637,0,0,0,0,1,77,0,959,707.1322299999999,99.0,0,722.7272999999997
89,707.1322299999999,0,0,0,1,0,81,0,960,600.20662,108.0,0,510.52894000000003
90,600.20662,0,1,0,0,0,73,0,961,1227.35538,115.0,0,772.7273100000001
91,1227.35538,0,0,1,0,0,77,0,962,992.2727600000003,103.0,0,508.31406
92,992.2727600000003,0,0,0,0,0,93,1,963,687.45453,105.0,0,914.8678
93,687.45453,1,0,0,0,0,66,0,964,954.07443,115.0,0,735.69426
94,954.07443,0,0,0,0,0,86,0,965,794.80168,131.0,1,736.7356000000002
95,794.80168,0,0,0,0,1,65,0,966,744.1405100000002,97.0,0,799.6033299999998
96,744.1405100000002,0,0,0,1,0,61,0,967,961.05789,85.0,0,409.53721
97,961.05789,0,1,0,0,0,86,0,968,1289.0496399999995,111.0,0,760.5289799999998
98,1289.0496399999995,0,0,1,0,0,78,0,969,957.4628300000003,106.0,0,757.63639
99,957.4628300000003,0,0,0,0,0,64,1,970,748.53721,102.0,0,554.90085
100,748.53721,1,0,0,0,0,75,0,971,534.6528900000002,96.0,0,511.13227000000006
101,534.6528900000002,0,0,0,0,0,68,0,972,770.9752300000001,93.0,1,535.1818400000001
102,770.9752300000001,0,0,0,0,1,68,0,973,684.33887,106.0,0,729.85127
103,684.33887,0,0,0,1,0,50,0,974,801.67772,80.0,0,538.48762
104,801.67772,0,1,0,0,0,68,0,975,772.57027,90.0,0,634.0248300000002
105,772.57027,0,0,1,0,0,59,0,976,497.57028000000014,67.0,0,734.14051
106,497.57028000000014,0,0,0,0,0,78,1,977,846.2396800000001,79.0,0,492.63637
107,846.2396800000001,1,0,0,0,0,81,0,978,741.26444,113.0,0,621.38846
108,741.26444,0,0,0,0,0,75,0,979,706.8512499999998,98.0,1,790.1322499999999
109,706.8512499999998,0,0,0,0,1,56,0,980,927.57853,100.0,0,731.2479600000001
110,927.57853,0,0,0,1,0,79,0,981,525.2231700000002,90.0,0,673.3058
111,525.2231700000002,0,1,0,0,0,83,0,982,1252.4545499999995,112.0,0,616.90912
112,1252.4545499999995,0,0,1,0,0,105,0,983,883.0413199999999,99.0,0,892.11575
113,883.0413199999999,0,0,0,0,0,97,1,984,667.2809900000002,122.0,0,892.82649
114,667.2809900000002,1,0,0,0,0,85,0,985,747.2148900000002,131.0,0,550.0744
115,747.2148900000002,0,0,0,0,0,64,0,986,663.3388800000001,92.0,1,673.6529200000001
116,663.3388800000001,0,0,0,0,1,70,0,987,620.2314500000001,112.0,0,701.71906
117,620.2314500000001,0,0,0,1,0,87,0,988,370.28099,113.0,0,619.16531
118,370.28099,0,1,0,0,0,74,0,989,965.4793600000003,103.0,0,895.69425
119,965.4793600000003,0,0,1,0,0,75,0,990,557.8264600000001,106.0,0,920.58681
120,557.8264600000001,0,0,0,0,0,72,1,991,587.2892599999999,82.0,0,533.7851599999998
121,587.2892599999999,1,0,0,0,0,83,0,992,879.0909300000002,83.0,0,951.69424
122,879.0909300000002,0,0,0,0,0,73,0,993,596.71074,90.0,1,642.42976
123,596.71074,0,0,0,0,1,101,0,994,591.19836,74.0,0,663.7520900000002
124,591.19836,0,0,0,1,0,85,0,995,571.2810000000002,67.0,0,551.9339299999998
125,571.2810000000002,0,1,0,0,0,95,0,996,432.85125,81.0,0,713.87607
126,432.85125,0,0,1,0,0,87,0,997,613.47933,85.0,0,704.1983900000001
127,613.47933,0,0,0,0,0,96,1,998,926.7190400000001,83.0,0,430.74382
128,926.7190400000001,1,0,0,0,0,72,0,999,841.9834400000001,82.0,0,544.7851499999998
129,841.9834400000001,0,0,0,0,0,87,0,1000,583.0496,66.0,1,632.7603600000001
130,583.0496,0,0,0,0,1,82,0,1001,558.7685700000002,88.0,0,606.3471400000001
131,558.7685700000002,0,0,0,1,0,84,0,1002,722.10742,84.0,0,713.65293
132,722.10742,0,1,0,0,0,112,0,1003,794.3223099999999,97.0,0,787.9752300000001
133,794.3223099999999,0,0,1,0,0,82,0,1004,836.80164,79.0,0,565.05785
134,836.80164,0,0,0,0,0,83,1,1005,803.35536,104.0,0,548.0496
135,803.35536,1,0,0,0,0,71,0,1006,676.2644399999998,110.0,0,803.38843
136,676.2644399999998,0,0,0,0,0,80,0,1007,880.7189800000001,109.0,1,493.27273
137,880.7189800000001,0,0,0,0,1,57,0,1008,620.38846,108.0,0,512.35539
138,620.38846,0,0,0,1,0,59,0,1009,630.1818400000001,90.0,0,526.18182
139,630.1818400000001,0,1,0,0,0,89,0,1010,849.4463099999999,118.0,0,798.2562200000003
140,849.4463099999999,0,0,1,0,0,61,0,1011,686.78515,101.0,0,436.85125000000005
141,686.78515,0,0,0,0,0,71,1,1012,1017.0495600000003,106.0,0,749.5785599999999
142,1017.0495600000003,1,0,0,0,0,88,0,1013,830.51243,101.0,0,860.5124099999999
143,830.51243,0,0,0,0,0,60,0,1014,514.4793599999999,98.0,1,744.4876
144,514.4793599999999,0,0,0,0,1,96,0,1015,889.0412699999998,83.0,0,917.0661
145,889.0412699999998,0,0,0,1,0,46,0,1016,1083.18175,31.0,0,255.93389
146,1083.18175,0,1,0,0,0,58,0,1017,858.0413500000003,46.0,0,491.68598000000014
147,858.0413500000003,0,0,1,0,0,84,0,1018,849.05786,68.0,0,737.3553999999998
148,849.05786,0,0,0,0,0,68,1,1019,790.6528799999999,66.0,0,379.52067999999997
149,790.6528799999999,1,0,0,0,0,110,0,1020,865.6363499999999,91.0,0,725.60333
150,865.6363499999999,0,0,0,0,0,82,0,1021,844.3305399999997,95.0,1,855.4959100000002
151,844.3305399999997,0,0,0,0,1,60,0,1022,727.2148900000001,96.0,0,641.4297799999998
152,727.2148900000001,0,0,0,1,0,46,0,1023,697.6363899999999,64.0,0,505.55375999999984
153,697.6363899999999,0,1,0,0,0,52,0,1024,571.2066599999998,77.0,0,439.15705
154,571.2066599999998,0,0,1,0,0,81,0,1025,872.5454100000002,92.0,0,595.3388600000002
155,872.5454100000002,0,0,0,0,0,84,1,1026,891.5041,71.0,0,530.5289900000001
156,891.5041,1,0,0,0,0,86,0,1027,763.5619600000001,92.0,0,781.6198699999999
157,763.5619600000001,0,0,0,0,0,72,0,1028,671.70251,101.0,1,391.69423
158,671.70251,0,0,0,0,1,69,0,1029,696.8182099999999,81.0,0,595.22319
159,696.8182099999999,0,0,0,1,0,61,0,1030,571.3140900000002,56.0,0,522.19836
160,571.3140900000002,0,1,0,0,0,56,0,1031,650.0083000000002,92.0,0,414.95042000000007
161,650.0083000000002,0,0,1,0,0,59,0,1032,722.62809,100.0,0,533.7438400000001
162,722.62809,0,0,0,0,0,80,1,1033,619.6611700000002,70.0,0,551.2810599999998
163,619.6611700000002,1,0,0,0,0,65,0,1034,873.50413,73.0,0,601.32235
164,873.50413,0,0,0,0,0,56,0,1035,715.04134,88.0,1,525.5041699999998
165,715.04134,0,0,0,0,1,56,0,1036,702.84298,82.0,0,394.39671
166,702.84298,0,0,0,1,0,32,0,1037,551.36366,60.0,0,562.17359
167,551.36366,0,1,0,0,0,55,0,1038,851.8595099999997,64.0,0,419.40499
168,851.8595099999997,0,0,1,0,0,63,0,1039,998.87604,100.0,0,448.24795
169,998.87604,0,0,0,0,0,83,1,1040,869.7438599999999,120.0,0,478.41327
170,869.7438599999999,1,0,0,0,0,63,0,1041,672.38014,106.0,0,525.0909300000002
171,672.38014,0,0,0,0,0,67,0,1042,725.9586499999998,70.0,1,446.90088
172,725.9586499999998,0,0,0,0,1,50,0,1043,1047.10741,58.0,0,498.95873
173,1047.10741,0,0,0,1,0,78,0,1044,567.9504300000001,94.0,0,622.9752299999999
174,567.9504300000001,0,1,0,0,0,91,0,1045,430.26447000000013,123.0,0,648.29756
175,430.26447000000013,0,0,1,0,0,84,0,1046,843.3223,102.0,0,534.15707
176,843.3223,0,0,0,0,0,73,1,1047,753.0247899999998,113.0,0,630.5041600000002
177,753.0247899999998,1,0,0,0,0,62,0,1048,1328.7767900000001,120.0,0,670.1488
178,1328.7767900000001,0,0,0,0,0,58,0,1049,751.08263,101.0,1,479.97524000000004
179,751.08263,0,0,0,0,1,55,0,1050,982.27266,101.0,0,435.03309000000013
180,982.27266,0,0,0,1,0,49,0,1051,687.4793099999999,67.0,0,603.0496099999999
181,687.4793099999999,0,1,0,0,0,65,0,1052,1188.4959199999998,89.0,0,469.79340000000013
182,1188.4959199999998,0,0,1,0,0,66,0,1053,1008.61154,121.0,0,711.45456
183,1008.61154,0,0,0,0,0,61,1,1054,949.3966599999997,98.0,0,575.7851799999999
184,949.3966599999997,1,0,0,0,0,71,0,1055,800.8181699999997,73.0,0,451.23969
185,800.8181699999997,0,0,0,0,0,65,0,1056,552.1900800000002,123.0,1,959.12405
186,552.1900800000002,0,0,0,0,1,49,0,1057,719.7602999999998,125.0,0,689.9257
187,719.7602999999998,0,0,0,1,0,53,0,1058,695.7189800000001,79.0,0,516.1570499999998
188,695.7189800000001,0,1,0,0,0,58,0,1059,831.3140199999998,82.0,0,285.82645
189,831.3140199999998,0,0,1,0,0,79,0,1060,697.5371599999999,78.0,0,641.97525
190,697.5371599999999,0,0,0,0,0,50,1,1061,742.80989,88.0,0,525.6694600000002
191,742.80989,1,0,0,0,0,81,0,1062,513.1074199999998,91.0,0,506.73559999999986
192,513.1074199999998,0,0,0,0,0,64,0,1063,470.02477000000016,101.0,1,558.0165599999998
193,470.02477000000016,0,0,0,0,1,61,0,1064,856.7520399999999,99.0,0,521.8430099999998
194,856.7520399999999,0,0,0,1,0,58,0,1065,681.6528800000002,39.0,0,327.9587
195,681.6528800000002,0,1,0,0,0,43,0,1066,985.9668999999997,43.0,0,306.57027
16 changes: 16 additions & 0 deletions pyearth/test/pathological_data/issue_195.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Unpruned Earth Model
-------------------------------------
Basis Function Pruned Coefficient
-------------------------------------
(Intercept) No 854.422
x6 No 4.32647
x10 No 1.11089
x7 No -86.8824
x8 No -0.687854
x11 No 20.9724
x9 No -0.00349966
x0 No 0.0756107
x4 No -44.481
x5 No -13.4003
-------------------------------------
MSE: 19925.1443, GCV: 25723.8175, RSQ: 0.6889, GRSQ: 0.6025
6 changes: 5 additions & 1 deletion pyearth/test/pathological_data/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ This data set exposed a bug that occurred when using the sample_weight parameter
was that the apply methods of the BasisFunctions were not applying the weights, and the
next_pair method of the ForwardPasser class assumed they were. Now next_pair applies the
weights after calling apply. The same data set exposed issue 51, in which user-specified
endspans were not used. This test case covers both issues.
endspans were not used. This test case covers both issues.

issue_195:
This data set exposed a bug when you do not use pruning and only linear variables. In the
forward pass a variable could be added more than once. This data set covers this issue.
79 changes: 49 additions & 30 deletions pyearth/test/test_earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,15 @@ def test_smooth():
def test_linvars():
earth = Earth(**default_params)
earth.fit(X, y, linvars=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
res = str(earth.rsq_)
filename = os.path.join(os.path.dirname(__file__),
'earth_linvars_regress.txt')
res = earth.rsq_
filename = os.path.join(os.path.dirname(__file__), "earth_linvars_regress.txt")
if regenerate_target_files:
with open(filename, 'w') as fl:
with open(filename, "w") as fl:
fl.write(res)
with open(filename, 'r') as fl:
prev = fl.read()
with open(filename, "r") as fl:
prev = float(fl.read())

assert_equal(res, prev)
assert_almost_equal(res, prev, places=7)


def test_linvars_coefs():
Expand Down Expand Up @@ -249,32 +248,52 @@ def test_score():
@if_pandas
@if_environ_has('test_pathological_cases')
def test_pathological_cases():
import pandas
import pandas as pd

directory = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'pathological_data')
cases = {'issue_44': {},
'issue_50': {'penalty': 0.5,
'minspan': 1,
'allow_linear': False,
'endspan': 1,
'check_every': 1,
'sample_weight': 'issue_50_weight.csv'}}
for case, settings in cases.iteritems():
data = pandas.read_csv(os.path.join(directory, case + '.csv'))
y = data['y']
del data['y']
X = data
if 'sample_weight' in settings:
filename = os.path.join(directory, settings['sample_weight'])
sample_weight = pandas.read_csv(filename)['sample_weight']
del settings['sample_weight']
os.path.dirname(os.path.abspath(__file__)), "pathological_data"
)
cases = {
"issue_44": {},
"issue_50": {
"penalty": 0.5,
"minspan": 1,
"allow_linear": False,
"endspan": 1,
"check_every": 1,
"sample_weight": "issue_50_weight.csv",
},
"issue_195": {
"allow_linear": True,
"minspan": 7,
"endspan": 7,
"max_degree": 1,
"thresh": 0.001,
"enable_pruning": False,
"max_terms": 30,
"linvars": True,
},
}
for case, settings in cases.items():
data = pd.read_csv(os.path.join(directory, case + ".csv"), index_col=0)
y = data["y"]
X = data.drop("y", axis=1)
if "sample_weight" in settings:
filename = os.path.join(directory, settings["sample_weight"])
sample_weight = pd.read_csv(filename)["sample_weight"]
del settings["sample_weight"]
else:
sample_weight = None
model = Earth(**settings)
model.fit(X, y, sample_weight=sample_weight)
with open(os.path.join(directory, case + '.txt'), 'r') as infile:
correct = infile.read()
assert_equal(model.summary(), correct)
if "linvars" in settings:
del settings["linvars"]
model = Earth(**settings)
model.fit(X, y, sample_weight=sample_weight, linvars=X.columns)
else:
model = Earth(**settings)
model.fit(X, y, sample_weight=sample_weight)
with open(os.path.join(directory, case + ".txt"), "r") as infile:
correct_summary = infile.read()
assert_equal(model.summary(), correct_summary)


@if_pandas
Expand Down

0 comments on commit ec06b62

Please sign in to comment.