Alexandre Daltro
2018-11-08 03:52:42 UTC
Hello, I am having some trouble to run a simple code for a multiple linear
regression.
the code is the following:
import statsmodels.formula.api as sm
regressor_OLS = sm.OLS(endog=y, exog=X_opt).fit()
y and X_opt are numpy arrays.
y ---> array([192261.83, 191792.06, 191050.39, 182901.99, 166187.94,
156991.12,
156122.51, 155752.6 , 152211.77, 149759.96, 146121.95, 144259.4 ,
141585.52, 134307.35, 132602.65, 129917.04, 126992.93, 125370.37,
124266.9 , 122776.86, 118474.03, 111313.02, 110352.25, 108733.99,
108552.04, 107404.34, 105733.54, 105008.31, 103282.38, 101004.64,
99937.59, 97483.56, 97427.84, 96778.92, 96712.8 , 96479.51,
90708.19, 89949.14, 81229.06, 81005.76, 78239.91, 77798.83,
71498.49, 69758.98, 65200.33, 64926.08, 49490.75, 42559.73,
35673.41, 14681.4 ])
X_opt ---> array([[1, 0.0, 1.0, 165349.2, 136897.8, 471784.1],
[1, 0.0, 0.0, 162597.7, 151377.59, 443898.53],
[1, 1.0, 0.0, 153441.51, 101145.55, 407934.54],
[1, 0.0, 1.0, 144372.41, 118671.85, 383199.62],
[1, 1.0, 0.0, 142107.34, 91391.77, 366168.42],
[1, 0.0, 1.0, 131876.9, 99814.71, 362861.36],
[1, 0.0, 0.0, 134615.46, 147198.87, 127716.82],
[1, 1.0, 0.0, 130298.13, 145530.06, 323876.68],
[1, 0.0, 1.0, 120542.52, 148718.95, 311613.29],
[1, 0.0, 0.0, 123334.88, 108679.17, 304981.62],
[1, 1.0, 0.0, 101913.08, 110594.11, 229160.95],
[1, 0.0, 0.0, 100671.96, 91790.61, 249744.55],
[1, 1.0, 0.0, 93863.75, 127320.38, 249839.44],
[1, 0.0, 0.0, 91992.39, 135495.07, 252664.93],
[1, 1.0, 0.0, 119943.24, 156547.42, 256512.92],
[1, 0.0, 1.0, 114523.61, 122616.84, 261776.23],
[1, 0.0, 0.0, 78013.11, 121597.55, 264346.06],
[1, 0.0, 1.0, 94657.16, 145077.58, 282574.31],
[1, 1.0, 0.0, 91749.16, 114175.79, 294919.57],
[1, 0.0, 1.0, 86419.7, 153514.11, 0.0],
[1, 0.0, 0.0, 76253.86, 113867.3, 298664.47],
[1, 0.0, 1.0, 78389.47, 153773.43, 299737.29],
[1, 1.0, 0.0, 73994.56, 122782.75, 303319.26],
[1, 1.0, 0.0, 67532.53, 105751.03, 304768.73],
[1, 0.0, 1.0, 77044.01, 99281.34, 140574.81],
[1, 0.0, 0.0, 64664.71, 139553.16, 137962.62],
[1, 1.0, 0.0, 75328.87, 144135.98, 134050.07],
[1, 0.0, 1.0, 72107.6, 127864.55, 353183.81],
[1, 1.0, 0.0, 66051.52, 182645.56, 118148.2],
[1, 0.0, 1.0, 65605.48, 153032.06, 107138.38],
[1, 1.0, 0.0, 61994.48, 115641.28, 91131.24],
[1, 0.0, 1.0, 61136.38, 152701.92, 88218.23],
[1, 0.0, 0.0, 63408.86, 129219.61, 46085.25],
[1, 1.0, 0.0, 55493.95, 103057.49, 214634.81],
[1, 0.0, 0.0, 46426.07, 157693.92, 210797.67],
[1, 0.0, 1.0, 46014.02, 85047.44, 205517.64],
[1, 1.0, 0.0, 28663.76, 127056.21, 201126.82],
[1, 0.0, 0.0, 44069.95, 51283.14, 197029.42],
[1, 0.0, 1.0, 20229.59, 65947.93, 185265.1],
[1, 0.0, 0.0, 38558.51, 82982.09, 174999.3],
[1, 0.0, 0.0, 28754.33, 118546.05, 172795.67],
[1, 1.0, 0.0, 27892.92, 84710.77, 164470.71],
[1, 0.0, 0.0, 23640.93, 96189.63, 148001.11],
[1, 0.0, 1.0, 15505.73, 127382.3, 35534.17],
[1, 0.0, 0.0, 22177.74, 154806.14, 28334.72],
[1, 0.0, 1.0, 1000.23, 124153.04, 1903.93],
[1, 1.0, 0.0, 1315.46, 115816.21, 297114.46],
[1, 0.0, 0.0, 0.0, 135426.92, 0.0],
[1, 0.0, 1.0, 542.05, 51743.15, 0.0],
[1, 0.0, 0.0, 0.0, 116983.8, 45173.06]]
I always get the error ufunc 'isfinite' not supported for the input types,
and the inputs could not be safely coerced to any supported types according
to the casting rule ''safe''. Does anyone know how to fix it? Thanks!
regression.
the code is the following:
import statsmodels.formula.api as sm
regressor_OLS = sm.OLS(endog=y, exog=X_opt).fit()
y and X_opt are numpy arrays.
y ---> array([192261.83, 191792.06, 191050.39, 182901.99, 166187.94,
156991.12,
156122.51, 155752.6 , 152211.77, 149759.96, 146121.95, 144259.4 ,
141585.52, 134307.35, 132602.65, 129917.04, 126992.93, 125370.37,
124266.9 , 122776.86, 118474.03, 111313.02, 110352.25, 108733.99,
108552.04, 107404.34, 105733.54, 105008.31, 103282.38, 101004.64,
99937.59, 97483.56, 97427.84, 96778.92, 96712.8 , 96479.51,
90708.19, 89949.14, 81229.06, 81005.76, 78239.91, 77798.83,
71498.49, 69758.98, 65200.33, 64926.08, 49490.75, 42559.73,
35673.41, 14681.4 ])
X_opt ---> array([[1, 0.0, 1.0, 165349.2, 136897.8, 471784.1],
[1, 0.0, 0.0, 162597.7, 151377.59, 443898.53],
[1, 1.0, 0.0, 153441.51, 101145.55, 407934.54],
[1, 0.0, 1.0, 144372.41, 118671.85, 383199.62],
[1, 1.0, 0.0, 142107.34, 91391.77, 366168.42],
[1, 0.0, 1.0, 131876.9, 99814.71, 362861.36],
[1, 0.0, 0.0, 134615.46, 147198.87, 127716.82],
[1, 1.0, 0.0, 130298.13, 145530.06, 323876.68],
[1, 0.0, 1.0, 120542.52, 148718.95, 311613.29],
[1, 0.0, 0.0, 123334.88, 108679.17, 304981.62],
[1, 1.0, 0.0, 101913.08, 110594.11, 229160.95],
[1, 0.0, 0.0, 100671.96, 91790.61, 249744.55],
[1, 1.0, 0.0, 93863.75, 127320.38, 249839.44],
[1, 0.0, 0.0, 91992.39, 135495.07, 252664.93],
[1, 1.0, 0.0, 119943.24, 156547.42, 256512.92],
[1, 0.0, 1.0, 114523.61, 122616.84, 261776.23],
[1, 0.0, 0.0, 78013.11, 121597.55, 264346.06],
[1, 0.0, 1.0, 94657.16, 145077.58, 282574.31],
[1, 1.0, 0.0, 91749.16, 114175.79, 294919.57],
[1, 0.0, 1.0, 86419.7, 153514.11, 0.0],
[1, 0.0, 0.0, 76253.86, 113867.3, 298664.47],
[1, 0.0, 1.0, 78389.47, 153773.43, 299737.29],
[1, 1.0, 0.0, 73994.56, 122782.75, 303319.26],
[1, 1.0, 0.0, 67532.53, 105751.03, 304768.73],
[1, 0.0, 1.0, 77044.01, 99281.34, 140574.81],
[1, 0.0, 0.0, 64664.71, 139553.16, 137962.62],
[1, 1.0, 0.0, 75328.87, 144135.98, 134050.07],
[1, 0.0, 1.0, 72107.6, 127864.55, 353183.81],
[1, 1.0, 0.0, 66051.52, 182645.56, 118148.2],
[1, 0.0, 1.0, 65605.48, 153032.06, 107138.38],
[1, 1.0, 0.0, 61994.48, 115641.28, 91131.24],
[1, 0.0, 1.0, 61136.38, 152701.92, 88218.23],
[1, 0.0, 0.0, 63408.86, 129219.61, 46085.25],
[1, 1.0, 0.0, 55493.95, 103057.49, 214634.81],
[1, 0.0, 0.0, 46426.07, 157693.92, 210797.67],
[1, 0.0, 1.0, 46014.02, 85047.44, 205517.64],
[1, 1.0, 0.0, 28663.76, 127056.21, 201126.82],
[1, 0.0, 0.0, 44069.95, 51283.14, 197029.42],
[1, 0.0, 1.0, 20229.59, 65947.93, 185265.1],
[1, 0.0, 0.0, 38558.51, 82982.09, 174999.3],
[1, 0.0, 0.0, 28754.33, 118546.05, 172795.67],
[1, 1.0, 0.0, 27892.92, 84710.77, 164470.71],
[1, 0.0, 0.0, 23640.93, 96189.63, 148001.11],
[1, 0.0, 1.0, 15505.73, 127382.3, 35534.17],
[1, 0.0, 0.0, 22177.74, 154806.14, 28334.72],
[1, 0.0, 1.0, 1000.23, 124153.04, 1903.93],
[1, 1.0, 0.0, 1315.46, 115816.21, 297114.46],
[1, 0.0, 0.0, 0.0, 135426.92, 0.0],
[1, 0.0, 1.0, 542.05, 51743.15, 0.0],
[1, 0.0, 0.0, 0.0, 116983.8, 45173.06]]
I always get the error ufunc 'isfinite' not supported for the input types,
and the inputs could not be safely coerced to any supported types according
to the casting rule ''safe''. Does anyone know how to fix it? Thanks!