shogun-toolbox / shogun

Shōgun
http://shogun-toolbox.org
BSD 3-Clause "New" or "Revised" License
3.03k stars 1.04k forks source link

CrossValidation with Kernel and LibSVM uterly broken #4200

Open vigsterkr opened 6 years ago

vigsterkr commented 6 years ago
import pandas as pd
import numpy as np
from shogun import BinaryLabels
from shogun import CrossValidation
from shogun import ROCEvaluation, PRCEvaluation, F1Measure
from shogun import RealFeatures, CrossValidationSplitting, LibSVM, LibLinear
from shogun import LinearKernel

def evaluate(classifier, labels, features, metric, split):
    cross=CrossValidation(classifier, features, labels, split, metric)
    result=cross.evaluate()
    return CrossValidationResult.obtain_from_generic(result)

def get_labels_and_features(df, feature_type):
    labels = BinaryLabels(np.array(df.iloc[:, 0]))
    features = feature_type(np.array(df.iloc[:, 1:]))
    return labels, features

real_data = pd.read_csv("C_elegans_acc_gc.csv", header=None)
cv_folds = 5
real_labels, real_features = get_labels_and_features(real_data, RealFeatures)
splits = CrossValidationSplitting(real_labels, cv_folds)

c = LibSVM()
c.set_C(1.0, 1.0)
c.set_batch_computation_enabled(True)
c.set_epsilon(1e-5)
c.set_linadd_enabled(True)
k = LinearKernel()
c.set_kernel(k)
m = ROCEvaluation()
r = evaluate(c, real_labels, real_features, m, splits)

output

SystemError: [ERROR] In file /tmp/shogun-20180130-88267-157zdg8/shogun-6.1.3/src/shogun/kernel/Kernel.h line 210: CustomKernel::kernel(): index out of Range: idx_a=1/1760 idx_b=1689/2
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.