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