def fit_svm_custom_wrapper_liblinear(X, y, C=1.0):

    p = PyLibLinear()
    w = p.trainSVM(X, y, L1R_L2LOSS_SVC, C, 1.0, 0.01)
    weights = w[0, :-1].ravel()
    bias = w[0, -1]

    return weights, bias
def fit_svm_custom_wrapper_liblinear(X, y, C = 1.0):
    
    p = PyLibLinear()
    w = p.trainSVM(X,y,L1R_L2LOSS_SVC,C,1.0,0.01)
    weights = w[0,:-1].ravel()
    bias = w[0,-1]
    
    return weights, bias
def fit_svm_custom_wrapper_liblinear_with_cv(C, X_train, X_test, y_train, y_test):
                    
    X_train, y_train, X_test, y_test = dtype_ensure(X_train, y_train, X_test, y_test)
            
    p = PyLibLinear()
    w = p.trainSVM(X_train,y_train,L1R_L2LOSS_SVC,C,1.0,0.0001)
    
    weights = w[0,:-1].ravel()
    bias = w[0,-1]
    y_pred = predict(X_test, weights, bias, intercept = 0.5)
    
    y_tr_pred = predict(X_train, weights, bias, intercept = 0.5)
    
    accuracy, recall, precision, f1, tr_err = classifier_statistics(y_train, y_test, y_tr_pred, y_pred)
    
    return C, accuracy, recall, precision, f1, tr_err
def fit_svm_custom_wrapper_liblinear_with_cv(C, X_train, X_test, y_train,
                                             y_test):

    X_train, y_train, X_test, y_test = dtype_ensure(X_train, y_train, X_test,
                                                    y_test)

    p = PyLibLinear()
    w = p.trainSVM(X_train, y_train, L1R_L2LOSS_SVC, C, 1.0, 0.0001)

    weights = w[0, :-1].ravel()
    bias = w[0, -1]
    y_pred = predict(X_test, weights, bias, intercept=0.5)

    y_tr_pred = predict(X_train, weights, bias, intercept=0.5)

    accuracy, recall, precision, f1, tr_err = classifier_statistics(
        y_train, y_test, y_tr_pred, y_pred)

    return C, accuracy, recall, precision, f1, tr_err