Python 在mat2py中,如何修复错误属性error:&x27;numpy.ndarray和#x27;对象没有属性';获取"svm"类型';

Python 在mat2py中,如何修复错误属性error:&x27;numpy.ndarray和#x27;对象没有属性';获取"svm"类型';,python,matlab,Python,Matlab,我正在尝试将Matlab代码转换为Python代码。我已经使用sudo-apt-get-install-python-libsvm下载了libsvm库,但是我得到了一个错误 import scipy.io from svmutil import svm_predict def SVM_LIBSVM(VECTOR_TRAINING_LABELS , VECTOR_TRAINING_POINTS ,VECTOR_TESTING_LABELS , VECTOR_TESTING_POINTS):

我正在尝试将Matlab代码转换为Python代码。我已经使用
sudo-apt-get-install-python-libsvm
下载了
libsvm
库,但是我得到了一个错误

import scipy.io
from svmutil import svm_predict
def SVM_LIBSVM(VECTOR_TRAINING_LABELS , VECTOR_TRAINING_POINTS ,VECTOR_TESTING_LABELS , VECTOR_TESTING_POINTS):
    mat = scipy.io.loadmat('model.mat')
    model = mat['model']
    predicted_label = list()
    predicted_label = svm_predict(VECTOR_TESTING_LABELS , VECTOR_TESTING_POINTS , model)
    return predicted_label
我得到以下错误:

File "/home/optimum/mat2py/svmutil.py", line 193, in svm_predict
    svm_type = m.get_svm_type()
AttributeError: 'numpy.ndarray' object has no attribute 'get_svm_type'

我假设
model
对象来自MATLAB libsvm接口,这将使其成为MATLAB结构,而不是
svm\u model
对象。这里没有直接转换,但是您应该能够从结构中读取字段,您可以将其用于python
svm_模型
对象(在这方面不是100%;我没有太多使用python API)

如果在python中找不到方法,最痛苦的方法是将MATLAB结构值移动到ctypes结构,然后使用
toPyModel
(python API)将其转换为python
svm\u模型

struct svm_model
{
    struct svm_parameter param; /* parameter */
    int nr_class;       /* number of classes, = 2 in regression/one class svm */
    int l;          /* total #SV */
    struct svm_node **SV;       /* SVs (SV[l]) */
    double **sv_coef;   /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
    double *rho;        /* constants in decision functions (rho[k*(k-1)/2]) */
    double *probA;      /* pairwise probability information */
    double *probB;
    int *sv_indices;        /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */

    /* for classification only */

    int *label;     /* label of each class (label[k]) */
    int *nSV;       /* number of SVs for each class (nSV[k]) */
                /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
    /* XXX */
    int free_sv;        /* 1 if svm_model is created by svm_load_model*/
                /* 0 if svm_model is created by svm_train */
};

thnks..你能给我一个python API的链接吗谢谢你的回复,我们不能用纯python来做吗?比如在包mat2py中使用svm_predict函数?我使用了它,但我得到了上面的错误,我使用下面的软件包
struct svm_model
{
    struct svm_parameter param; /* parameter */
    int nr_class;       /* number of classes, = 2 in regression/one class svm */
    int l;          /* total #SV */
    struct svm_node **SV;       /* SVs (SV[l]) */
    double **sv_coef;   /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
    double *rho;        /* constants in decision functions (rho[k*(k-1)/2]) */
    double *probA;      /* pairwise probability information */
    double *probB;
    int *sv_indices;        /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */

    /* for classification only */

    int *label;     /* label of each class (label[k]) */
    int *nSV;       /* number of SVs for each class (nSV[k]) */
                /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
    /* XXX */
    int free_sv;        /* 1 if svm_model is created by svm_load_model*/
                /* 0 if svm_model is created by svm_train */
};