Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeprecationWarning: numpy.core.umath_tests

I'm trying to run this python script below:

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score from sklearn.metrics import confusion_matrix

It gives me the error below.

Warning (from warnings module): File "C:\Users\Dipali\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\ensemble\weight_boosting.py", line 29 from numpy.core.umath_tests import inner1d DeprecationWarning: numpy.core.umath_tests is an internal NumPy module and should not be imported. It will be removed in a future NumPy release.

What I need to do?

like image 452
dipali Avatar asked Aug 23 '18 12:08

dipali


2 Answers

You can ignore warning following ways like below

Example1:

#!/usr/bin/env python -W ignore::DeprecationWarning

Example2:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning) 

Example 3:

import warnings

def fxn():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()
like image 149
Ganesan Karuppasamy Avatar answered Sep 28 '22 08:09

Ganesan Karuppasamy


Alright so this is a deprecation warning on Python 3.x.
Since, this is warning your code will run fine. It is not an error (When the code stops running by graceful degradation).

The solution to remove this error is as follow:

  1. As I can see you have Scikit-Learn version 0.19.2 installed you need to get the latest version. To do so enter the following command
    pip3 install --force-reinstall scikit-learn==0.20rc1
    This will install the latest versions of scikit-learn, scipy and numpy. Your deprecation warnings will now not exist.

  2. Although you'll next get a new warning. This time regarding the file in the scikit-learn library called cloudpickle \sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py.
    To overcome this warning you got to edit the code which python shows us.
    Just do a sudo idle3 onto the file and edit the lines which says :
    import imp
    from imp import find_module
    to
    import importlib
    Next go to the funtion find_module and change the line
    file, path, description = find_module(path)
    to
    file, path, description = importlib.utils.find_spec(path).

This must solve the deprecation warnings in the scikit-learn libraries.

like image 21
Chandra Kanth Avatar answered Sep 28 '22 09:09

Chandra Kanth