[scikit-learn] Problem found when testing DecisionTreeClassifier within the source folder

Sebastian Raschka se.raschka at gmail.com
Mon Sep 4 23:29:09 EDT 2017


Hi, Hanna,

I think Joel is right and the renaming is probably causing the issues. Instead of renaming the package to sklearn1, consider modifying, compiling, and installing sklearn in a virtual environment. I am not sure if you are using conda, in this case, creating a new virtual env for development would be really straight forward:

conda create -n 'my-sklearn-dev'
source activate my-sklearn-dev

There are also a bunch of Python packages out there that do essentially the same thing (https://docs.python.org/3/tutorial/venv.html); I am not sure which one people generally recommend/prefer. 

Anyway, to use venv that should be available in Python already, you could do e.g.,

python -m venv my-sklearn-dev
source my-sklearn-dev/bin/activate

Best,
Sebastian

> On Sep 4, 2017, at 11:21 PM, Joel Nothman <joel.nothman at gmail.com> wrote:
> 
> I suspect this is due to an intricacy of Cython. Despite using relative imports, Cython expects the Criterion instance to come from a package called sklearn, not called sklearn1.
> 
> On 5 September 2017 at 12:42, hanzi mao <hzmao at hotmail.com> wrote:
> 
> Hi,
> 
> I am researching on the source code of DecisionTree recently. Here are the things I tried.
> 
> 	• Downloaded source code from github. 
> 	• run "python setup.py build_ext --inplace" to compile the sources in the unzipped source folder.
> 	• Try the following codes to see whether it works. Here I changed the name of the sklearn folder to sklearn1 to differentiate it from the one installed. 
> 
> 
> 
> >>> from sklearn1 import tree
> 
> 
> >>> from sklearn.datasets import load_iris
> 
> 
> >>> iris = load_iris()
> 
> 
> >>> clf = tree.DecisionTreeClassifier()
> 
> 
> >>> clf = clf.fit(iris.data, iris.target)
> 
> 
> Traceback (most recent call last):
> 
> 
>   File "<stdin>", line 1, in <module>
> 
> 
>   File "sklearn1\tree\tree.py", line 790, in fit
> 
> 
>     X_idx_sorted=X_idx_sorted)
> 
> 
>   File "sklearn1\tree\tree.py", line 341, in fit
> 
> 
>     self.presort)
> 
> 
> TypeError: Argument 'criterion' has incorrect type (expected sklearn.tree._criterion.Criterion, got sklearn.tree._criterion.Gini)
> 
> 
> Then a weird error happened. Actually I also tried the newest stable version of scikit-learn earlier today. It had the same error. So I was thinking maybe try the newest version in github might help. Unlikely, it didn't.
> 
> I have limited knowledge about the source code of scikit-learn. I am wondering if anyone could help me with this.
> 
> Thanks!
> 
> Best,
> Hanna
> 
> 
> 
> 
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
> 
> 
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn



More information about the scikit-learn mailing list