Advertisement
Guest User

vif error

a guest
May 20th, 2024
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.31 KB | Source Code | 0 0
  1. ---------------------------------------------------------------------------
  2. TypeError                                 Traceback (most recent call last)
  3. Cell In[58], line 6
  4.       4 vif=pd.DataFrame()
  5.       5 vif["feature"]=df.columns
  6. ----> 6 vif["value"]=[variance_inflation_factor(df.values,i) for i in range(len(df.columns))]
  7.  
  8. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\stats\outliers_influence.py:196, in variance_inflation_factor(exog, exog_idx)
  9.     194 mask = np.arange(k_vars) != exog_idx
  10.     195 x_noti = exog[:, mask]
  11. --> 196 r_squared_i = OLS(x_i, x_noti).fit().rsquared
  12.     197 vif = 1. / (1. - r_squared_i)
  13.     198 return vif
  14.  
  15. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\regression\linear_model.py:924, in OLS.__init__(self, endog, exog, missing, hasconst, **kwargs)
  16.     921     msg = ("Weights are not supported in OLS and will be ignored"
  17.     922            "An exception will be raised in the next version.")
  18.     923     warnings.warn(msg, ValueWarning)
  19. --> 924 super().__init__(endog, exog, missing=missing,
  20.     925                           hasconst=hasconst, **kwargs)
  21.     926 if "weights" in self._init_keys:
  22.     927     self._init_keys.remove("weights")
  23.  
  24. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\regression\linear_model.py:749, in WLS.__init__(self, endog, exog, weights, missing, hasconst, **kwargs)
  25.     747 else:
  26.     748     weights = weights.squeeze()
  27. --> 749 super().__init__(endog, exog, missing=missing,
  28.     750                           weights=weights, hasconst=hasconst, **kwargs)
  29.     751 nobs = self.exog.shape[0]
  30.     752 weights = self.weights
  31.  
  32. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\regression\linear_model.py:203, in RegressionModel.__init__(self, endog, exog, **kwargs)
  33.     202 def __init__(self, endog, exog, **kwargs):
  34. --> 203     super().__init__(endog, exog, **kwargs)
  35.     204     self.pinv_wexog: Float64Array | None = None
  36.     205     self._data_attr.extend(['pinv_wexog', 'wendog', 'wexog', 'weights'])
  37.  
  38. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\base\model.py:270, in LikelihoodModel.__init__(self, endog, exog, **kwargs)
  39.     269 def __init__(self, endog, exog=None, **kwargs):
  40. --> 270     super().__init__(endog, exog, **kwargs)
  41.     271     self.initialize()
  42.  
  43. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\base\model.py:95, in Model.__init__(self, endog, exog, **kwargs)
  44.      93 missing = kwargs.pop('missing', 'none')
  45.      94 hasconst = kwargs.pop('hasconst', None)
  46. ---> 95 self.data = self._handle_data(endog, exog, missing, hasconst,
  47.      96                               **kwargs)
  48.      97 self.k_constant = self.data.k_constant
  49.      98 self.exog = self.data.exog
  50.  
  51. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\base\model.py:135, in Model._handle_data(self, endog, exog, missing, hasconst, **kwargs)
  52.     134 def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
  53. --> 135     data = handle_data(endog, exog, missing, hasconst, **kwargs)
  54.     136     # kwargs arrays could have changed, easier to just attach here
  55.     137     for key in kwargs:
  56.  
  57. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\base\data.py:675, in handle_data(endog, exog, missing, hasconst, **kwargs)
  58.     672     exog = np.asarray(exog)
  59.     674 klass = handle_data_class_factory(endog, exog)
  60. --> 675 return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
  61.     676              **kwargs)
  62.  
  63. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\base\data.py:88, in ModelData.__init__(self, endog, exog, missing, hasconst, **kwargs)
  64.      86 self.const_idx = None
  65.      87 self.k_constant = 0
  66. ---> 88 self._handle_constant(hasconst)
  67.      89 self._check_integrity()
  68.      90 self._cache = {}
  69.  
  70. File ~\AppData\Roaming\Python\Python312\site-packages\statsmodels\base\data.py:133, in ModelData._handle_constant(self, hasconst)
  71.     131 check_implicit = False
  72.     132 exog_max = np.max(self.exog, axis=0)
  73. --> 133 if not np.isfinite(exog_max).all():
  74.     134     raise MissingDataError('exog contains inf or nans')
  75.     135 exog_min = np.min(self.exog, axis=0)
  76.  
  77. TypeError: 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''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement