scikit-learn: use classifier from older version - scikit-learn

I have a pickled scikit-learn classifier trained in version 0.14.1, and I want to use it on my mac which has scikit-learn version 0.17.1. When I try to run clf.score I get the following error:
AttributeError: 'SVC' object has no attribute '_dual_coef_'
Googling this it looks like the problem is with the difference in version between making the classifier and now wanting to test it. If retraining is not an option, is there a way to upgrade the classifier to work in the new version of scikit-learn?

Related

how can I solve this error regarding the spacy version

This is the code:
nlp_model=spacy.load('nlp_model')
This is the error:
OSError: [E053] Could not read config.cfg from nlp_model\config.cfg
I am using a pre trained model from spacy v2 and my spacy model is 3.2.1. How can I use this model in my spacy version
You can't use a model from spaCy v2 with spaCy v3. The major version (the first part of the version number) of spaCy and your model need to be the same.
You need to upgrade your model, or, if it's one you trained yourself, retrain it.

how to deploy a model trained on TF2 Keras on Movidius Myriad 2 (NCSDK 2.05.00.02)

I try to optimize my model using 'MvNCCompile' but it doesn't accept my frozen TF2 graph.
'Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.'.
Can I somehow convert my TF2 (keras) model to TF1 graph format so it can be used? Or is there another way to get the TF2 Keras model to be accepted by the Intel optimisation tool?
Hm. MvNCCompile is a deprecated tool to work with NCS2. I suggest you to try the latest version of OpenVINO: https://docs.openvinotoolkit.org/

scikit learn upgrade causes failure when old models are loaded

I trained some data science models with scikit learn from v0.19.1. The models are stored in a pickle file. After upgrading to latest version (v0.23.1), I get the following error when I try to load them:
File "../../Utils/WebsiteContentSelector.py", line 100, in build_page_selector
page_selector = pickle.load(pkl_file)
AttributeError: Can't get attribute 'DeprecationDict' on <module 'sklearn.utils.deprecation' from '/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py'>
Is there a way to upgrade without retraining all my models (which is very expensive)?
You used a new version of sklearn to load a model which was trained by an old version of sklearn.
So, the options are:
Retrain the model with current version of sklearn if you have the training script and data
Or fall back to the lower sklearn version reported in the warning message
Depending on the kind of sklearn model used, if the model is simple regression model, what is probably needed is to get the actual weights and bias (or intercept) values.
You can check these values in your model:
model.classes_
model.coef_
model.intercept_
they are of numpy type and can be pickled easily. Also, you need to get the same parameters passed to the model construction. For example:
tol
max_iter
and so on. With this, in the upgraded version, the same model created with the same parameters can read the weights and intercept.
In this way, no re-training is needed and you can use the upgrade sklearn.
When lib versions are not backward compatible you can do the following:
Downgrade sklearn back to the original version
Load each model, extract and store its coefficients (which are model-specific - check documentation)
Upgrade sklearn, load coefficients and init models with them, save models
Related question.

Are there syntax differences between using Keras with a Tensorflow 2, Theano, or CNTK backend?

It looks like tf.keras is suggested if you're using a Tensorflow 2 backend, but what about using Theano or CNTK as a backend? I have never used Keras or any DL library.
Keras has officially decided to drop support of CNTK and Theano moving forward. Therefore, if you are using keras with tensorflow as the backend, you should use tf.keras.
For older versions for keras, you can use all three backend with no syntax change in your keras code.
Keras 2.2.5 was the last release of Keras implementing the 2.2.* API.
It was the last release to only support TensorFlow 1 (as well as
Theano and CNTK).
The current release is Keras 2.3.0, which makes significant API
changes and add support for TensorFlow 2.0. The 2.3.0 release will be
the last major release of multi-backend Keras. Multi-backend Keras is
superseded by tf.keras.
You can find the above information here.

sklearn: Regression models on sparse data?

Does python's scikit-learn have any regression models that work well with sparse data?
I was poking around and found this "sparse linear regression" module, but it seems outdated. (It's so old that scikit-learn was called 'scikits-learn' at the time, I think.)
Most scikit-learn regression models (linear such as Ridge, Lasso, ElasticNet or non-linear, e.g. with RandomForestRegressor) support both dense and sparse input data recent versions of scikit-learn (0.16.0 is the latest stable version at the time of writing).
Edit: if you are unsure, check the docstring of the fit method of the class of interest.

Resources