WillKoehrsen / feature-selector

Feature selector is a tool for dimensionality reduction of machine learning datasets
GNU General Public License v3.0
2.22k stars 770 forks source link

When using identify_collinear: too many indices for array: array is 1-dimensional, but 2 were indexed #63

Open Dongdong-cHU opened 2 weeks ago

Dongdong-cHU commented 2 weeks ago

too many indices for array: array is 1-dimensional, but 2 were indexed How can I solve this problems?

When I am using this code

fs.identify_collinear(correlation_threshold=0.8)
correlated_features = fs.ops['collinear']
correlated_features

it turns out to be:

IndexError Traceback (most recent call last) Cell In[107], line 1 ----> 1 fs.identify_collinear(correlation_threshold=0.8) 2 correlated_features = fs.ops['collinear'] 3 correlated_features

File ~/TMOF_ML/feature_selector.py:211, in FeatureSelector.identify_collinear(self, correlation_threshold, one_hot) 207 # Iterate through the columns to drop to record pairs of correlated features 208 for column in to_drop: 209 210 # Find the correlated features --> 211 corr_features = list(upper.index[upper[column].abs() > correlation_threshold]) 213 # Find the correlated values 214 corr_values = list(upper[column][upper[column].abs() > correlation_threshold])

File ~/.conda/envs/ML/lib/python3.8/site-packages/pandas/core/indexes/base.py:5196, in Index.getitem(self, key) 5193 else: 5194 key = np.asarray(key, dtype=bool) -> 5196 result = getitem(key) 5197 # Because we ruled out integer above, we always get an arraylike here 5198 if result.ndim > 1:

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed