How to fit UMAP object with an embedding_ property of shape (200,2)

103
March 27, 2022, at 8:40 PM

I'm trying to take the first 200 rows of my dataframe and pass it through a UMAP fit method but I'm not able to get it to shape the way I want at (200,2). Should I add an embedding parameter?

This is the code I have so far:

def example():
    feature_names = ['beer_name','review_appearance', 'review_aroma', 'review_palate', 'review_taste', 'review_overall']
    new_df = df[feature_names]
    final_df = new_df.groupby(['beer_name']).mean()
    scaler = StandardScaler()
    scaler.fit(final_df)
    results = scaler.transform(final_df)
    X_normalized_200 = results[0:200,:]
    umap_obj = umap.UMAP(set_op_mix_ratio=0.15, random_state = 0).fit(final_df)
    output=umap_obj
    
    return output

Snapshot of my dataframe:

Answer 1

You need to use the transform method after fitting UMAP in order to get the coordinates of each point in the embedding.

def example():
    feature_names = [
        "beer_name",
        "review_appearance",
        "review_aroma",
        "review_pallete",
        "review_taste",
        "review_overall",
    ]
    new_df = df[feature_names]
    final_df = new_df.groupby(["beer_name"]).mean()
    scaler = StandardScaler()
    scaler.fit(final_df)
    results = scaler.transform(final_df)
    X_normalized_200 = results[0:200, :]
    umap_obj = umap.UMAP(set_op_mix_ratio=0.15, random_state=0).fit(final_df)
    output = umap_obj.transform(X_normalized_200)  # missing this line
    return output
Rent Charter Buses Company
READ ALSO
Django - passing one model to another while creating new object

Django - passing one model to another while creating new object

My site has multiple tests with multiple questions eachI'd like to make question creation form which will have preset test object depended on url

106
Import could not be resolve after installing the dependency

Import could not be resolve after installing the dependency

I'm trying to install de messagebird dependency into my python project

171
With cartopy, can a local map be rotated so that north points in an arbitrary direction?

With cartopy, can a local map be rotated so that north points in an arbitrary direction?

I have this block of python code to plot a city-scale satellite map

144
python - convert curl command

python - convert curl command

I have this curl command

147