Comments (6)
The models should implement the Serde
trait, so you can serialize them using something like ciborium
from linfa.
Seems like MultiClassModel
and linfa-bayes
have no support for Serde
. Weird. We'll need to add that.
from linfa.
My bad, it turns out the example SVM model uses Svm<f64, bool> not Svm<_, bool>. I only changed the line to :
let model: Svm<f65, bool> = model_value.deserialized().unwrap();
And it works super cool!
from linfa.
I'm having a little problem hehe, I'm trying to serialize the model (I'm using the example of linfa_svm) but I don't know if I'm using the correct syntax since I get the error in the line where I use cbor:
the trait bound `MultiClassModel<ndarray::ArrayBase<ndarray::data_repr::OwnedRepr<f64>, ndarray::dimension::dim::Dim<[usize; 2]>>, usize>: serde::ser::Serialize` is not satisfied
the following other types implement trait `serde::ser::Serialize`:
This is the code I'm using (linfa_svm/examples/winequality_multi.rs) :
let model = train
.one_vs_all()?
.into_iter()
.map(|(l, x)| (l, params.fit(&x).unwrap()))
.collect::<MultiClassModel<_, _>>();
let pred = model.predict(&valid);
//Trying to serialize model
let save_model = cbor!(model).unwrap();
Could you give me a more detailed example? I would appreciate it too much!
from linfa.
Oh! I will try with normal SVM then, thank you!
from linfa.
One last question,
I already managed to serialize the SVM model without Multiclass to CBOR, using ciborium, I also managed to de-serialize it in another file and convert it to Value, the last step would be to convert it from Value to SVM, any idea how to do this?
Code for creating and exporting the model :
let model = Svm::<_, bool>::params().pos_neg_weights(50000., 5000.).gaussian_kernel(80.0).fit(&train)?;
//Serializing the trained model with ciborium
let value_model : Value = cbor!(model).unwrap();
let mut vec_model : Vec<u8> = Vec::new();
let _cebor_writer = ciborium::ser::into_writer(&value_model, &mut vec_model);
//Esporting it to a .cbor file
let path: &Path = Path::new("./model.cbor");
fs::write(path, vec_model).unwrap();
Attempt to use the trained model in other .rs program :
let mut file = File::open("./model.cbor").unwrap();
let mut data: Vec<u8> = Vec::new();
file.read_to_end(&mut data).unwrap();
let model_value : Value = ciborium::de::from_reader::<Value, _>(&data[..]).unwrap();
let model: Svm<_, bool> = model_value.deserialized().unwrap(); // Error
But I keep getting error when trying to converting form ciborium::Value to SVM, the rust-analyzer suggests : consider specifying the generic argument: ::<Svm<_, bool>>
, I guess I have to pass the SVM serve-deserializer but I don't know how to do that.
I know this has nothing to do with linfa, but I really think that exporting and importing the models can be very useful.
Thank you!
from linfa.
Related Issues (20)
- Add arrow data storage support for linfa pre-processing and training module HOT 3
- Is it possible to use Polars instead of ndarray? HOT 1
- I am trying to get Linfa to work with apple M2 accelerate: HOT 2
- How to use `LInfDist` for `HierarchicalCluster` HOT 1
- Add Serde to CountVectorizer, to export and import it HOT 6
- Would there be any interest in a Covariance module? HOT 2
- How I can save a logistic model for serving? HOT 6
- linfa-clustering depends on partitions 0.2.4, which throws future-incompatibilities warnings HOT 1
- Incompatibility of the partitions dependency with future versions of Rust HOT 3
- Shuffle dataset HOT 2
- Implementing serde Serialize/Deserialize for linfa_bayes crate models HOT 1
- Bump `argmin` dependency to 0.8 HOT 6
- Standard error estimation on OLS coefficients HOT 3
- linfa-kernel fails to compile HOT 10
- linfa-svm learning speed and memory allocation
- Dependency version thiserror in linfa hierarchical causes problems in real world projects
- Crates.io version of linfa_kernel fails to compile. HOT 1
- Would it be better to use the same API as scikit-learn HOT 2
- Serialize a trained model to disk? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linfa.