问题
I want to use svmutil functions from https://github.com/Netflix/vmaf/tree/master/libsvm/python in my Jupyter notebook which runs on Google Colaboratory.
Running
import svmutil
gives the following error:
ModuleNotFoundError: No module named 'svmutil'
How do I install this github repo in colab?
回答1:
You'll need to install the library first. Here's a complete example:
https://colab.research.google.com/drive/1svYMGnV7HdeqXpN15T5ajxbLijLmBeSm
The key bits:
# Clone the git repo.
!git clone https://github.com/Netflix/vmaf.git
# Build the library.
%cd vmaf/
!make && make install
# Build Python-specific bits.
%cd /content/vmaf/libsvm/python/
!make
# Add the Python module to the path.
import sys
sys.path.append('/content/vmaf/libsvm/python')
# Switch back to the base directory. (This is a convenience
# and isn't required.)
%cd /content
回答2:
First download and save svmutil.py file in the location where you are running your jupyter notebook. Then import svmutil functions using
from svmutil import *
You could be able to use its functionalities
svm_train() : train an SVM model
svm_predict() : predict testing data
svm_read_problem() : read the data from a LIBSVM-format file.
svm_load_model() : load a LIBSVM model.
svm_save_model() : save model to a file.
evaluations() : evaluate prediction results.
回答3:
The accepted answer downloads many other things, not just libsvm. If you want to install only the libsvm library you have to do the following:
!git clone https://github.com/cjlin1/libsvm
%cd libsvm/
!make && make install
%cd /content/libsvm/python/
!make
import sys
sys.path.append('/content/libsvm/python')
%cd /content
来源:https://stackoverflow.com/questions/53931575/how-to-install-svmutil-in-jupyter-notebook-on-google-colaboratory