給定以下 Python 資料結構: 中的行數與 中df的值相同labels。
df =
[[0.003 0.9238 0.3882 0.3823]
[0.0383 0.2382 0.8328 0.3823]
...
[0.723 0.3282 0.1372 0.3723]]
labels = [0 1 0 0 ... 2]
我有一個 score 函式,給定 adf和 its labels,計算一個指標的值。問題是它不可擴展,我想通過隨機抽取 100 個人的平均值來近似其結果。
seed = 12345
N = 5
score_sum = 0
# Make Perform N times and average
for i in range(0, N):
# Suffle df and labels in the same way and select 100 points
score_sum = score(subset_df, subset_labels)
score_sum = score_sum / N
表示shuffle后,df和labels需要選擇相同的索引。
uj5u.com熱心網友回復:
你可以有:
seed = 12345
N = 5
score_sum = 0
# Make Perform N times and average
for i in range(0, N):
rnd_indices = np.random.choice(len(df), size=100, replace=False)
subset_df, subset_labels = df[rnd_indices], labels[rnd_indices]
score_sum = score(subset_df, subset_labels)
score_sum = score_sum / N
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/487601.html
上一篇:以每行的最大值反轉順序
