Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何加快交叉评分?_Python_Python 3.x_Scikit Learn_Cross Validation - Fatal编程技术网

Python 如何加快交叉评分?

Python 如何加快交叉评分?,python,python-3.x,scikit-learn,cross-validation,Python,Python 3.x,Scikit Learn,Cross Validation,我想使用sklearn.model\u selection.cross\u val\u score在MNIST数据集上评估SGDClassizer。 我用了大约6分钟的时间打了3折。 如何使用全系统电源(我的意思是使用从CPU到图形卡等的所有设备)来加快进程 顺便说一下,我在监控CPU使用情况时,它只使用了54%的电源 from sklearn.datasets import fetch_openml from sklearn.linear_model import SGDClassifier

我想使用
sklearn.model\u selection.cross\u val\u score
在MNIST数据集上评估SGDClassizer。 我用了大约6分钟的时间打了3折。 如何使用全系统电源(我的意思是使用从CPU到图形卡等的所有设备)来加快进程 顺便说一下,我在监控CPU使用情况时,它只使用了54%的电源

from sklearn.datasets import fetch_openml
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import cross_val_score

mnist = fetch_openml('mnist_784')
X, y = mnist['data'], mnist['target']
X_train, X_test, y_train, y_test = X[:60000], X[60000:], y[:60000], y[60000:]
y_train_5 = (y_train == 5)
y_test_5 = (y_test == 5)

sgd_clf = SGDClassifier(random_state=42)
sgd_clf.fit(X_train, y_train)

cross_val_score(sgd_clf, X_train, y_train, cv=3, scoring='accuracy')
从:

n\u作业:int或None,可选(默认为None)

用于执行计算的CPU数。None表示1,除非在joblib.parallel_后端上下文中-1表示使用所有处理器

i、 e.您可以使用所有可用的内核

cross_val_score(sgd_clf, X_train, y_train, cv=3, scoring='accuracy', n_jobs=-1)
或者指定一些其他值
n_jobs=k
,如果使用所有内核会使您的机器速度变慢或无响应


这将使用更多的CPU核;据我所知,scikit中没有学习将计算卸载到GPU的功能。

尝试将
n_jobs=x
放置在
x>1
内部
交叉值得分
。不确定它是否有效,但您知道sklearn是否在工作进程之间共享数据集或为每个工作进程复制数据集吗?否则,这可能会导致内存不足error@ShihabShahriarKhan我想它是共享的,但不确定,你最好检查一下,看看进展如何