GithubHelp home page GithubHelp logo

Comments (2)

lmcinnes avatar lmcinnes commented on June 2, 2024

Thanks, I'll try to look into this when I get a chance.

from pynndescent.

j-adamczyk avatar j-adamczyk commented on June 2, 2024

The dataset used was Codon Usage. Interestingly enough, it has only nonnegative values (codon percentages), so regular cosine is always nonnegative as well. Exact code:

import pandas as pd
from pynndescent import PyNNDescentTransformer
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from pynndescent import PyNNDescentTransformer
from sklearn.pipeline import make_pipeline

df = pd.read_csv("codon_usage.csv")
df = df[pd.to_numeric(df["UUU"], errors="coerce").notnull()].copy()
df = df.copy()  # to avoid irritating SettingWithCopyWarning
df["UUU"] = df.loc[:, "UUU"].astype(float)
df["UUC"] = df.loc[:, "UUC"].astype(float)
df = df.loc[df["Ncodons"] >= 1000, :]
df = df.loc[df["Kingdom"] != "plm", :]
df = df.drop(["DNAtype", "SpeciesID", "Ncodons", "SpeciesName"], axis="columns")
kingdom_mapping = {
    "arc": 0,
    "bct": 1,
    "pln": 2,
    "inv": 2,
    "vrt": 2,
    "mam": 2,
    "rod": 2,
    "pri": 2,
    "phg": 3,
    "vrl": 4,
}
df = df.replace({"Kingdom": kingdom_mapping})
y = df.pop("Kingdom")


X_train, X_test, y_train, y_test = train_test_split(
    df, y, test_size=0.2, random_state=0, stratify=y
)

sklearn_knn = KNeighborsClassifier(metric="cosine")

pynndescent_ann = make_pipeline(
    PyNNDescentTransformer(metric="cosine", random_state=0),
    KNeighborsClassifier(metric="precomputed"),
)

sklearn_knn.fit(X_train, y_train)
pynndescent_ann.fit(X_train, y_train)

from pynndescent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.