Open itsamejoshab opened 3 years ago
Yes, I have the same issue. It's because of the if statement on line 169 here https://github.com/Sundar0989/XuniVerse/blob/master/xverse/transformer/_binning.py .
Should be firstly assigned...
I m having similar issues. If there is a fix, please share.
Passing y as numpy array fixed it for me... y = df['target_varible'].to_numpy()
This has worked for me: y_train.T.squeeze()
you can check the issue here https://github.com/Sundar0989/XuniVerse/issues/3
I had similar issue. However after trying above solutions, I'm getting a new error -
AttributeError Traceback (most recent call last) Input In [11], in <cell line: 2>() 1 clf = MonotonicBinning() ----> 2 clf.fit(X,y)
File ~\Anaconda3\lib\site-packages\xverse\transformer_binning.py:122, in MonotonicBinning.fit(self, X, y) 118 raise ValueError("The input feature(s) should be numeric type. Some of the input features \ 119 has character values in it. Please use a encoder before performing monotonic operations.") 121 #apply the monotonic train function on dataset --> 122 fit_X.apply(lambda x: self.train(x, y), axis=0) 123 return self
File ~\Anaconda3\lib\site-packages\pandas\core\frame.py:8833, in DataFrame.apply(self, func, axis, raw, result_type, args, **kwargs) 8822 from pandas.core.apply import frame_apply 8824 op = frame_apply( 8825 self, 8826 func=func, (...) 8831 kwargs=kwargs, 8832 ) -> 8833 return op.apply().finalize(self, method="apply")
File ~\Anaconda3\lib\site-packages\pandas\core\apply.py:727, in FrameApply.apply(self) 724 elif self.raw: 725 return self.apply_raw() --> 727 return self.apply_standard()
File ~\Anaconda3\lib\site-packages\pandas\core\apply.py:851, in FrameApply.apply_standard(self) 850 def apply_standard(self): --> 851 results, res_index = self.apply_series_generator() 853 # wrap results 854 return self.wrap_results(results, res_index)
File ~\Anaconda3\lib\site-packages\pandas\core\apply.py:867, in FrameApply.apply_series_generator(self) 864 with option_context("mode.chained_assignment", None): 865 for i, v in enumerate(series_gen): 866 # ignore SettingWithCopy here in case the user mutates --> 867 results[i] = self.f(v) 868 if isinstance(results[i], ABCSeries): 869 # If we have a view on v, we need to make a copy because 870 # series_generator will swap out the underlying data 871 results[i] = results[i].copy(deep=False)
File ~\Anaconda3\lib\site-packages\xverse\transformer_binning.py:122, in MonotonicBinning.fit.
File ~\Anaconda3\lib\site-packages\xverse\transformer_binning.py:170, in MonotonicBinning.train(self, X, y) 165 """ 166 Execute this block when monotonic relationship is not identified by spearman technique. 167 We still want our code to produce bins. 168 """ 169 if len(bins_X_grouped) == 1: --> 170 bins = algos.quantile(X, np.linspace(0, 1, force_bins)) #creates a new binnning based on forced bins 171 if len(np.unique(bins)) == 2: 172 bins = np.insert(bins, 0, 1)
AttributeError: module 'pandas.core.algorithms' has no attribute 'quantile
This solution worked for me
for the solution: y = df['target_varible'].to_numpy() the shape of the y is (row_number, 1)
whereas for the solution y = y_train.T.squeeze() the shape of the y is (row_number, )
it seems y as vector works.
I can work around this problem by passing the entire dataframe in... along w/ the y, but I'm not sure if this is expected behavior. X implies passing dataframe without y included.
UnboundLocalError: local variable 'bins_X_grouped' referenced before assignment
df = pd.DataFrame({'x1': list(range(100)), 'x2': list(range(100)), 'x3': list(range(100)), 'y': list(range(100))})
df['y'] = np.where(df['x1']>50,1,0)
from xverse.transformer import MonotonicBinning clf = MonotonicBinning()
X = df[['x1','x2','x3']] y = df[['y']]
if not isinstance(X, pd.DataFrame): print("Not a dataframe") else: print("Is a DataFrame")
clf.fit(X, y)
UnboundLocalError Traceback (most recent call last)