如何在python中从多处理中提取预测?
我正在尝试对svm的结果进行多重处理 我尝试了以下简单的方法如何在python中从多处理中提取预测?,python,multithreading,multiprocessing,Python,Multithreading,Multiprocessing,我正在尝试对svm的结果进行多重处理 我尝试了以下简单的方法 clf = svm.SVC(C=1.0, cache_size=1000000, class_weight=None, coef0=0.0, decision_function_shape='ovo', degree=3, gamma='auto', kernel='rbf', max_iter=-1, probability=False, random_state=None, shrinking=True,
clf = svm.SVC(C=1.0, cache_size=1000000, class_weight=None, coef0=0.0,
decision_function_shape='ovo', degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
clf.fit(x, y)
def predict(x):
clf.predict(x)
from multiprocessing import Pool
pool= Pool(processes = 4)
setting = np.loadtxt('~/test.csv', delimiter=',')
x=setting[:,0:3]
y=setting[:,3]
x[i]
[cols,rows] = setting.shape
i = 0
while i < rows:
k = x[i]
pool.map(predict,[[k]])
print(pool.map(predict,[[k]]))
i = i+1
clf=svm.SVC(C=1.0,缓存大小=1000000,类权重=None,coef0=0.0,
决策函数(shape='ovo',degree=3,gamma='auto',kernel='rbf',,
最大值=1,概率=假,随机状态=无,收缩=真,
tol=0.001,详细=False)
clf.配合(x,y)
def预测(x):
clf.predict(x)
来自多处理导入池
池=池(进程=4)
设置=np.loadtxt(“~/test.csv”,分隔符=”,“)
x=设置[:,0:3]
y=设置[:,3]
x[i]
[cols,rows]=设置.shape
i=0
而我是:
k=x[i]
map(预测,[[k]])
打印(pool.map(predict,[[k]]))
i=i+1
此代码将运行,但似乎没有正确的结果
我想返回或打印预测值
如果您能提供获得预测值结果的方法或代码,我将不胜感激。setting.shape将返回一个元组(m,n),其中m是行数,n是列数。看来你的情况正好相反 试着把你的线路改成
[rows, cols] = setting.shape
此外,您可能希望尝试将预测数据拆分为大小相等的矩阵,每个矩阵都有行/进程条目,并在其上进行映射。逐行共享的开销可能不值得。您能给我一些代码来尝试您推荐的方法吗?当我尝试这些代码时,预测值都是零。输入类型或方法是否有问题?请参阅以下答案: