Skip to content

Cannot perform inference on deserialized SVC and SVR  #267

Closed
@Roee-87

Description

@Roee-87

I'm submitting a

  • bug report.
  • improvement.
  • [ x] feature request.

Current Behaviour:

SVC and SVR models skip the parameters during serialization. What is the correct way to deserialize a model in order to perform inference?

let lr_json = serde_json::to_string(&my_model);

produces the following json file:

{ "classes": [-1, 1], "instances": [ [4.9, 2.4, 3.3, 1.0], [4.4, 2.9, 1.4, 0.2], [7.0, 3.2, 4.7, 1.4], [5.5, 2.3, 4.0, 1.3], [6.9, 3.1, 4.9, 1.5], [5.4, 3.9, 1.7, 0.4], [5.7, 2.8, 4.5, 1.3], [6.3, 3.3, 4.7, 1.6] ], "w": [ 0.7330568313232404, -0.9886291197226762, 0.4983642540817094, 0.1369267334839056, 0.12914908421939392, -0.9760276163690054, 0.3306627164164916, 0.13649711656694088 ], "b": 0.18156339068191985, "phantomdata": null }

The "parameters" field is missing due a serde skip command in svc.rs:128:7.

A deserialized model cannot perform inference using SVC.predict() due to the missing parameters field.

let y_hat: &Vec<f64> = &model.predict(&x).unwrap();

results in an error:

thread 'main' panicked at 'called Option::unwrap() on a None value', /Users/.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/smartcore-0.3.2/src/svm/svc.rs:349:26

Expected Behaviour:

If serde skip is removed and I am able to serialize the parameters, I would expect a deserialized model to perform inference.

Steps to reproduce:

https://github.com/Roee-87/SVC/blob/master/src/main.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions