Skip to content

Commit

Permalink
Merge 9c2b857 into fdd747b
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Jun 24, 2020
2 parents fdd747b + 9c2b857 commit 1a2a702
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

## 14.2.1
- `README`: Examples on prediction and collecting learning data added

## 14.2.0
- `SoftmaxRegressor`:
- `Default constructor`: `collectLearningData` parameter added
Expand Down
37 changes: 35 additions & 2 deletions README.md
Expand Up @@ -134,6 +134,20 @@ iteration
full-batch gradient ascent, that's why we used `trainSamples.rows.length` here - the total amount of data.
- `probabilityThreshold` - lower bound for positive label probability

If we want to evaluate the learning process more thoroughly, we may pass `collectLearningData` argument to the classifier
constructor:

```dart
final createClassifier = (DataFrame samples, _) =>
LogisticRegressor(
...,
collectLearningData: true,
);
```

This argument activates collecting costs per each optimization iteration, and you can see the cost values after model
creation.

Assume, we chose good hyperprameters which can lead to a high-performant model. In order to validate our hypothesis let's
use CrossValidator instance created before:

Expand Down Expand Up @@ -173,21 +187,40 @@ The final score is like:
print(finalScore.toStringAsFixed(2)); // approx. 0.75
```

If we specified `collectLearningData` parameter, we may see costs per each iteration in order to evaluate how our cost
changed from iteration to iteration during the learning process:

```dart
print(classifier.costPerIteration);
```

Seems, our model has a good generalization ability, and that means we may use it in the future.
To do so we may store the model to file as JSON:
To do so we may store the model to a file as JSON:

```dart
await classifier.saveAsJson('diabetes_classifier.json');
```

After that we can simply read the model from the file:
After that we can simply read the model from the file and make predictions:

```dart
import 'dart:io';
final file = File(fileName);
final encodedData = await file.readAsString();
final classifier = LogisticRegressor.fromJson(encodedData);
final unlabelledData = await fromCsv('some_unlabelled_data.csv');
final prediction = classifier.predict(unlabelledData);
print(prediction.header); // ('class variable (0 or 1)')
print(prediction.rows); // [
// (1),
// (0),
// (0),
// (1),
// ...,
// (1),
// ]
```

All the code above all together:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: ml_algo
description: Machine learning algorithms, Machine learning models performance evaluation functionality
version: 14.2.0
version: 14.2.1
homepage: https://github.com/gyrdym/ml_algo

environment:
Expand Down

0 comments on commit 1a2a702

Please sign in to comment.