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

hanzi mao hzmao at hotmail.com
Tue Sep 5 00:26:09 EDT 2017


Thanks Sebastian and Joel!


It works after I run the codes in the newly created virtual environment. I thought after the sources were compiled, it was ok to change the folder name.


Also thanks for teaching me to use the virtual environment!


Best,

Hanna


________________________________
From: scikit-learn <scikit-learn-bounces+hzmao=hotmail.com at python.org> on behalf of Sebastian Raschka <se.raschka at gmail.com>
Sent: Monday, September 4, 2017 11:29 PM
To: Scikit-learn mailing list
Subject: Re: [scikit-learn] Problem found when testing DecisionTreeClassifier within the source folder

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.
12. Virtual Environments and Packages — Python 3.6.2 ...<https://docs.python.org/3/tutorial/venv.html>
docs.python.org
12.1. Introduction¶ Python applications will often use packages and modules that don’t come as part of the standard library. Applications will sometimes need a ...




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 Info Page - Python<https://mail.python.org/mailman/listinfo/scikit-learn>
mail.python.org
To see the collection of prior postings to the list, visit the scikit-learn Archives. Using scikit-learn: To post a message to all the list members ...



>
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
scikit-learn Info Page - Python<https://mail.python.org/mailman/listinfo/scikit-learn>
mail.python.org
To see the collection of prior postings to the list, visit the scikit-learn Archives. Using scikit-learn: To post a message to all the list members ...




_______________________________________________
scikit-learn mailing list
scikit-learn at python.org
https://mail.python.org/mailman/listinfo/scikit-learn
scikit-learn Info Page - Python<https://mail.python.org/mailman/listinfo/scikit-learn>
mail.python.org
To see the collection of prior postings to the list, visit the scikit-learn Archives. Using scikit-learn: To post a message to all the list members ...



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170905/c653952d/attachment-0001.html>


More information about the scikit-learn mailing list