GithubHelp home page GithubHelp logo

How to persist DTree? about ml_algo HOT 3 CLOSED

gyrdym avatar gyrdym commented on July 16, 2024
How to persist DTree?

from ml_algo.

Comments (3)

gyrdym avatar gyrdym commented on July 16, 2024

@mohas Hi, thank you for opening the issue, I will add the desired functionality to the classifier as soon as possible - it's one of the things that I planned to do first. Unfortunately, right now you can't save the trained model. Just keep tracking this issue, I'll write when the functionality is ready.

from ml_algo.

mohas avatar mohas commented on July 16, 2024

Coming from other programming languages I thought I could just binary serialize the dtree class itself, but apparently this is not easily doable in dart

from ml_algo.

gyrdym avatar gyrdym commented on July 16, 2024

@mohas sorry for such a big delay, finally I've added the desired functionality to DecisionTreeClassifier. You can use the following example as a guide:

final fakeDataSet = DataFrame.fromSeries([
  Series('col_1', <int>[10, 90, 23, 55]),
  Series('col_2', <int>[20, 51, 40, 10]),
  Series('col_3', <int>[1, 0, 0, 1], isDiscrete: true),
  Series('col_4', <int>[0, 0, 1, 0], isDiscrete: true),
  Series('col_5', <int>[0, 1, 0, 0], isDiscrete: true),
  Series('col_6', <int>[30, 34, 90, 22]),
  Series('col_7', <int>[40, 31, 50, 80]),
  Series('col_8', <int>[0, 0, 1, 2], isDiscrete: true),
]);

final targetName = 'col_8';

final classifier = DecisionTreeClassifier(fakeDataSet, targetName, minError: 0.3, minSamplesCount: 1, maxDepth: 3);
final testFileName = 'test/classifier/decision_tree_classifier/serialized_classifier.json';
await classifier.saveAsJson(testFileName);

And to restore the classifier:

final file = await File(testFileName);
final json = await file.readAsString();
final restoredClassifier = DecisionTreeClassifier.fromJson(json);

You may visit the appropriate unit test to see it in action.

from ml_algo.

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.