[scikit-learn] running examples

David Nicholson nicholdav at gmail.com
Tue Mar 23 23:18:41 EDT 2021


Looks like you need to install pandas for this example--`fetch_openl` is
trying to give you back a pandas DataFrame

https://scikit-learn.org/stable/modules/generated/sklearn.datasets.fetch_openml.html#sklearn.datasets.fetch_openml

not sure if you could just run it with as_frame = False

David Nicholson, Ph.D.
https://nicholdav.info/
https://github.com/NickleDave
Prinz lab <http://www.biology.emory.edu/research/Prinz/>, Emory University,
Atlanta, GA, USA


On Tue, Mar 23, 2021 at 10:57 PM James Bunn <leibniz01 at gmail.com> wrote:

> Hi,
>
> I am a new user trying to run the Visualization of MLP weights on MNIST
> example for neural networks.
>
> I am not able to get the example to run.  I loaded the scikitlearn and
> matplotlib packages called in the program, but still it will not work.
>
> Is there any more I need to do?
>
> My error text is below.
>
> Thank you,
>
> James
>
> "C:\Users\James\PycharmProjects\MATH541 Project\venv\Scripts\python.exe"
> C:/Users/James/Documents/MATH541/plot_mnist_filters.py
> C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py:65:
> RuntimeWarning: Invalid cache, redownloading file
>   warn("Invalid cache, redownloading file", RuntimeWarning)
>
> =====================================
> Visualization of MLP weights on MNIST
> =====================================
>
> Sometimes looking at the learned coefficients of a neural network can
> provide
> insight into the learning behavior. For example if weights look
> unstructured,
> maybe some were not used at all, or if very large coefficients exist, maybe
> regularization was too low or the learning rate too high.
>
> This example shows how to plot some of the first layer weights in a
> MLPClassifier trained on the MNIST dataset.
>
> The input data consists of 28x28 pixel handwritten digits, leading to 784
> features in the dataset. Therefore the first layer weight matrix have the
> shape
> (784, hidden_layer_sizes[0]).  We can therefore visualize a single column
> of
> the weight matrix as a 28x28 pixel image.
>
> To make the example run faster, we use very few hidden units, and train
> only
> for a very short time. Training longer would result in weights with a much
> smoother spatial appearance. The example will throw a warning because it
> doesn't converge, in this case this is what we want because of CI's time
> constraints.
>
> Traceback (most recent call last):
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\utils\__init__.py", line 1081, in
> check_pandas_support
>     import pandas  # noqa
> ModuleNotFoundError: No module named 'pandas'
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 61, in
> wrapper
>     return f(*args, **kw)
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 518, in
> _load_arff_response
>     parsed_arff = parse_arff(arff)
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 332, in
> _convert_arff_data_dataframe
>     pd = check_pandas_support('fetch_openml with as_frame=True')
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\utils\__init__.py", line 1084, in
> check_pandas_support
>     raise ImportError(
> ImportError: fetch_openml with as_frame=True requires pandas.
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\utils\__init__.py", line 1081, in
> check_pandas_support
>     import pandas  # noqa
> ModuleNotFoundError: No module named 'pandas'
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "C:\Users\James\Documents\MATH541\plot_mnist_filters.py", line 36,
> in <module>
>     X, y = fetch_openml('mnist_784', version=1, return_X_y=True)
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\utils\validation.py", line 63, in
> inner_f
>     return f(*args, **kwargs)
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 915, in
> fetch_openml
>     bunch = _download_data_to_bunch(url, return_sparse, data_home,
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 633, in
> _download_data_to_bunch
>     out = _retry_with_clean_cache(url, data_home)(
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 69, in
> wrapper
>     return f(*args, **kw)
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 518, in
> _load_arff_response
>     parsed_arff = parse_arff(arff)
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\datasets\_openml.py", line 332, in
> _convert_arff_data_dataframe
>     pd = check_pandas_support('fetch_openml with as_frame=True')
>   File "C:\Users\James\PycharmProjects\MATH541
> Project\venv\lib\site-packages\sklearn\utils\__init__.py", line 1084, in
> check_pandas_support
>     raise ImportError(
> ImportError: fetch_openml with as_frame=True requires pandas.
>
> Process finished with exit code 1
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scikit-learn/attachments/20210323/c71a18ee/attachment-0001.html>


More information about the scikit-learn mailing list