標準化の統計量
次のコードを実行したときの出力として、正しいものを1つ選べ。
import numpy as np
from sklearn.preprocessing import StandardScaler
s = StandardScaler().fit(np.array([[1.0], [3.0]]))
print(float(s.mean_[0]), float(s.scale_[0]))
- A
1.0 2.0 - B
2.0 1.414 - C
3.0 1.0 - D
2.0 1.0
正解と解説を見る
正解:D
StandardScaler は、fit で平均(mean_)と標準偏差(scale_)を求める。標準偏差は n で割る母標準偏差。訓練データで fit する。
| 順 | 実行する行 | 実行後の変数 |
|---|---|---|
| 1 | `import numpy as np` | — |
| 2 | `from sklearn.preprocessing import StandardSca…` | — |
| 3 | `s = StandardScaler().fit(np.array([[1.0], [3.…` | — |
| 4 | `print(float(s.mean_[0]), float(s.scale_[0]))` | — |
| 結果 | 実際の出力 | 2.0 1.0 |
- A
誤り。平均と標準偏差が逆。
- B
誤り。
StandardScalerは母標準偏差(n で割る)を使う。 - C
誤り。平均は 2。
- D
正しい。平均は 2、標準偏差は 1(母標準偏差)。
fitで求めた値が、transformで使われる。
このサイトの問題は、各試験の公式に示された出題範囲に沿って作ったオリジナルの模擬問題です。本試験の問題ではありません。一般社団法人Pythonエンジニア育成推進協会の公式サービスではありません。