我正在使用開發版Python Python sklearn包與NN實現。 我的任務是培養4 NN與不同的輸入數據和平均預測使用python多處理sklearn NN
X_median = preprocessing.scale(data_median)
X_min = preprocessing.scale(data_min)
X_max = preprocessing.scale(data_max)
X_mean = preprocessing.scale(data_mean)
我創造一個神經網絡這樣
NN1 = MLPClassifier(hidden_layer_sizes = (50), activation = 'logistic', algorithm='adam', alpha= 0 , max_iter = 40, batch_size = 10, learning_rate = 'adaptive', shuffle = True, random_state=1)
NN2 = MLPClassifier(hidden_layer_sizes = (50), activation = 'logistic', algorithm='adam', alpha= 0 , max_iter = 40, batch_size = 10, learning_rate = 'adaptive', shuffle = True, random_state=1)
NN3 = MLPClassifier(hidden_layer_sizes = (50), activation = 'logistic', algorithm='adam', alpha= 0 , max_iter = 40, batch_size = 10, learning_rate = 'adaptive', shuffle = True, random_state=1)
NN4 = MLPClassifier(hidden_layer_sizes = (50), activation = 'logistic', algorithm='adam', alpha= 0 , max_iter = 40, batch_size = 10, learning_rate = 'adaptive', shuffle = True, random_state=1)
(標準sklearn功能)
,我想在上述數據集上進行訓練。 不使用游泳池我的代碼看起來就像這樣:
NN1.fit(X_mean,train_y)
NN2.fit(X_median,train_y)
NN3.fit(X_min,train_y)
NN4.fit(X_max,train_y)
當然,因爲所有的4培訓是獨立我想並行運行他們,我想我應該用池此。但是,我不完全理解計算是如何執行的。我會假設寫的是這樣的:
pool = Pool()
pool.apply_async(NN1.fit, args = (X_mean, train_y))
但是,這不會產生任何結果,我甚至可以像這樣輸入(通過只有一個參數),並計劃將完成沒有任何錯誤! pool.apply_async(NN1.fit, args = (X_mean,))
。
執行此類計算的正確方法是什麼? 有人可以建議良好的資源來理解Python多處理的用法嗎?
對於'apply_async',你需要提供一個回調函數來完成計算。我想你想要'apply()',它在返回之前等待計算。 – mirosval
的確,似乎這樣的代碼做的工作: '高清MYFUNC(MyNN,X,train_y): \t MyNN.fit(X,train_y) \t回MyNN' 然後 'NN_mean = pool.apply(MYFUNC ,(NN_mean,X_mean,train_y))' – Shir