Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSError: [Errno 9] Bad file descriptor using GridSearchCV

I'm having little hard times figure out what's the problem with my code. I'm a newbie in the fabulous world of python, so forgive me for any kind of syntax problem. Thanks to anyone who's gonna spend his time to help me. Here's my code:

X_train=np.random.randn(4000,400)

y_train=np.random.randn(4000)

parameters={
    "solver":("auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga"),

    "tol":[1e-3,1e-5,1e-8],

    "alpha":[1,1.2,1.4,1.5],

    "random_state":[42]

}

reg= Ridge()

clf = GridSearchCV(reg, parameters,scoring="r2", n_jobs=-1,cv=5)

clf.fit(X_train,y_train) **here's where troubles happen**

print(clf.best_score_)

print(clf.best_params_)

And here is the error:

File"/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 290, in _on_run

r = self.sock.recv(1024)

OSError: [Errno 9] Bad file descriptor
like image 696
wrong_tactic Avatar asked Nov 22 '25 20:11

wrong_tactic


1 Answers

The problem is because of the argument n_jobs=-1. It means, the computer can use all cores available, and certains algorithms in several scenarios it raises an error.

Check this sentence:

clf = GridSearchCV(reg, parameters, scoring="r2", cv=5)
like image 103
Julio CamPlaz Avatar answered Nov 24 '25 11:11

Julio CamPlaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!