Solution of Overfitting
Definition of Overfitting

:train setは正しいがvalidation/test setは正しくない
Regularization

定義
Lp norm

vector norm
i)pが自然数の場合

x=np.array([1,10,1,1,1])
p=5
norm_x=np.linalg.norm(x, ord=p)
making_norm = (sum(x**p))**(1/p)
print("result of numpy package norm function : %0.5f "%norm_x)
print("result of making norm : %0.5f "%making_norm)
ii)pが無限大の場合
norm_x=np.linalg.norm(x, ord=np.inf)
print("result of infinite norm : %0.5f "%norm_x)
matrix norm
:p=1,pが無限大であれば,把握すればよい.
i)p=1、最大の列と値を出力
ii)p無限大,Louの和出力最大値
:A=m*n行列

A=np.array([[1,2,3],[1,2,3],[4,6,8]])
inf_norm_A=np.linalg.norm(A, ord=np.inf)
print("result inf norm of A :", inf_norm_A)
one_norm_A=np.linalg.norm(A, ord=1)
print("result one norm of A :", one_norm_A)
L1 Regularization
式:

機能:
- 어떤 컬럼이 결과에 영향을 미치는지에 대해서 알 수 있다.

例:
plt.figure(figsize=(5,5))
plt.scatter(X,Y)
plt.plot(X,linear.predict(X.reshape(-1,1)),'-b')
plt.title('petal-sepal scatter with linear regression')
plt.xlabel('petal length (cm)')
plt.ylabel('sepal length (cm)')
plt.grid()
plt.show()

L2 Regularization

機能:
円の形態:

しゅうそくそくどが速い
->2乗基準が結果に大きな影響を与える場合は、それをより大きいまたはより小さい位置に送信します.
#L2 regularization은 Ridge로 import 합니다.
from sklearn.linear_model import Ridge
L2 = Ridge()
L2.fit(X.reshape(-1,1), Y)
a, b = L2.coef_, L2.intercept_
print("기울기 : %0.2f, 절편 : %0.2f" %(a,b))
plt.figure(figsize=(5,5))
plt.scatter(X,Y)
plt.plot(X,L2.predict(X.reshape(-1,1)),'-b')
plt.title('petal-sepal scatter with L2 regularization(Ridge)')
plt.xlabel('petal length (cm)')
plt.ylabel('sepal length (cm)')
plt.grid()
plt.show()

Normalization

定義

例:z-scoreまたはminmax scalerを使用して、値分布を0と1の間の右に調整します.
効果:データ値の分布による距離の歪みによる学習の妨げとなる問題の解決
Batch Normalization
機能:
Dropout
定義:情報をランダムに選択して渡す
機能:
コード実装
tf.keras.layers.Dropout(rate, noise_shape=None, seed=None, **kwargs)
>>> tf.random.set_seed(0)
>>> layer = tf.keras.layers.Dropout(.2, input_shape=(2,))
>>> data = np.arange(10).reshape(5, 2).astype(np.float32)
>>> print(data)
[[0. 1.]
[2. 3.]
[4. 5.]
[6. 7.]
[8. 9.]]
>>> outputs = layer(data, training=True)
>>> print(outputs)
tf.Tensor(
[[ 0. 1.25]
[ 2.5 3.75]
[ 5. 6.25]
[ 7.5 8.75]
[10. 0. ]], shape=(5, 2), dtype=float32)
Reference
この問題について(Solution of Overfitting), 我々は、より多くの情報をここで見つけました https://velog.io/@qsdcfd/Solution-of-Overfittingテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol