Open 1098994933 opened 1 day ago
another error with df_train.reset_index(drop=True,inplace=True) added to the code above
_LinAlgError Traceback (most recent call last) Cell In[91], line 11 9 operators = ['+','-','*','/','exp','ln','sin','pow(2)'] 10 sm = SissoModel(data=df_train,operators=operators,usegpu=True) ---> 11 rmse, equation, r2, = sm.fit()
File /opt/conda/lib/python3.10/site-packages/TorchSisso/model.py:138, in SissoModel.fit(self) 134 x,y,names = fc.feature_space_construction(self.operators,self.df,self.no_of_operators,self.device,self.initial_screening,self.custom_unary_functions,self.custom_binary_functions).feature_space() 136 from .Regressor import Regressor --> 138 rmse, equation,r2,final_eq = Regressor(x,y,names,self.dimension,self.sis_features,self.device,self.use_gpu).regressor_fit() 140 return rmse, equation, r2,final_eq 142 else:
File /opt/conda/lib/python3.10/site-packages/TorchSisso/Regressor.py:301, in Regressor.regressor_fit(self) 297 else: 299 start = time.time() --> 301 rmse,terms,intercept,coefs,r2 = self.higher_dimension(i) 303 equation ='' 305 for k in range(len(terms)):
File /opt/conda/lib/python3.10/site-packages/TorchSisso/Regressor.py:137, in Regressor.higher_dimension(self, iteration) 132 comb_tensor = self.x_standardized.T[combinations_generated.tolist(),:] 134 x_p = combtensor.permute(0,2,1) --> 137 sol, , , = torch.linalg.lstsq(x_p, y_centered_clone) 139 predicted = torch.matmul(x_p,sol) 141 residuals = y_centered_clone - predicted
_LinAlgError: torch.linalg.lstsq: (Batch element 37): The least squares solution could not be computed because the input matrix does not have full rank (error code: 2).
if I do not reset the index of df_train by df_train.reset_index(drop=True,inplace=True) raise error
code: `X = np.array([2i for i in range(100)],dtype=float) y = np.array([(0.35x+1)**2 for x in X],dtype=float)
create dataframe composed of targets "y" and primary features "X"
data = np.column_stack((y, X)) df = pd.DataFrame(data,columns=["Target","F1"]) from sklearn.model_selection import train_test_split df_train, df_test = train_test_split(df,test_size=0.2) print(df_train.shape) print(df_test.shape) from TorchSisso import SissoModel import numpy as np import pandas as pd import sympy from sympy import symbols
define unary and binary operators of interest
operators = ['+','-','*','/','exp','ln','sin','pow(2)'] sm = SissoModel(data=df_train,operators=operators,usegpu=True) rmse, equation, r2, = sm.fit()`
KeyError Traceback (most recent call last) File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key) 3804 try: -> 3805 return self._engine.get_loc(casted_key) 3806 except KeyError as err:
File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:2606, in pandas._libs.hashtable.Int64HashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:2630, in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: 13
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last) Cell In[89], line 11 9 operators = ['+','-','*','/','exp','ln','sin','pow(2)'] 10 sm = SissoModel(data=df_train,operators=operators,usegpu=True) ---> 11 rmse, equation, r2, = sm.fit()
File /opt/conda/lib/python3.10/site-packages/TorchSisso/model.py:134, in SissoModel.fit(self) 129 else: continue 132 else: --> 134 x,y,names = fc.feature_space_construction(self.operators,self.df,self.no_of_operators,self.device,self.initial_screening,self.custom_unary_functions,self.custom_binary_functions).feature_space() 136 from .Regressor import Regressor 138 rmse, equation,r2,final_eq = Regressor(x,y,names,self.dimension,self.sis_features,self.device,self.use_gpu).regressor_fit()
File /opt/conda/lib/python3.10/site-packages/TorchSisso/FeatureSpaceConstruction.py:72, in feature_space_construction.init(self, operators, df, no_of_operators, device, initial_screening, custom_unary_functions, custom_binary_functions) 69 # Pop out the Targer variable of the problem and convert to tensor 70 self.df.rename(columns = {f'{self.df.columns[0]}':'Target'},inplace=True) ---> 72 self.Target_column = torch.tensor(self.df.pop('Target')).to(self.device) 75 if initial_screening != None: 77 self.screening = initial_screening[0]
File /opt/conda/lib/python3.10/site-packages/pandas/core/series.py:1121, in Series.getitem(self, key) 1118 return self._values[key] 1120 elif key_is_scalar: -> 1121 return self._get_value(key) 1123 # Convert generator to list before going through hashable part 1124 # (We will iterate through the generator there to check for slices) 1125 if is_iterator(key):
File /opt/conda/lib/python3.10/site-packages/pandas/core/series.py:1237, in Series._get_value(self, label, takeable) 1234 return self._values[label] 1236 # Similar to Index.get_value, but we do not fall back to positional -> 1237 loc = self.index.get_loc(label) 1239 if is_integer(loc): 1240 return self._values[loc]
File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key) 3807 if isinstance(casted_key, slice) or ( 3808 isinstance(casted_key, abc.Iterable) 3809 and any(isinstance(x, slice) for x in casted_key) 3810 ): 3811 raise InvalidIndexError(key) -> 3812 raise KeyError(key) from err 3813 except TypeError: 3814 # If we have a listlike key, _check_indexing_error will raise 3815 # InvalidIndexError. Otherwise we fall through and re-raise 3816 # the TypeError. 3817 self._check_indexing_error(key)
KeyError: 13