如何在Google Colaboratory上的Jupyter笔记本中安装svmutil?

问题描述 投票:0回答:3

我想在我的Jupyter笔记本中使用https://github.com/Netflix/vmaf/tree/master/libsvm/python的svmutil函数,该笔记本在Google Colaboratory上运行。

运行

import svmutil

给出以下错误:

ModuleNotFoundError: No module named 'svmutil'

如何在colab中安装这个github repo?

python jupyter-notebook google-colaboratory
3个回答
0
投票

您需要先安装库。这是一个完整的例子:

https://colab.research.google.com/drive/1svYMGnV7HdeqXpN15T5ajxbLijLmBeSm

关键位:

# 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

0
投票

首先在运行jupyter笔记本的位置下载并保存svmutil.py文件。然后使用导入svmutil函数

from svmutil import *

您可以使用其功能

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.

0
投票

接受的答案会下载许多其他内容,而不仅仅是libsvm。如果只想安装libsvm库,则必须执行以下操作:

!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
© www.soinside.com 2019 - 2024. All rights reserved.