Skip to content

Commit

Permalink
Cross validator entity: evaluate method now returns Future<Vector> in…
Browse files Browse the repository at this point in the history
…stead of double
  • Loading branch information
gyrdym committed Jun 21, 2020
1 parent 5e06b60 commit e5b9dba
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions README.md
Expand Up @@ -98,7 +98,7 @@ All are set, so we can do our classification.
Evaluate our model via accuracy metric:

````dart
final accuracy = validator.evaluate((samples, targetNames) =>
final scores = await validator.evaluate((samples, targetNames) =>
LogisticRegressor(
samples,
targetNames[0], // remember, we provided a list of just a single name
Expand All @@ -112,6 +112,13 @@ final accuracy = validator.evaluate((samples, targetNames) =>
), MetricType.accuracy);
````

Since the CrossValidator's instance returns a Vector of scores as a result of our predictor evaluation, we may choose
any way to reduce all the collected scores to a single number, for instance we may use Vector's `mean` method:

```dart
final accuracy = scores.mean();
```

Let's print the score:
````dart
print('accuracy on classification: ${accuracy.toStringAsFixed(2)}');
Expand All @@ -134,7 +141,7 @@ Future main() async {
final samples = await fromCsv('datasets/pima_indians_diabetes_database.csv', headerExists: true);
final targetColumnName = 'class variable (0 or 1)';
final validator = CrossValidator.KFold(samples, [targetColumnName], numberOfFolds: 5);
final accuracy = validator.evaluate((samples, targetNames) =>
final scores = await validator.evaluate((samples, targetNames) =>
LogisticRegressor(
samples,
targetNames[0], // remember, we provide a list of just a single name
Expand All @@ -146,6 +153,7 @@ Future main() async {
interceptScale: .1,
learningRateType: LearningRateType.constant
), MetricType.accuracy);
final accuracy = scores.mean();
print('accuracy on classification: ${accuracy.toStringFixed(2)}');
}
Expand Down Expand Up @@ -202,14 +210,15 @@ Let the `k` parameter be equal to `4`.
Assess a knn regressor with the chosen `k` value using MAPE metric

````dart
final error = validator.evaluate((samples, targetNames) =>
final scores = await validator.evaluate((samples, targetNames) =>
KnnRegressor(samples, targetNames[0], 4), MetricType.mape);
final averageError = scores.mean();
````

Let's print our error

````dart
print('MAPE error on k-fold validation: ${error.toStringAsFixed(2)}%'); // it yields approx. 6.18
print('MAPE error on k-fold validation: ${averageError.toStringAsFixed(2)}%'); // it yields approx. 6.18
````

### Contacts
Expand Down

0 comments on commit e5b9dba

Please sign in to comment.