You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there a way to provide customized metrics to .fit function?
import pandas as pd
from sklearn import datasets
from openTSNE import TSNE
from scipy.spatial.distance import euclidean
import numpy as np
import matplotlib.pyplot as plt
# a. use the iris dataset
iris = datasets.load_iris()
x, y = iris["data"], iris["target"]
year = np.arange(x.shape[0]).reshape(-1, 1)
data_with_time = np.hstack([x, year])
# b. use my dataset
# embeddings = np.load("asdf.npy")
# metadata = pd.read_csv("asdf.tsv", sep="\t")
# year = metadata['year'].values.reshape(-1, 1)
# data_with_time = np.hstack([embeddings, year])
def custom_metric(v1, v2):
feature_dist = euclidean(v1[:-1], v2[:-1]) # non-time dis
time_dist = abs(v1[-1] - v2[-1]) # time dis
return feature_dist + time_dist
embedding = TSNE(
metric=custom_metric,
perplexity=30,
n_iter=500,
random_state=42
).fit(data_with_time)
this script seems to be work with sklearn's iris dataset but after switching to my dataset, it says error
File "anaconda3/envs/tsne/lib/python3.10/site-packages/openTSNE/nearest_neighbors.py", line 247, in build
self.index = AnnoyIndex(data.shape[1], annoy_metric)
TypeError: argument 2 must be str, not function
The text was updated successfully, but these errors were encountered:
I think it is possible to use custom metric with PyNNDescent, but you will probably need to do it outside of openTSNE, and then pass the kNN graph into openTSNE as PrecomputedNeighbors.
is there a way to provide customized metrics to .fit function?
this script seems to be work with sklearn's iris dataset but after switching to my dataset, it says error
The text was updated successfully, but these errors were encountered: