How to install svmutil in Jupyter notebook on Google Colaboratory?

天大地大妈咪最大 提交于 2020-01-03 06:01:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!