Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to a class #12

Open
targos opened this issue Aug 12, 2018 · 4 comments
Open

Refactor to a class #12

targos opened this issue Aug 12, 2018 · 4 comments

Comments

@targos
Copy link
Member

targos commented Aug 12, 2018

I'd like to refactor the library to a class, with an API similar to sklearn: http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html

I'll migrate to TypeScript at the same time.

@mljs/collaborators WDYT?

@maasencioh
Copy link
Member

why TypeScript? I think that the class is not a bad idea, do you see any advantage doing this?

@stropitek
Copy link
Member

stropitek commented Aug 13, 2018

I think that's a very good idea. People will be familiar with the API. I think most people doing ML have worked with python and scikit before.

@maasencioh we've been experimenting with Typescript and it's awesome.

  • Auto-completion and documentation as you code, really useful for ML where you often see have complex types
  • Fix typos and type errors before even running the program
  • Thinking with types in mind helps you to design a better API IMHO
  • It's still just js at the end
  • We often have a build step anyway (for example to support es6 modules)
  • People have already expressed their desire to see MLJS in typescript

@jobo322
Copy link
Member

jobo322 commented Aug 13, 2018

Syntax is like Java, for reading the code maybe it's better, you need to write more code for the same result but personally I like the comments functionality for the argument types

@lpatiny
Copy link
Member

lpatiny commented Oct 9, 2020

Migrating to a class would be great indeed but I would prefer to have something similar to pca, pls and other packages

const kMeans = new KMeans(dataset, options); (or new KMeans(dataset, numberClusters, options))

const newPoints = [[4.9, 3.2, 1.2, 0.4], [5.4, 3.3, 1.4, 0.9]];
console.log(kMeans.predict(newPoints)); // project new points into the PCA space

const model2 = kMeans.toJSON(); // to save the model

const kMeans2 = KMeans.load(model);
kMeans2.predict(newPoints);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants