Skip to content
Browse files

working on segfault

  • Loading branch information...
1 parent 129702f commit a097bf81785d43a68d3b3ad99e063ca9f45a0403 @ndawe committed Apr 5, 2011
View
35 scikits/learn/decisiontree/decisiontree.py
@@ -12,14 +12,43 @@ def __init__(self, minleafsize = None, maxdepth = -1, maxnodes = -1, nbins = 20,
self.nbins = nbins
self.sepcriterion = sepcriterion
self.root = None
+ self.nfeatures = 0
- def fit(self, X, Y, sample_weight = np.empty(0)):
-
- self.root = libdecisiontree.fit(X, Y, sample_weight, self.minleafsize, self.nbins)
+ def fit(self, X, y, sample_weight = [], **params):
+
+ self._set_params(**params)
+
+ X = np.atleast_2d(np.asanyarray(X, dtype = np.float64, order = 'C'))
+ y = np.asanyarray(y, dtype = np.float64, order = 'C')
+ sample_weight = np.asanyarray(sample_weight, dtype = np.float64, order = 'C')
+
+ if X.shape[0] != y.shape[0]:
+ raise ValueError("X and y have incompatible shapes.\n" +
+ "X has %s features, but y has %s." % \
+ (X.shape[0], y.shape[0]))
+
+ if len(sample_weight) == 0:
+ sample_weight = np.ones(X.shape[0], dtype=np.float64)
+ elif sample_weight.shape[0] != X.shape[0]:
+ raise ValueError("sample_weight and X have incompatible shapes.\n" +
+ "sample_weight has %s samples while X has %s" % \
+ (sample_weight.shape[0], X.shape[0]))
+
+ self.root = libdecisiontree.fit(X, y, sample_weight, self.minleafsize, self.nbins)
+ self.nfeatures = X.shape[1]
return self
def predict(self, X):
+ if self.root is None:
+ return None
+
+ X = np.atleast_2d(np.asanyarray(X, dtype = np.float64, order = 'C'))
+
+ if X.shape[1] != self.nfeatures:
+ raise ValueError("X.shape[1] should be equal to the number of "
+ "features at training time!")
+
return libdecisiontree.predict(X, self.root)
"""
View
596 scikits/learn/decisiontree/libdecisiontree.cpp
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.14.1 on Tue Apr 5 17:37:04 2011 */
+/* Generated by Cython 0.14.1 on Tue Apr 5 22:20:15 2011 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@@ -497,15 +497,15 @@ typedef struct {
static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
static void __Pyx_RaiseBufferFallbackError(void); /*proto*/
-static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
-
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
@@ -528,6 +528,14 @@ Py_ssize_t __Pyx_minusones[] = {-1, -1};
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
+static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
+#if PY_MAJOR_VERSION >= 3
+static PyObject* __pyx_print = 0;
+static PyObject* __pyx_print_kwargs = 0;
+#endif
+
+static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/
+
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t);
#if CYTHON_CCOMPLEX
@@ -706,16 +714,15 @@ static int __pyx_module_is_main_scikits__learn__decisiontree__libdecisiontree =
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_RuntimeError;
-static char __pyx_k_2[] = "sample_weight and X have incompatible shapes: ";
-static char __pyx_k_3[] = "sample_weight has %s samples while X has %s";
-static char __pyx_k_4[] = "ndarray is not C contiguous";
-static char __pyx_k_6[] = "ndarray is not Fortran contiguous";
-static char __pyx_k_8[] = "Non-native byte order not supported";
-static char __pyx_k_10[] = "unknown dtype code in numpy.pxd (%d)";
-static char __pyx_k_11[] = "Format string allocated too short, see comment in numpy.pxd";
-static char __pyx_k_14[] = "Format string allocated too short.";
-static char __pyx_k_16[] = "\nBinding for libdecisiontree\n---------------------------\n\nNotes\n-----\n\nAuthors\n-------\n2011: Noel Dawe <Noel.Dawe@cern.ch>\n";
-static char __pyx_k_18[] = "scikits.learn.decisiontree.libdecisiontree";
+static char __pyx_k_2[] = "done split";
+static char __pyx_k_3[] = "ndarray is not C contiguous";
+static char __pyx_k_5[] = "ndarray is not Fortran contiguous";
+static char __pyx_k_7[] = "Non-native byte order not supported";
+static char __pyx_k_9[] = "unknown dtype code in numpy.pxd (%d)";
+static char __pyx_k_10[] = "Format string allocated too short, see comment in numpy.pxd";
+static char __pyx_k_13[] = "Format string allocated too short.";
+static char __pyx_k_15[] = "\nBinding for libdecisiontree\n---------------------------\n\nNotes\n-----\n\nAuthors\n-------\n2011: Noel Dawe <Noel.Dawe@cern.ch>\n";
+static char __pyx_k_17[] = "scikits.learn.decisiontree.libdecisiontree";
static char __pyx_k__B[] = "B";
static char __pyx_k__H[] = "H";
static char __pyx_k__I[] = "I";
@@ -741,20 +748,19 @@ static char __pyx_k__fit[] = "fit";
static char __pyx_k__obj[] = "obj";
static char __pyx_k__base[] = "base";
static char __pyx_k__data[] = "data";
+static char __pyx_k__init[] = "init";
static char __pyx_k__ndim[] = "ndim";
-static char __pyx_k__ones[] = "ones";
static char __pyx_k__root[] = "root";
static char __pyx_k__descr[] = "descr";
-static char __pyx_k__dtype[] = "dtype";
static char __pyx_k__empty[] = "empty";
static char __pyx_k__names[] = "names";
static char __pyx_k__nbins[] = "nbins";
static char __pyx_k__numpy[] = "numpy";
static char __pyx_k__range[] = "range";
static char __pyx_k__shape[] = "shape";
+static char __pyx_k__split[] = "split";
static char __pyx_k__fields[] = "fields";
static char __pyx_k__format[] = "format";
-static char __pyx_k__float64[] = "float64";
static char __pyx_k__predict[] = "predict";
static char __pyx_k__strides[] = "strides";
static char __pyx_k__thisptr[] = "thisptr";
@@ -771,14 +777,13 @@ static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__sample_weight[] = "sample_weight";
static char __pyx_k__recursive_split[] = "recursive_split";
static PyObject *__pyx_kp_u_10;
-static PyObject *__pyx_kp_u_11;
-static PyObject *__pyx_kp_u_14;
-static PyObject *__pyx_n_s_18;
+static PyObject *__pyx_kp_u_13;
+static PyObject *__pyx_n_s_17;
static PyObject *__pyx_kp_s_2;
-static PyObject *__pyx_kp_s_3;
-static PyObject *__pyx_kp_u_4;
-static PyObject *__pyx_kp_u_6;
-static PyObject *__pyx_kp_u_8;
+static PyObject *__pyx_kp_u_3;
+static PyObject *__pyx_kp_u_5;
+static PyObject *__pyx_kp_u_7;
+static PyObject *__pyx_kp_u_9;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s__X;
@@ -790,12 +795,11 @@ static PyObject *__pyx_n_s__buf;
static PyObject *__pyx_n_s__byteorder;
static PyObject *__pyx_n_s__data;
static PyObject *__pyx_n_s__descr;
-static PyObject *__pyx_n_s__dtype;
static PyObject *__pyx_n_s__empty;
static PyObject *__pyx_n_s__fields;
static PyObject *__pyx_n_s__fit;
-static PyObject *__pyx_n_s__float64;
static PyObject *__pyx_n_s__format;
+static PyObject *__pyx_n_s__init;
static PyObject *__pyx_n_s__itemsize;
static PyObject *__pyx_n_s__minleafsize;
static PyObject *__pyx_n_s__names;
@@ -804,28 +808,28 @@ static PyObject *__pyx_n_s__ndim;
static PyObject *__pyx_n_s__np;
static PyObject *__pyx_n_s__numpy;
static PyObject *__pyx_n_s__obj;
-static PyObject *__pyx_n_s__ones;
static PyObject *__pyx_n_s__predict;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__readonly;
static PyObject *__pyx_n_s__recursive_split;
static PyObject *__pyx_n_s__root;
static PyObject *__pyx_n_s__sample_weight;
static PyObject *__pyx_n_s__shape;
+static PyObject *__pyx_n_s__split;
static PyObject *__pyx_n_s__strides;
static PyObject *__pyx_n_s__suboffsets;
static PyObject *__pyx_n_s__thisptr;
static PyObject *__pyx_n_s__type_num;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_15;
static PyArrayObject *__pyx_k_1;
-static PyObject *__pyx_k_tuple_5;
-static PyObject *__pyx_k_tuple_7;
-static PyObject *__pyx_k_tuple_9;
+static PyObject *__pyx_k_tuple_4;
+static PyObject *__pyx_k_tuple_6;
+static PyObject *__pyx_k_tuple_8;
+static PyObject *__pyx_k_tuple_11;
static PyObject *__pyx_k_tuple_12;
-static PyObject *__pyx_k_tuple_13;
-static PyObject *__pyx_k_tuple_15;
-static PyObject *__pyx_k_tuple_17;
+static PyObject *__pyx_k_tuple_14;
+static PyObject *__pyx_k_tuple_16;
/* "scikits/learn/decisiontree/libdecisiontree.pyx":26
* cdef class PyNode:
@@ -911,18 +915,7 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_fit(P
Py_ssize_t __pyx_bstride_0_sample_weight = 0;
Py_ssize_t __pyx_bshape_0_sample_weight = 0;
PyObject *__pyx_r = NULL;
- Py_ssize_t __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- PyObject *__pyx_t_7 = NULL;
- PyArrayObject *__pyx_t_8 = NULL;
- int __pyx_t_9;
- PyObject *__pyx_t_10 = NULL;
- PyObject *__pyx_t_11 = NULL;
- PyObject *__pyx_t_12 = NULL;
+ PyObject *__pyx_t_1 = NULL;
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__X,&__pyx_n_s__Y,&__pyx_n_s__sample_weight,&__pyx_n_s__minleafsize,&__pyx_n_s__nbins,0};
__Pyx_RefNannySetupContext("fit");
__pyx_self = __pyx_self;
@@ -1008,7 +1001,6 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_fit(P
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __Pyx_INCREF((PyObject *)__pyx_v_sample_weight);
__pyx_v_root = ((struct __pyx_obj_7scikits_5learn_12decisiontree_15libdecisiontree_PyNode *)Py_None); __Pyx_INCREF(Py_None);
__pyx_bstruct_X.buf = NULL;
__pyx_bstruct_Y.buf = NULL;
@@ -1038,138 +1030,64 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_fit(P
/* "scikits/learn/decisiontree/libdecisiontree.pyx":60
* cdef PyNode root
*
- * if len(sample_weight) == 0: # <<<<<<<<<<<<<<
- * sample_weight = np.ones(X.shape[0], dtype=np.float64)
- * else:
- */
- __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_sample_weight)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_2 = (__pyx_t_1 == 0);
- if (__pyx_t_2) {
-
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":61
- *
- * if len(sample_weight) == 0:
- * sample_weight = np.ones(X.shape[0], dtype=np.float64) # <<<<<<<<<<<<<<
- * else:
- * assert sample_weight.shape[0] == X.shape[0], \
- */
- __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ones); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_PyInt_to_py_Py_intptr_t((__pyx_v_X->dimensions[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_5));
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_3 = 0;
- __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_3));
- __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_7 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__float64); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_7);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- __pyx_t_7 = PyEval_CallObjectWithKeywords(__pyx_t_4, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_7);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
- __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
- if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_8 = ((PyArrayObject *)__pyx_t_7);
- {
- __Pyx_BufFmt_StackElem __pyx_stack[1];
- __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sample_weight);
- __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sample_weight, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
- if (unlikely(__pyx_t_9 < 0)) {
- PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
- if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sample_weight, (PyObject*)__pyx_v_sample_weight, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
- Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
- __Pyx_RaiseBufferFallbackError();
- } else {
- PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
- }
- }
- __pyx_bstride_0_sample_weight = __pyx_bstruct_sample_weight.strides[0];
- __pyx_bshape_0_sample_weight = __pyx_bstruct_sample_weight.shape[0];
- if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- }
- __pyx_t_8 = 0;
- __Pyx_DECREF(((PyObject *)__pyx_v_sample_weight));
- __pyx_v_sample_weight = ((PyArrayObject *)__pyx_t_7);
- __pyx_t_7 = 0;
- goto __pyx_L6;
- }
- /*else*/ {
-
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":63
- * sample_weight = np.ones(X.shape[0], dtype=np.float64)
- * else:
- * assert sample_weight.shape[0] == X.shape[0], \ # <<<<<<<<<<<<<<
- * "sample_weight and X have incompatible shapes: " + \
- * "sample_weight has %s samples while X has %s" % \
+ * root = PyNode() # <<<<<<<<<<<<<<
+ * print "init"
+ * init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr)
*/
- #ifndef CYTHON_WITHOUT_ASSERTIONS
- if (unlikely(!((__pyx_v_sample_weight->dimensions[0]) == (__pyx_v_X->dimensions[0])))) {
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7scikits_5learn_12decisiontree_15libdecisiontree_PyNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_v_root));
+ __pyx_v_root = ((struct __pyx_obj_7scikits_5learn_12decisiontree_15libdecisiontree_PyNode *)__pyx_t_1);
+ __pyx_t_1 = 0;
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":66
- * "sample_weight and X have incompatible shapes: " + \
- * "sample_weight has %s samples while X has %s" % \
- * (sample_weight.shape[0], X.shape[0]) # <<<<<<<<<<<<<<
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":61
*
+ * root = PyNode()
+ * print "init" # <<<<<<<<<<<<<<
* init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr)
+ * print "split"
*/
- __pyx_t_7 = __Pyx_PyInt_to_py_Py_intptr_t((__pyx_v_sample_weight->dimensions[0])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_7);
- __pyx_t_3 = __Pyx_PyInt_to_py_Py_intptr_t((__pyx_v_X->dimensions[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_5));
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
- __Pyx_GIVEREF(__pyx_t_7);
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __pyx_t_7 = 0;
- __pyx_t_3 = 0;
- __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_3));
- __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
- __pyx_t_5 = PyNumber_Add(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_5));
- __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
- PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_5));
- __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- }
- #endif
- }
- __pyx_L6:;
+ if (__Pyx_PrintOne(0, ((PyObject *)__pyx_n_s__init)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":68
- * (sample_weight.shape[0], X.shape[0])
- *
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":62
+ * root = PyNode()
+ * print "init"
* init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr) # <<<<<<<<<<<<<<
+ * print "split"
* root.thisptr.recursive_split(minleafsize, nbins)
- * return root
*/
init_root(__pyx_v_X->data, __pyx_v_Y->data, __pyx_v_sample_weight->data, __pyx_v_X->dimensions, __pyx_v_root->thisptr);
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":69
- *
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":63
+ * print "init"
* init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr)
+ * print "split" # <<<<<<<<<<<<<<
+ * root.thisptr.recursive_split(minleafsize, nbins)
+ * print "done split"
+ */
+ if (__Pyx_PrintOne(0, ((PyObject *)__pyx_n_s__split)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":64
+ * init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr)
+ * print "split"
* root.thisptr.recursive_split(minleafsize, nbins) # <<<<<<<<<<<<<<
+ * print "done split"
* return root
- *
*/
__pyx_v_root->thisptr->recursive_split(__pyx_v_minleafsize, __pyx_v_nbins);
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":70
- * init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr)
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":65
+ * print "split"
+ * root.thisptr.recursive_split(minleafsize, nbins)
+ * print "done split" # <<<<<<<<<<<<<<
+ * return root
+ *
+ */
+ if (__Pyx_PrintOne(0, ((PyObject *)__pyx_kp_s_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":66
* root.thisptr.recursive_split(minleafsize, nbins)
+ * print "done split"
* return root # <<<<<<<<<<<<<<
*
* def predict(np.ndarray[np.float64_t, ndim=2, mode='c'] X,
@@ -1182,11 +1100,7 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_fit(P
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_1);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_bstruct_Y);
@@ -1202,13 +1116,12 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_fit(P
__Pyx_SafeReleaseBuffer(&__pyx_bstruct_sample_weight);
__pyx_L2:;
__Pyx_DECREF((PyObject *)__pyx_v_root);
- __Pyx_DECREF((PyObject *)__pyx_v_sample_weight);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "scikits/learn/decisiontree/libdecisiontree.pyx":72
+/* "scikits/learn/decisiontree/libdecisiontree.pyx":68
* return root
*
* def predict(np.ndarray[np.float64_t, ndim=2, mode='c'] X, # <<<<<<<<<<<<<<
@@ -1261,11 +1174,11 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_1pred
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__root);
if (likely(values[1])) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "predict") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "predict") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_X = ((PyArrayObject *)values[0]);
__pyx_v_root = ((struct __pyx_obj_7scikits_5learn_12decisiontree_15libdecisiontree_PyNode *)values[1]);
@@ -1277,7 +1190,7 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_1pred
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("predict", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("scikits.learn.decisiontree.libdecisiontree.predict");
__Pyx_RefNannyFinishContext();
@@ -1286,39 +1199,39 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_1pred
__pyx_v_dec_values = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None);
__pyx_bstruct_dec_values.buf = NULL;
__pyx_bstruct_X.buf = NULL;
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_X), __pyx_ptype_5numpy_ndarray, 1, "X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_root), __pyx_ptype_7scikits_5learn_12decisiontree_15libdecisiontree_PyNode, 1, "root", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_X), __pyx_ptype_5numpy_ndarray, 1, "X", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_root), __pyx_ptype_7scikits_5learn_12decisiontree_15libdecisiontree_PyNode, 1, "root", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
- if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_X, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_X, (PyObject*)__pyx_v_X, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_bstride_0_X = __pyx_bstruct_X.strides[0]; __pyx_bstride_1_X = __pyx_bstruct_X.strides[1];
__pyx_bshape_0_X = __pyx_bstruct_X.shape[0]; __pyx_bshape_1_X = __pyx_bstruct_X.shape[1];
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":90
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":86
* cdef np.ndarray[np.float64_t, ndim=1, mode='c'] dec_values
*
* dec_values = np.empty(X.shape[0]) # <<<<<<<<<<<<<<
* copy_predict(X.data, root.thisptr, X.shape, dec_values.data)
* return dec_values
*/
- __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = __Pyx_PyInt_to_py_Py_intptr_t((__pyx_v_X->dimensions[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyInt_to_py_Py_intptr_t((__pyx_v_X->dimensions[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
__pyx_t_1 = 0;
- __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
- if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_t_4 = ((PyArrayObject *)__pyx_t_1);
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
@@ -1335,22 +1248,22 @@ static PyObject *__pyx_pf_7scikits_5learn_12decisiontree_15libdecisiontree_1pred
}
__pyx_bstride_0_dec_values = __pyx_bstruct_dec_values.strides[0];
__pyx_bshape_0_dec_values = __pyx_bstruct_dec_values.shape[0];
- if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_4 = 0;
__Pyx_DECREF(((PyObject *)__pyx_v_dec_values));
__pyx_v_dec_values = ((PyArrayObject *)__pyx_t_1);
__pyx_t_1 = 0;
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":91
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":87
*
* dec_values = np.empty(X.shape[0])
* copy_predict(X.data, root.thisptr, X.shape, dec_values.data) # <<<<<<<<<<<<<<
* return dec_values
*/
copy_predict(__pyx_v_X->data, __pyx_v_root->thisptr, __pyx_v_X->dimensions, __pyx_v_dec_values->data);
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":92
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":88
* dec_values = np.empty(X.shape[0])
* copy_predict(X.data, root.thisptr, X.shape, dec_values.data)
* return dec_values # <<<<<<<<<<<<<<
@@ -1510,7 +1423,7 @@ static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_
*
* if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
*/
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@@ -1550,7 +1463,7 @@ static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_
*
* info.buf = PyArray_DATA(self)
*/
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@@ -1820,7 +1733,7 @@ static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_
* if t == NPY_BYTE: f = "b"
* elif t == NPY_UBYTE: f = "B"
*/
- __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_Raise(__pyx_t_4, 0, 0);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@@ -2060,7 +1973,7 @@ static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_
*/
__pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_10), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_9), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_8));
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -2563,7 +2476,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
*
* if ((child.byteorder == '>' and little_endian) or
*/
- __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
@@ -2614,7 +2527,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
* # One could encode it in the format string and have Cython
* # complain instead, BUT: < and > in format strings also imply
*/
- __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_Raise(__pyx_t_5, 0, 0);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
@@ -2719,7 +2632,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
*
* # Until ticket #99 is fixed, use integers to avoid warnings
*/
- __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_Raise(__pyx_t_3, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
@@ -3065,7 +2978,7 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx
* f += 1
* else:
*/
- __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_10), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_9), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_5));
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
@@ -3457,7 +3370,7 @@ static PyMethodDef __pyx_methods[] = {
static struct PyModuleDef __pyx_moduledef = {
PyModuleDef_HEAD_INIT,
__Pyx_NAMESTR("libdecisiontree"),
- __Pyx_DOCSTR(__pyx_k_16), /* m_doc */
+ __Pyx_DOCSTR(__pyx_k_15), /* m_doc */
-1, /* m_size */
__pyx_methods /* m_methods */,
NULL, /* m_reload */
@@ -3469,14 +3382,13 @@ static struct PyModuleDef __pyx_moduledef = {
static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_kp_u_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 1, 0, 0},
- {&__pyx_kp_u_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 1, 0, 0},
- {&__pyx_kp_u_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 1, 0, 0},
- {&__pyx_n_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 1},
+ {&__pyx_kp_u_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 1, 0, 0},
+ {&__pyx_n_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 1},
{&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
- {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
- {&__pyx_kp_u_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 1, 0, 0},
- {&__pyx_kp_u_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 1, 0, 0},
- {&__pyx_kp_u_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 1, 0, 0},
+ {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0},
+ {&__pyx_kp_u_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 1, 0, 0},
+ {&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0},
+ {&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0},
{&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
{&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
{&__pyx_n_s__X, __pyx_k__X, sizeof(__pyx_k__X), 0, 0, 1, 1},
@@ -3488,12 +3400,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__byteorder, __pyx_k__byteorder, sizeof(__pyx_k__byteorder), 0, 0, 1, 1},
{&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1},
{&__pyx_n_s__descr, __pyx_k__descr, sizeof(__pyx_k__descr), 0, 0, 1, 1},
- {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1},
{&__pyx_n_s__empty, __pyx_k__empty, sizeof(__pyx_k__empty), 0, 0, 1, 1},
{&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1},
{&__pyx_n_s__fit, __pyx_k__fit, sizeof(__pyx_k__fit), 0, 0, 1, 1},
- {&__pyx_n_s__float64, __pyx_k__float64, sizeof(__pyx_k__float64), 0, 0, 1, 1},
{&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1},
+ {&__pyx_n_s__init, __pyx_k__init, sizeof(__pyx_k__init), 0, 0, 1, 1},
{&__pyx_n_s__itemsize, __pyx_k__itemsize, sizeof(__pyx_k__itemsize), 0, 0, 1, 1},
{&__pyx_n_s__minleafsize, __pyx_k__minleafsize, sizeof(__pyx_k__minleafsize), 0, 0, 1, 1},
{&__pyx_n_s__names, __pyx_k__names, sizeof(__pyx_k__names), 0, 0, 1, 1},
@@ -3502,14 +3413,14 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1},
{&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1},
{&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1},
- {&__pyx_n_s__ones, __pyx_k__ones, sizeof(__pyx_k__ones), 0, 0, 1, 1},
{&__pyx_n_s__predict, __pyx_k__predict, sizeof(__pyx_k__predict), 0, 0, 1, 1},
{&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
{&__pyx_n_s__readonly, __pyx_k__readonly, sizeof(__pyx_k__readonly), 0, 0, 1, 1},
{&__pyx_n_s__recursive_split, __pyx_k__recursive_split, sizeof(__pyx_k__recursive_split), 0, 0, 1, 1},
{&__pyx_n_s__root, __pyx_k__root, sizeof(__pyx_k__root), 0, 0, 1, 1},
{&__pyx_n_s__sample_weight, __pyx_k__sample_weight, sizeof(__pyx_k__sample_weight), 0, 0, 1, 1},
{&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1},
+ {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1},
{&__pyx_n_s__strides, __pyx_k__strides, sizeof(__pyx_k__strides), 0, 0, 1, 1},
{&__pyx_n_s__suboffsets, __pyx_k__suboffsets, sizeof(__pyx_k__suboffsets), 0, 0, 1, 1},
{&__pyx_n_s__thisptr, __pyx_k__thisptr, sizeof(__pyx_k__thisptr), 0, 0, 1, 1},
@@ -3535,12 +3446,12 @@ static int __Pyx_InitCachedConstants(void) {
*
* if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
*/
- __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_5));
- __Pyx_INCREF(((PyObject *)__pyx_kp_u_4));
- PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_u_4));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_4));
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_u_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_u_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
/* "numpy.pxd":210
* if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
@@ -3549,12 +3460,12 @@ static int __Pyx_InitCachedConstants(void) {
*
* info.buf = PyArray_DATA(self)
*/
- __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7));
- __Pyx_INCREF(((PyObject *)__pyx_kp_u_6));
- PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_u_6));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_6));
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7));
+ __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_u_5));
+ PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_u_5));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_5));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));
/* "numpy.pxd":248
* if ((descr.byteorder == '>' and little_endian) or
@@ -3563,12 +3474,12 @@ static int __Pyx_InitCachedConstants(void) {
* if t == NPY_BYTE: f = "b"
* elif t == NPY_UBYTE: f = "B"
*/
- __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_9));
- __Pyx_INCREF(((PyObject *)__pyx_kp_u_8));
- PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_kp_u_8));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_8));
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9));
+ __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_8));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_u_7));
+ PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_u_7));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_7));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
/* "numpy.pxd":787
*
@@ -3577,12 +3488,12 @@ static int __Pyx_InitCachedConstants(void) {
*
* if ((child.byteorder == '>' and little_endian) or
*/
- __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12));
- __Pyx_INCREF(((PyObject *)__pyx_kp_u_11));
- PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_kp_u_11));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_11));
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
+ __pyx_k_tuple_11 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_11));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_u_10));
+ PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, ((PyObject *)__pyx_kp_u_10));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_10));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
/* "numpy.pxd":791
* if ((child.byteorder == '>' and little_endian) or
@@ -3591,12 +3502,12 @@ static int __Pyx_InitCachedConstants(void) {
* # One could encode it in the format string and have Cython
* # complain instead, BUT: < and > in format strings also imply
*/
- __pyx_k_tuple_13 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_13));
- __Pyx_INCREF(((PyObject *)__pyx_kp_u_8));
- PyTuple_SET_ITEM(__pyx_k_tuple_13, 0, ((PyObject *)__pyx_kp_u_8));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_8));
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13));
+ __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_u_7));
+ PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_kp_u_7));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_7));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
/* "numpy.pxd":811
* t = child.type_num
@@ -3605,12 +3516,12 @@ static int __Pyx_InitCachedConstants(void) {
*
* # Until ticket #99 is fixed, use integers to avoid warnings
*/
- __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_15));
- __Pyx_INCREF(((PyObject *)__pyx_kp_u_14));
- PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_u_14));
- __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_14));
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15));
+ __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_14));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_u_13));
+ PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_u_13));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_13));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));
/* "scikits/learn/decisiontree/libdecisiontree.pyx":40
* def fit(np.ndarray[np.float64_t, ndim=2, mode='c'] X,
@@ -3619,12 +3530,12 @@ static int __Pyx_InitCachedConstants(void) {
* int minleafsize = 10,
* int nbins = 0):
*/
- __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_17));
+ __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_16));
__Pyx_INCREF(__pyx_int_0);
- PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, __pyx_int_0);
+ PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, __pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
- __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16));
__Pyx_RefNannyFinishContext();
return 0;
__pyx_L1_error:;
@@ -3676,7 +3587,7 @@ PyMODINIT_FUNC PyInit_libdecisiontree(void)
#endif
/*--- Module creation code ---*/
#if PY_MAJOR_VERSION < 3
- __pyx_m = Py_InitModule4(__Pyx_NAMESTR("libdecisiontree"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_16), 0, PYTHON_API_VERSION);
+ __pyx_m = Py_InitModule4(__Pyx_NAMESTR("libdecisiontree"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_15), 0, PYTHON_API_VERSION);
#else
__pyx_m = PyModule_Create(&__pyx_moduledef);
#endif
@@ -3735,7 +3646,7 @@ PyMODINIT_FUNC PyInit_libdecisiontree(void)
__pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -3750,21 +3661,21 @@ PyMODINIT_FUNC PyInit_libdecisiontree(void)
* np.ndarray[np.float64_t, ndim=1, mode='c'] Y,
* np.ndarray[np.float64_t, ndim=1, mode='c'] sample_weight = np.empty(0),
*/
- __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7scikits_5learn_12decisiontree_15libdecisiontree_fit, NULL, __pyx_n_s_18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7scikits_5learn_12decisiontree_15libdecisiontree_fit, NULL, __pyx_n_s_17); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__fit, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "scikits/learn/decisiontree/libdecisiontree.pyx":72
+ /* "scikits/learn/decisiontree/libdecisiontree.pyx":68
* return root
*
* def predict(np.ndarray[np.float64_t, ndim=2, mode='c'] X, # <<<<<<<<<<<<<<
* PyNode root):
* """
*/
- __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7scikits_5learn_12decisiontree_15libdecisiontree_1predict, NULL, __pyx_n_s_18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7scikits_5learn_12decisiontree_15libdecisiontree_1predict, NULL, __pyx_n_s_17); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__predict, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__predict, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "scikits/learn/decisiontree/libdecisiontree.pyx":1
@@ -4425,32 +4336,6 @@ static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
__Pyx_ReleaseBuffer(info);
}
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
- PyObject *result;
- result = PyObject_GetAttr(dict, name);
- if (!result)
- PyErr_SetObject(PyExc_NameError, name);
- return result;
-}
-
-static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
- if (unlikely(!type)) {
- PyErr_Format(PyExc_SystemError, "Missing type object");
- return 0;
- }
- if (likely(PyObject_TypeCheck(obj, type)))
- return 1;
- PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
- Py_TYPE(obj)->tp_name, type->tp_name);
- return 0;
-}
-
-static void __Pyx_RaiseBufferFallbackError(void) {
- PyErr_Format(PyExc_ValueError,
- "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
-}
-
-
static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET();
@@ -4478,6 +4363,32 @@ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyOb
}
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result)
+ PyErr_SetObject(PyExc_NameError, name);
+ return result;
+}
+
+static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+ if (unlikely(!type)) {
+ PyErr_Format(PyExc_SystemError, "Missing type object");
+ return 0;
+ }
+ if (likely(PyObject_TypeCheck(obj, type)))
+ return 1;
+ PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
+ Py_TYPE(obj)->tp_name, type->tp_name);
+ return 0;
+}
+
+static void __Pyx_RaiseBufferFallbackError(void) {
+ PyErr_Format(PyExc_ValueError,
+ "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
+}
+
+
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
Py_XINCREF(type);
@@ -4678,6 +4589,143 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
return module;
}
+#if PY_MAJOR_VERSION < 3
+static PyObject *__Pyx_GetStdout(void) {
+ PyObject *f = PySys_GetObject((char *)"stdout");
+ if (!f) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+ }
+ return f;
+}
+
+static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
+ PyObject* v;
+ int i;
+
+ if (!f) {
+ if (!(f = __Pyx_GetStdout()))
+ return -1;
+ }
+ for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
+ if (PyFile_SoftSpace(f, 1)) {
+ if (PyFile_WriteString(" ", f) < 0)
+ return -1;
+ }
+ v = PyTuple_GET_ITEM(arg_tuple, i);
+ if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
+ return -1;
+ if (PyString_Check(v)) {
+ char *s = PyString_AsString(v);
+ Py_ssize_t len = PyString_Size(v);
+ if (len > 0 &&
+ isspace(Py_CHARMASK(s[len-1])) &&
+ s[len-1] != ' ')
+ PyFile_SoftSpace(f, 0);
+ }
+ }
+ if (newline) {
+ if (PyFile_WriteString("\n", f) < 0)
+ return -1;
+ PyFile_SoftSpace(f, 0);
+ }
+ return 0;
+}
+
+#else /* Python 3 has a print function */
+
+static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
+ PyObject* kwargs = 0;
+ PyObject* result = 0;
+ PyObject* end_string;
+ if (unlikely(!__pyx_print)) {
+ __pyx_print = __Pyx_GetAttrString(__pyx_b, "print");
+ if (!__pyx_print)
+ return -1;
+ }
+ if (stream) {
+ kwargs = PyDict_New();
+ if (unlikely(!kwargs))
+ return -1;
+ if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0))
+ goto bad;
+ if (!newline) {
+ end_string = PyUnicode_FromStringAndSize(" ", 1);
+ if (unlikely(!end_string))
+ goto bad;
+ if (PyDict_SetItemString(kwargs, "end", end_string) < 0) {
+ Py_DECREF(end_string);
+ goto bad;
+ }
+ Py_DECREF(end_string);
+ }
+ } else if (!newline) {
+ if (unlikely(!__pyx_print_kwargs)) {
+ __pyx_print_kwargs = PyDict_New();
+ if (unlikely(!__pyx_print_kwargs))
+ return -1;
+ end_string = PyUnicode_FromStringAndSize(" ", 1);
+ if (unlikely(!end_string))
+ return -1;
+ if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) {
+ Py_DECREF(end_string);
+ return -1;
+ }
+ Py_DECREF(end_string);
+ }
+ kwargs = __pyx_print_kwargs;
+ }
+ result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
+ if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
+ Py_DECREF(kwargs);
+ if (!result)
+ return -1;
+ Py_DECREF(result);
+ return 0;
+bad:
+ if (kwargs != __pyx_print_kwargs)
+ Py_XDECREF(kwargs);
+ return -1;
+}
+
+#endif
+
+#if PY_MAJOR_VERSION < 3
+
+static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
+ if (!f) {
+ if (!(f = __Pyx_GetStdout()))
+ return -1;
+ }
+ if (PyFile_SoftSpace(f, 0)) {
+ if (PyFile_WriteString(" ", f) < 0)
+ return -1;
+ }
+ if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
+ return -1;
+ if (PyFile_WriteString("\n", f) < 0)
+ return -1;
+ return 0;
+ /* the line below is just to avoid compiler
+ * compiler warnings about unused functions */
+ return __Pyx_Print(f, NULL, 0);
+}
+
+#else /* Python 3 has a print function */
+
+static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
+ int res;
+ PyObject* arg_tuple = PyTuple_New(1);
+ if (unlikely(!arg_tuple))
+ return -1;
+ Py_INCREF(o);
+ PyTuple_SET_ITEM(arg_tuple, 0, o);
+ res = __Pyx_Print(stream, arg_tuple, 1);
+ Py_DECREF(arg_tuple);
+ return res;
+}
+
+#endif
+
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_Py_intptr_t(Py_intptr_t val) {
const Py_intptr_t neg_one = (Py_intptr_t)-1, const_zero = (Py_intptr_t)0;
const int is_unsigned = const_zero < neg_one;
View
13 scikits/learn/decisiontree/libdecisiontree.pyx
@@ -20,7 +20,6 @@ cdef extern from "Node.h":
cdef cppclass Node:
Node()
void recursive_split(int, int)
- double predict(double*)
cdef class PyNode:
cdef Node *thisptr
@@ -58,16 +57,12 @@ def fit(np.ndarray[np.float64_t, ndim=2, mode='c'] X,
"""
cdef PyNode root
- if len(sample_weight) == 0:
- sample_weight = np.ones(X.shape[0], dtype=np.float64)
- else:
- assert sample_weight.shape[0] == X.shape[0], \
- "sample_weight and X have incompatible shapes: " + \
- "sample_weight has %s samples while X has %s" % \
- (sample_weight.shape[0], X.shape[0])
-
+ root = PyNode()
+ print "init"
init_root(X.data, Y.data, sample_weight.data, X.shape, root.thisptr)
+ print "split"
root.thisptr.recursive_split(minleafsize, nbins)
+ print "done split"
return root
def predict(np.ndarray[np.float64_t, ndim=2, mode='c'] X,
View
4 scikits/learn/decisiontree/src/Node.cpp
@@ -1,4 +1,5 @@
#include "Node.h"
+#include <iostream>
double Node::predict(const double* attrs) const
{
@@ -18,6 +19,7 @@ double Node::predict(const double* attrs) const
void Node::recursive_split(unsigned int min_leaf_size, unsigned int bins)
{
+ std::cout << "SPLIT" << std::endl;
if (this->split(min_leaf_size, bins))
{
this->left_child->recursive_split(min_leaf_size, bins);
@@ -81,7 +83,7 @@ bool Node::split(unsigned int min_leaf_size, unsigned int bins)
pair<double,double> extrema;
Histogram<double,double>* sigHist;
Histogram<double,double>* bkgHist;
- float bestGini = -1;
+ float bestGini(-1.);
for (unsigned int i(0); i < numAttributes; ++i)
{
// get max and min value of this attribute over signal and background combined
View
14 testbdt.py
@@ -1,10 +1,18 @@
from scikits.learn.decisiontree import DecisionTree
import numpy as np
-a = DecisionTree(minleafsize=1)
+a = DecisionTree(minleafsize=10)
-x = np.array([[.3, .4, .2] for i in xrange(100)])
+cov = [[1,.5],[.5,1]]
+X_bkg = np.random.multivariate_normal([.5,.5], cov, 1000)
+X_sig = np.random.multivariate_normal([-.5,-.5], cov, 1000)
+
+x = np.append(X_sig, X_bkg)
+x = np.reshape(x, (2000,-1))
print x.shape
-y = np.append(np.ones(50),-np.ones(50))
+y = np.append(np.ones(1000),-np.ones(1000))
+print y.shape
a.fit(x,y)
+
+print a.predict(x)

0 comments on commit a097bf8

Please sign in to comment.
Something went wrong with that request. Please try again.