1

I trying to edit sklearn and I need to add an attribute for one of the class. I was sure that adding self.attribute will be the answer but i keep getting an error this attribute isn't available. I try to add this attribute install the new package with my change and everything went fine until I run it

cdef class ClassificationCriterion(Criterion):
    """Abstract criterion for classification."""

    def __cinit__(self, SIZE_t n_outputs,
                  np.ndarray[SIZE_t, ndim=1] n_classes, int test = 1):
        """Initialize attributes for this criterion.

        Parameters
        ----------
        n_outputs : SIZE_t
            The number of targets, the dimensionality of the prediction
        n_classes : numpy.ndarray, dtype=SIZE_t
            The number of unique classes in each target
        """
        self.test = test

code I ran:

clf = sklearn.tree.DecisionTreeClassifier(criterion='entropy',random_state=0,max_depth=2 )
clf2=clf.fit(x,y)

AttributeError: sklearn.tree._criterion.Entropy object has no attribute test

Parthasarathy Subburaj
  • 4,106
  • 2
  • 10
  • 24
M.Marudi
  • 33
  • 2
  • 1
    Can't you make a subclass it instead of editing the source code? – Dan Jul 18 '19 at 14:13
  • 1
    Possible duplicate of [Mixing cdef and regular python attributes in cdef class](https://stackoverflow.com/questions/42632297/mixing-cdef-and-regular-python-attributes-in-cdef-class) – DavidW Jul 18 '19 at 15:46

0 Answers0