Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[CS Foundation] AIML - 3 - Common Issue

x-village
August 15, 2018

[CS Foundation] AIML - 3 - Common Issue

x-village

August 15, 2018
Tweet

More Decks by x-village

Other Decks in Programming

Transcript

  1. Underfitting • Address underfitting 6 2. Increase number of features

    3. Remove outlier 1. Use more complex model Underfitting
  2. Underfitting • Address underfitting 7 2. Increase number of features

    3. Remove outlier 1. Use more complex model Level 1 2 3 4 5 ATK 0 10 25 50 100 + x (Level) y x 1 (Level) y x 2 (ATK)
  3. Underfitting • Address underfitting 8 2. Increase number of features

    3. Remove outliers 1. Use more complex model Outliers
  4. Overfitting • Address overfitting 9 1. Use simpler model 3.

    Validation 2. Collect more training data 4. Regularization
  5. Overfitting • Address overfitting 10 1. Use simpler model 3.

    Validation 2. Collect more training data 4. Regularization
  6. Overfitting • Address overfitting 11 1. Use simpler model 3.

    Validation 2. Collect more training data 4. Regularization
  7. Overfitting • Address overfitting 12 1. Use simpler model 3.

    Validation 2. Collect more training data 4. Regularization
  8. Example of regression Regularization • Keep all the features, but

    reduce value of weights θ • Add penalty 13 original cost function → θ 3 ≈ 0 θ 4 ≈ 0 + 1000 • θ 3 + 1000 • θ 4 2 2 any big number (正規化)
  9. Regularization • Smaller values for weights θ j 14 Σ

    θ j j = 1 n 2 + λ Regularization Parameter Regularization Term [ ] Cost Function
  10. Regularized Linear Regression • How does λ affect the performance

    • Large λ works fine (e.g. λ = 1000) • Small λ leads to overfitting 15 Q: If λ extremely large ? (e.g. λ = 1010) Cost Function Hypothesis → θ 1 , θ 2 , θ 3 , θ 4 ≈ 0 Underfitting
  11. Regularization • Regression uses L2 Regularization • Ridge 17 2

    Minimize penalty Minimize cost Minimize cost + penalty
  12. Regularization • Regression uses L1 Regularization • Lasso (least absolute

    shrinkage and selection operator) 18 Minimize cost 1 Minimize penalty Minimize cost + penalty
  13. Regularization • Lasso regression v.s. Ridge regression • Lasso shrinks

    the less important weight to 0 19 Works well for feature selection Lasso θ 1 = 0 θ 1, θ 2 ≠ 0
  14. Exercise - (4) 22 • TASK: Call Ridge, Lasso, ElasticNet

    models • Requirements • 使用sklearn.datasets中的boston數據來訓練此三個models • 印出三個model訓練完後的weights
  15. Sparse data • The problem of sparse data • Space

    complexity • Require large memory • Time complexity • Spend much time on useless calculations 26
  16. Sparse data • Deal with sparse data 1. Use other

    data structures to save the data 27 • Tool: scipy.sparse 2. Dimensionality reduction
  17. Sparse data 28 Opinion space: A scalable tool for browsing

    online comments - Scientific Figure on ResearchGate. Available from: https://www.researchgate.net/Dimensionality-reduction-from-3D-to-2D_fig4_22151902 4 [accessed 15 Aug, 2018] • Deal with sparse data 1. Use other data structures to save the data • Tool: scipy.sparse 2. Dimensionality reduction
  18. Imbalanced data • What is imbalanced data 30 我愛梨明! 我愛梨明!

    張學酉!張學酉! 我們愛你! Training data
  19. Imbalanced data • The problem of imbalanced data 31 Testing

    data 張學酉fans 張學酉fans 張學酉fans 張學酉fans Predict 梨明fans 張學酉fans 張學酉fans 張學酉fans Trut h 模型只預測多數派!
  20. Imbalanced data 32 • Deal with imbalanced data • Collect

    more training data • Resample training data • Use other evaluation metrics
  21. Imbalanced data 33 前期 後期 • Deal with imbalanced data

    • Collect more training data • Resample training data • Use other evaluation metrics 每個時期的資料趨勢 可能不一樣!
  22. Imbalanced data • Deal with imbalanced data • Collect more

    training data • Resample training data • Use other evaluation metrics 34 收集比例較少的樣本 刪除比例較多的樣本
  23. Imbalanced data • Deal with imbalanced data • Collect more

    training data • Resample training data • Use other evaluation metrics 35 True Positive False Positive False Negative True Negative (Predicted) positive (Predicted) negative (Actual) positive (Actual) negative Precision = TP TP + FP Recall = TP TP + FN Accuracy = TP + TN TP + FN + TN + FP
  24. Imbalanced data • Deal with imbalanced data • Collect more

    training data • Resample training data • Use other evaluation metrics 36 True Positive False Positive False Negative True Negative (Predicted) positive (Predicted) negative (Actual) positive (Actual) negative Precision = TP TP + FP Recall = TP TP + FN Accuracy = TP + TN TP + FN + TN + FP
  25. Exercise - (5) 38 • TASK: Practice GridSearchCV • Requirements

    • 使用GridSearchCV來幫Ridge model調參,嘗試alpha = [1, 5, 10], 找出可以使結果最好的alpha值