【问题标题】:How to install svmutil in Jupyter notebook on Google Colaboratory?如何在 Google Colaboratory 的 Jupyter notebook 中安装 svmutil?
【发布时间】:2019-05-24 16:30:40
【问题描述】:

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

跑步

import svmutil

给出以下错误:

ModuleNotFoundError: No module named 'svmutil'

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

【问题讨论】:

    标签: python jupyter-notebook google-colaboratory


    【解决方案1】:

    首先下载 svmutil.py 文件并将其保存在运行 jupyter notebook 的位置。然后使用

    导入 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.
    

    【讨论】:

      【解决方案2】:

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

      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
      

      【讨论】:

        【解决方案3】:

        接受的答案会下载许多其他内容,而不仅仅是 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
        

        【讨论】:

          猜你喜欢
          • 2020-06-16
          • 2018-08-04
          • 2018-08-01
          • 2019-08-27
          • 1970-01-01
          • 2019-10-30
          • 2020-01-18
          • 1970-01-01
          相关资源
          最近更新 更多