Skip to content

RecursionError: maximum recursion depth exceeded while calling a Python object #4081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MetteHJo opened this issue Feb 11, 2021 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@MetteHJo
Copy link

Similar to #3746 I get "RecursionError: maximum recursion depth exceeded while calling a Python object"

Steps to reproduce

This is my code:

import warnings
warnings.filterwarnings('ignore')
import time
import numpy as np
import pandas as pd
import pickle as pk
import seaborn as sns
import matplotlib.pyplot as plt
import xgboost

from datetime import datetime
from sklearn.svm import SVC
from sklearn.model_selection import StratifiedKFold
from xgboost import XGBClassifier
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split, GridSearchCV, RandomizedSearchCV, cross_val_score
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score, accuracy_score, classification_report, cohen_kappa_score,confusion_matrix
from sklearn.preprocessing import MinMaxScaler

start_time = time.time()

#declare contants
kfold = 10

#helper modules for descriptive statistics
def get_redundant_pairs(df):
pairs_to_drop = set()
cols = df.columns
for i in range(0, df.shape(1)):
for j in range(0, i+1):
pairs_to_drop.add((cols(i), cols(j)))
return pairs_to_drop

def get_top_abs_correlations(df, n=5):
au_corr =df.corr().unstack()
labels_to_drop = get_redundant_pairs(df)
au_corr = au_corr.drop(labels=labels_to_drop).sort_values(accending=False)
return au_corr[0:n]

def corrank(X):
import itertools
df = pd.DataFrame([[(i,j),
X.corr().loc(i,j)] for i,j in list(itertools.combinations(X.corr(), 2))],
columns=[ 'pairs','corr'])
print(df.sort_values(by='corr',ascending=False))
print()

#load dataset
dataset=pd.read_csv("adult.csv")
dataset.head()
#removing '?' containing rows
dataset = dataset[(dataset != '?').all(axis=1)]
#label the income objects as 0 and 1
dataset['income']=dataset['income'].map({'<=50K': 0, '>50K': 1})

#Reformating marital.status values to single and married
dataset['marital-status']=dataset['marital-status'].map({'Married-civ-spouse':'Married', 'Divorced':'Single', 'Never-married':'Single', 'Separated':'Single',
'Widowed':'Single', 'Married-spouse-absent':'Married', 'Married-AF-spouse':'Married'})

#normalizing data to be between 0 and 1
for column in dataset:
enc=LabelEncoder()
if dataset.dtypes[column]==np.object:
dataset[column]=enc.fit_transform(dataset[column])

X=dataset.iloc[:,0:-1] #feature_name
y=dataset.iloc[:,-1]

print(X.head())
print(y.head())

#Split data
x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2,shuffle=False)

#model training
def training_model (x_train, y_train):
model = xgboost.XGBClassifier(objective = 'binary:logistic', use_label_encoder=False)

parameters = {
    'min_child_weight': [0, 1, 5],
    'gamma': [0.2, 0.5, 1, 1.5, 3],
    'subsample': [0.6, 0.8, 1.0],
    'colsample_bytree': [0.6, 0.8, 1.0],
    'max_depth': [3, 4, 5],
    'learning_rate' : [0.01, 0.02, 0.5]
    }

grid =GridSearchCV(estimator=model, param_grid=parameters, cv =kfold,
                   verbose =1, n_jobs = -1, refit = True)
grid.fit(x_train, y_train)

#Result
print("result from Grid Seard")
print("""""""""""""""""""""""""""""""")
print("\n The best estimator across ALL search params: \n", grid.best_estimator_)
print("\n The best score across ALL search params: \n", grid.best_score_)
print("\n The best parameters across ALL search params: \n", grid.best_params_) 

return(grid.best_estimator_) 

model = training_model(x_train, y_train)

Current behavior

Getting error: RecursionError: maximum recursion depth exceeded while calling a Python object.
I see that it was similar to #3746 but that was on a diffrent pylint version.

Expected behavior

Code running.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.5

@Pierre-Sassoulas
Copy link
Member

Looke like a duplicate of #3602, #3986, #3985, #3982, #3977, #3952, #3913, #3836

A possible temporary solution to the problem was proposed here: #3836 (comment)

turns out this is a genuinely large recursion problem, and can be gotten around by putting the following in your pylintrc file:
init-hook='import sys; sys.setrecursionlimit(3 * sys.getrecursionlimit())'

The fix is in master and will be released soon(ish).

@Pierre-Sassoulas Pierre-Sassoulas added the Duplicate 🐫 Duplicate of an already existing issue label Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants