SoftmaxRegressor.fromJson constructor
SoftmaxRegressor.fromJson(
- String json
Restores previously fitted classifier instance from the json
import 'dart:io';
import 'package:ml_dataframe/ml_dataframe.dart';
final data = <Iterable>[
['feature 1', 'feature 2', 'feature 3', 'outcome 1', 'outcome 2']
[ 5.0, 7.0, 6.0, 1.0, 0.0],
[ 1.0, 2.0, 3.0, 0.0, 1.0],
[ 10.0, 12.0, 31.0, 0.0, 1.0],
[ 9.0, 8.0, 5.0, 0.0, 1.0],
[ 4.0, 0.0, 1.0, 1.0, 0.0],
];
final targetNames = ['outcome 1', 'outcome 2'];
final samples = DataFrame(data, headerExists: true);
final classifier = SoftmaxRegressor(
samples,
targetNames,
iterationsLimit: 2,
initialLearningRate: 1.0,
batchSize: 5,
fitIntercept: true,
interceptScale: 3.0,
);
final pathToFile = './classifier.json';
await classifier.saveAsJson(pathToFile);
final file = File(pathToFile);
final json = await file.readAsString();
final restoredClassifier = SoftmaxRegressor.fromJson(json);
// here you can use previously fitted restored classifier to make
// some prediction, e.g. via `restoredClassifier.predict(...)`;
Implementation
factory SoftmaxRegressor.fromJson(String json) => initSoftmaxRegressorModule()
.get<SoftmaxRegressorFactory>()
.fromJson(json);