【问题标题】:OSError: [Errno 9] Bad file descriptor using GridSearchCVOSError: [Errno 9] 使用 GridSearchCV 的文件描述符错误
【发布时间】:2021-04-29 18:23:10
【问题描述】:

我很难弄清楚我的代码有什么问题。 我是神话般的python世界的新手,所以请原谅我的任何语法问题。 感谢任何愿意花时间帮助我的人。 这是我的代码:

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_)

这是错误:

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

【问题讨论】:

    标签: python regression grid-search oserror


    【解决方案1】:

    问题在于参数n_jobs=-1。这意味着,计算机可以使用所有可用的内核,并且某些算法在某些情况下会引发错误。

    检查这句话:

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

    【讨论】:

      猜你喜欢
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 2020-08-28
      相关资源
      最近更新 更多