1
import umap as UMAP

import umap


retarget = {df_train['target'].value_counts().reset_index()['index'][i]: i for i in range(len(df_train['target'].value_counts()))}
retarget2 = {i: k for k, i in retarget.items()}
df_train['target'] = df_train['target'].map(retarget)

umap = umap(n_components = 2, n_neighbors = 10, min_dist = 0.99).fit_transform(df_train.drop('target', axis = 1).sample(15000, random_state = 228), df_train['target'].sample(15000, random_state = 228))

I am trying to use UMAP for visualization but it is keep on giving me error:

TypeError                                 Traceback (most recent call last)
<ipython-input-15-bb51a04f463b> in <module>
      8 df_train['target'] = df_train['target'].map(retarget)
      9 
---> 10 umap = umap(n_components = 2, n_neighbors = 10, min_dist = 0.99).fit_transform(df_train.drop('target', axis = 1).sample(15000, random_state = 228), df_train['target'].sample(15000, random_state = 228))
     11 
     12 plt.figure(figsize=(15, 12))

TypeError: 'module' object is not callable

I have umap installed in my system:

(base) C:\Users\bakumari\Anaconda3\Lib\site-packages>pip install umap
Collecting umap
  Using cached umap-0.1.1-py3-none-any.whl
Installing collected packages: umap
Successfully installed umap-0.1.1

I am trying to use umap for visualization purpose.

Babita
  • 39
  • 5
  • I have never used this module before, but the issue in your code is that `umap` is a module. You are directly using that module as a function, and that obviously will not work. – Gautam Chettiar Nov 18 '22 at 17:13

1 Answers1

2

You need to install umap-learn

pip uninstall umap
pip install umap-learn

and then

import umap
umap = umap.UMAP(n_components = 2, n_neighbors = 10, min_dist = 0.99).fit_transform(df_train.drop('target', axis = 1).sample(15000, random_state = 228), df_train['target'].sample(15000, random_state = 228))
Gautam Chettiar
  • 449
  • 2
  • 11
  • I did follow the steps but now I am getting a new error: – Babita Nov 18 '22 at 17:18
  • TypeError Traceback (most recent call last) in 6 df_train['target'] = df_train['target'].map(retarget) 7 ----> 8 umap = umap(n_components = 2, n_neighbors = 10, min_dist = 0.99).fit_transform(df_train.drop('target', axis = 1).sample(15000, random_state = 228), df_train['target'].sample(15000, random_state = 228)) 9 10 plt.figure(figsize=(15, 12)) TypeError: 'module' object is not callable – Babita Nov 18 '22 at 17:19
  • I have edited it, check now – Gautam Chettiar Nov 18 '22 at 17:22
  • pip uninstall umap pip install umap-learn These 2 commands completed successfully – Babita Nov 18 '22 at 17:23
  • Change your last line and remove the first line – Gautam Chettiar Nov 18 '22 at 17:23
  • Thank you for your support, now I can plot the map using this module. – Babita Nov 18 '22 at 17:29