Skip to content

Commit

Permalink
Rank: Skip metrices not supported for sparse data
Browse files Browse the repository at this point in the history
  • Loading branch information
nikicc committed Jul 1, 2016
1 parent 4f698ee commit fa50954
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Orange/preprocess/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class Scorer:
feature_type = None
class_type = None
supports_sparse_data = None
preprocessors = [
RemoveNaNClasses()
]
Expand Down Expand Up @@ -62,6 +63,8 @@ def score_data(self, data, feature):


class SklScorer(Scorer, metaclass=WrapperMeta):
supports_sparse_data = True

preprocessors = Scorer.preprocessors + [
Impute()
]
Expand Down Expand Up @@ -172,6 +175,7 @@ class ClassificationScorer(Scorer):
"""
feature_type = DiscreteVariable
class_type = DiscreteVariable
supports_sparse_data = True
preprocessors = Scorer.preprocessors + [
Discretize(remove_const=False)
]
Expand Down Expand Up @@ -302,6 +306,7 @@ class ReliefF(Scorer):
"""
feature_type = Variable
class_type = DiscreteVariable
supports_sparse_data = False

def __init__(self, n_iterations=50, k_nearest=10):
self.n_iterations = n_iterations
Expand All @@ -324,9 +329,11 @@ def score_data(self, data, feature):
return weights[0]
return weights


class RReliefF(Scorer):
feature_type = Variable
class_type = ContinuousVariable
supports_sparse_data = False

def __init__(self, n_iterations=50, k_nearest=50):
self.n_iterations = n_iterations
Expand Down
5 changes: 5 additions & 0 deletions Orange/widgets/data/owrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections import namedtuple

import numpy as np
from scipy.sparse import issparse

from PyQt4 import QtGui
from PyQt4.QtCore import Qt
Expand Down Expand Up @@ -255,6 +256,10 @@ def setData(self, data):
self.error(0, "Cannot handle class variable type %r" %
type(self.data.domain.class_var).__name__)

if issparse(self.data.X): # keep only measures supporting sparse data
self.measures = [m for m in self.measures
if m.score.supports_sparse_data]

self.ranksModel.setRowCount(len(attrs))
for i, a in enumerate(attrs):
if a.is_discrete:
Expand Down

0 comments on commit fa50954

Please sign in to comment.