gpt4 book ai didi

python - 如何修复 sklearn.model_selection 的 GridSearchCV 库中已启动的运行时错误

转载 作者:行者123 更新时间:2023-11-30 08:39:33 25 4
gpt4 key购买 nike

我正在使用 svm 对新闻组主题进行分类。我正在提供最好的解决方案来对这些数据进行分类。请帮助删除这个错误,它阻止了我的整个项目。在这里,当我通过 GridSearchCV 库调用拟合方法时,它显示了错误,我已经提到了错误出现后的代码。

from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.corpus import names
from nltk.stem import WordNetLemmatizer
from sklearn.svm import SVC

categories=None

tfidf_vectorizer=TfidfVectorizer(stop_words="english",max_features=None)

all_names = set(names.words())
lemmatizer = WordNetLemmatizer()

def letters_only(astr):
return astr.isalpha()

def clean_text(docs):
cleaned_docs = []
for doc in docs:
cleaned_docs.append(' '.join([lemmatizer.lemmatize(word.lower())
for word in doc.split()
if letters_only(word)
and word not in all_names]))
return cleaned_docs

data_train=fetch_20newsgroups(subset='train',categories=categories,random_state=42)
data_test=fetch_20newsgroups(subset='test',categories=categories,random_state=42)
cleaned_train=clean_text(data_train.data)
label_train=data_train.target
cleaned_test=clean_text(data_test.data)
label_test=data_test.target
term_docs_train=tfidf_vectorizer.fit_transform(cleaned_train)
term_docs_test=tfidf_vectorizer.fit_transform(cleaned_test)


svc_libsvm=SVC(kernel='linear')
parameters={'C':(0.1,1,10,100)}

from sklearn.model_selection import GridSearchCV
grid_search=GridSearchCV(svc_libsvm,parameters,n_jobs= -1,cv=5)

import timeit
start_time=timeit.default_timer()
print(start_time)
grid_search.fit(term_docs_train,label_train)'''the error come after this statement'''

print("--- %0.3fs seconds ---"% (timeit.default_timer() - start_time))

grid_search.best_params_
grid_search.best_score_
svc_libsvm_best=grid_search.best_estimator_
accuracy=svc_libsvm_best.score(term_docs_test,label_test)
print('the accuracy of 20_class classification is:{0:.1f}%'.format(accuracy*100))```

E00115.534: Exception escaped from start_client

Traceback (most recent call last):
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/log.py", line 110, in g
return f(*args, **kwargs)
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/pydevd_hooks.py", line 74, in start_client
sock, start_session = daemon.start_client((host, port))
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/daemon.py", line 214, in start_client
with self.started():
File "/home/alok/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/daemon.py", line 110, in started
self.start()
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/daemon.py", line 145, in start
raise RuntimeError('already started')
RuntimeError: already started


Traceback (most recent call last):

Traceback (most recent call last):
/home/alok/anaconda3/lib/python3.7/site-packages/sklearn/externals/joblib/externals/loky/backend/semaphore_tracker.py:74: UserWarning: semaphore_tracker: process died unexpectedly, relaunching. Some semaphores might leak.
warnings.warn('semaphore_tracker: process died unexpectedly, '
E00115.575: Exception escaped from start_client

Traceback (most recent call last):
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/log.py", line 110, in g
return f(*args, **kwargs)
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/pydevd_hooks.py", line 74, in start_client
sock, start_session = daemon.start_client((host, port))
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/daemon.py", line 214, in start_client
with self.started():
File "/home/alok/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/daemon.py", line 110, in started
self.start()
File "/home/alok/.vscode/extensions/ms-python.python-2019.3.6558/pythonFiles/lib/python/ptvsd/daemon.py", line 145, in start
raise RuntimeError('already started')
RuntimeError: already started


Traceback (most recent call last):

Traceback (most recent call last):
Terminated

最佳答案

就我个人而言,我发现只有当我在 Debug模式下通过 VSCode 运行代码时才会出现此问题。如果我只是从 VSCode 内的终端运行它,它就可以正常运行

关于python - 如何修复 sklearn.model_selection 的 GridSearchCV 库中已启动的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55813441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com