├── projects ├── smartcab │ ├── smartcab │ │ ├── __init__.py │ │ └── planner.py │ ├── logs │ │ └── .gitignore │ ├── images │ │ ├── logo.png │ │ ├── car-red.png │ │ ├── car-black.png │ │ ├── car-blue.png │ │ ├── car-cyan.png │ │ ├── car-green.png │ │ ├── car-white.png │ │ ├── east-west.png │ │ ├── car-magenta.png │ │ ├── car-orange.png │ │ ├── car-yellow.png │ │ └── north-south.png │ └── README.md ├── image-classification │ ├── .gitignore │ └── helper.py ├── finding-donors │ ├── visuals.pyc │ ├── README.md │ ├── project_description.md │ └── visuals.py ├── customer_segments │ ├── visuals.pyc │ └── README.md ├── boston-housing-prices │ ├── visuals.pyc │ ├── README.md │ ├── visuals.py │ └── project_description.md ├── titanic-survival-exploration │ ├── visuals.pyc │ ├── README.md │ └── project_description.md └── capstone │ └── proposal.md ├── Gemfile ├── .gitignore ├── _config.yml ├── classes ├── supervised-learning │ ├── bayesian-methods-quizzes │ │ ├── mini-project │ │ │ ├── calculations.md │ │ │ ├── domain-knowledge-fill.md │ │ │ ├── optimal-classifier.md │ │ │ ├── images │ │ │ │ ├── calculations.png │ │ │ │ ├── optimal-classifier.png │ │ │ │ ├── domain-knowledge-fill.png │ │ │ │ └── optimal-classifier-question.png │ │ │ ├── domain-knowledge-quiz.md │ │ │ ├── joint-distirbution-probability.md │ │ │ ├── which-words-mediation.md │ │ │ ├── maximum-likelihood.py │ │ │ └── optimal-classifier.py │ │ ├── joint-distribution-quiz.md │ │ ├── bayesian-probabilities-on-your-own.py │ │ └── calculating-nb-accuracy.py │ ├── images │ │ ├── ID3.png │ │ ├── KNN.png │ │ ├── Entropy.png │ │ ├── margins.png │ │ ├── sigmoid.png │ │ ├── summary.png │ │ ├── DT-Graph.png │ │ ├── bayes-rule.png │ │ ├── example-spam.png │ │ ├── perceptron.png │ │ ├── similarity.png │ │ ├── summary-svm.png │ │ ├── cancer-problem.png │ │ ├── svm-parameters.png │ │ ├── backpropagation.png │ │ ├── bayesian-learning.png │ │ ├── boosting-example.png │ │ ├── boosting-overview.png │ │ ├── gradient-descent.png │ │ ├── inference-rules.png │ │ ├── information-gain.png │ │ ├── kernel-trick-svm.png │ │ ├── preference-bias.png │ │ ├── restriction-bias.png │ │ ├── boosting-example-1.png │ │ ├── boosting-example-2.png │ │ ├── boosting-example-3.png │ │ ├── joint-distribution.png │ │ ├── kernel-trick-svm-2.png │ │ ├── optimizing-weights.png │ │ ├── perceptron-training.png │ │ ├── boosting-example-final.png │ │ ├── kernel-trick-overview.png │ │ ├── learning-query-times.png │ │ ├── quadratic-programming.png │ │ ├── bayesian-learning-summary.png │ │ ├── minimum-description-length.png │ │ ├── naive-bayes-generalization.png │ │ ├── comparison-of-learning-rules.png │ │ └── prior-posterior-probabilities.png │ ├── nonparametric-models.md │ ├── neural-network-quizzes │ │ ├── layered-network-example.py │ │ ├── linear-representational-power.md │ │ ├── discretion-quiz.md │ │ ├── xor-network.py │ │ ├── perceptron-learning.py │ │ └── sigmoid-programming-exercise.py │ ├── ensemble-learners.md │ ├── support-vector-machines.md │ ├── bayesian-methods.md │ ├── svm-quizzes │ │ └── coding-up-svm.py │ ├── nonparametric-quizzes │ │ ├── domain-knnowledge.py │ │ └── domain-knnowledge-sklearn.py │ ├── artificial-neural-networks.md │ ├── decision-trees.md │ └── supervised-learning.md ├── deep-learning │ ├── images │ │ ├── dmft │ │ │ ├── t-sne.png │ │ │ ├── challenges.png │ │ │ ├── embeddings.png │ │ │ ├── word2vec-detail.png │ │ │ ├── word2vec-intro.png │ │ │ ├── embeddings-intro.png │ │ │ └── comparing-embeddings.png │ │ ├── rnns │ │ │ ├── lstm.png │ │ │ ├── rnn-past.png │ │ │ ├── lstm-cell.png │ │ │ ├── rnn-final.png │ │ │ ├── rnn-intro.png │ │ │ ├── rnn-vs-cnn.png │ │ │ ├── backprop-time.png │ │ │ ├── beam-search.png │ │ │ ├── simple-memory.png │ │ │ ├── memory-diagram.png │ │ │ ├── rnn-application.png │ │ │ ├── rnn-past-model.png │ │ │ ├── rnn-pred-sample.png │ │ │ ├── rnn-stationary.png │ │ │ ├── gradient-problems.png │ │ │ ├── image-captioning.png │ │ │ ├── lstm-cell-detailed.png │ │ │ ├── speech-recognition.png │ │ │ ├── lstm-regularization.png │ │ │ ├── machine-translation.png │ │ │ ├── multiple-predictions.png │ │ │ ├── backprop-time-problem.png │ │ │ ├── rnn-output-fixed-vector.png │ │ │ ├── image-captioning-dataset.png │ │ │ ├── rnn-input-output-variable.png │ │ │ ├── exploding-gradient-solution.png │ │ │ ├── rnn-output-variable-length.png │ │ │ └── vanishing-gradient-problem-explained.png │ │ ├── cnns │ │ │ ├── pooling.png │ │ │ ├── cnn-stride.png │ │ │ ├── cnn-padding.png │ │ │ ├── max-pooling.png │ │ │ ├── average-pooling.png │ │ │ ├── convolutions-1.png │ │ │ ├── convolutions-2.png │ │ │ ├── convolutions-3.png │ │ │ ├── 1-1-convolutions.png │ │ │ ├── convnet-overview.png │ │ │ ├── inception-modules.png │ │ │ ├── cnn-patch-feature-map.png │ │ │ ├── convnets-weight-sharing.png │ │ │ ├── convolutional-pyramid.png │ │ │ ├── statistical-invariance.png │ │ │ ├── translation-invariance.png │ │ │ ├── famous-cnn-architectures.png │ │ │ ├── structure-helps-learning.png │ │ │ └── translation-invariance-2.png │ │ ├── from-ml-to-dl │ │ │ ├── adagrad.png │ │ │ ├── softmax.png │ │ │ ├── zero-mean.png │ │ │ ├── gd-vs-sgd-1.png │ │ │ ├── gd-vs-sgd-2.png │ │ │ ├── helping-sgd.png │ │ │ ├── momentum-sgd.png │ │ │ ├── recap-deeper.png │ │ │ ├── sgd-black-magic.png │ │ │ ├── well-conditioned.png │ │ │ ├── cross-entropy-intro.png │ │ │ ├── logistic-classifier.png │ │ │ ├── normalizing-images.png │ │ │ ├── optimization-steps.png │ │ │ ├── learning-rate-tuning.png │ │ │ ├── validation-test-size.png │ │ │ ├── weight-initialization.png │ │ │ ├── cross-entropy-definition.png │ │ │ ├── gradient-descent-solver.png │ │ │ ├── learning-rate-decay-sgd.png │ │ │ ├── one-hot-encoding-problem.png │ │ │ ├── probabilities-classifier.png │ │ │ ├── loss-function-cross-entropy.png │ │ │ ├── loss-function-representation.png │ │ │ ├── minimizing-cross-entropy-intro.png │ │ │ ├── logistic-classifier-initialization.png │ │ │ ├── multinomial-logistic-classification.png │ │ │ └── multinomial-logistic-classification-recap.png │ │ └── deep-neural-networks │ │ │ ├── relus.png │ │ │ ├── chain-rule.png │ │ │ ├── nn-features.png │ │ │ ├── dropout-intro.png │ │ │ ├── dropout-scale.png │ │ │ ├── regularization.png │ │ │ ├── back-propagation.png │ │ │ ├── dropout-average.png │ │ │ ├── dropout-example.png │ │ │ ├── dropout-redundant.png │ │ │ ├── early-termination.png │ │ │ ├── relus-derivative.png │ │ │ ├── simple-operations.png │ │ │ ├── linear-models-stay.png │ │ │ ├── wider-vs-deeper-nn.png │ │ │ ├── 2-layer-neural-network.png │ │ │ ├── adding-hidden-layers.png │ │ │ ├── graphical-chain-rule.png │ │ │ ├── linear-models-stay-2.png │ │ │ ├── neural-network-relus.png │ │ │ ├── linear-model-complexity.png │ │ │ ├── linear-models-are-linear.png │ │ │ ├── neural-network-question.png │ │ │ ├── not-very-deep-2-layer-nn.png │ │ │ ├── linear-models-are-efficient.png │ │ │ ├── linear-models-are-stable-1.png │ │ │ ├── linear-models-are-stable-2.png │ │ │ ├── regularization-derivative.png │ │ │ ├── regularization-skinny-jeans.png │ │ │ └── regularization-loss-function.png │ └── exercises │ │ └── softmax.py ├── unsupervised-learning │ ├── images │ │ ├── slc.png │ │ ├── summary.png │ │ ├── ica-notes.png │ │ ├── ica-vs-pca.png │ │ ├── relevance.png │ │ ├── uniform-1.png │ │ ├── uniform-2.png │ │ ├── PCA-sklearn.png │ │ ├── alternatives.png │ │ ├── ica-vs-pca-2.png │ │ ├── PCA-sklearn-2.png │ │ ├── add-centroids.png │ │ ├── associate-step.png │ │ ├── em-properties.png │ │ ├── feature-scaling.png │ │ ├── move-centroids.png │ │ ├── soft-clustering.png │ │ ├── when-to-use-pca.png │ │ ├── clustering-summary.png │ │ ├── filtering-wrapping.png │ │ ├── clustering-properties.png │ │ ├── impossibility-theorem.png │ │ ├── minimum-features-quiz.png │ │ ├── review-definition-PCA.png │ │ ├── expectation-maximization.png │ │ ├── min-max-rescaler-sklearn.png │ │ ├── relevance-vs-usefulness.png │ │ ├── filtering-wrapping-comparison.png │ │ ├── maximal-variation-minimal-loss.png │ │ ├── filtering-wrapping-comparison-2.png │ │ └── feature-transformation-definition.png │ ├── feature-rescaling-example.py │ ├── clustering.md │ ├── dimensionality-reduction.md │ └── feature-engineering.md ├── reinforcement-learning │ ├── images │ │ ├── minimax.png │ │ ├── gt-summary.png │ │ ├── mdp-summary.png │ │ ├── rl-overview.png │ │ ├── rl-summary.png │ │ ├── von-neumann.png │ │ ├── brief-history.png │ │ ├── estimating-q-2.png │ │ ├── estimating-q.png │ │ ├── game-example.png │ │ ├── mixed-strategy.png │ │ ├── more-rewards.png │ │ ├── rl-approaches.png │ │ ├── bellman-equation.png │ │ ├── choosing-actions.png │ │ ├── finding-policies.png │ │ ├── hidden-info-game.png │ │ ├── nash-equilibrium.png │ │ ├── q-value-function.png │ │ ├── fundamental-result.png │ │ ├── greedy-exploration.png │ │ ├── hidden-info-game-2.png │ │ ├── mini-poker-result.png │ │ ├── prisioners-dilemma.png │ │ ├── what-is-game-theory.png │ │ ├── bellman-quiz-example.png │ │ ├── utility-quiz-infinite.png │ │ ├── markov-decision-process.png │ │ ├── nash-equilibrium-example.png │ │ ├── non-deterministic-game.png │ │ ├── q-learning-convergence.png │ │ ├── solving-bellman-equation.png │ │ ├── comparison-types-learning.png │ │ ├── discounted-utility-rewards.png │ │ ├── maximal-discounted-rewards.png │ │ ├── solving-bellman-equation-2.png │ │ └── nash-equilibrium-implications.png │ ├── reinforcement-learning.md │ ├── game-theory.md │ └── markov-decision-process.md ├── welcome-to-the-nano-degree │ ├── references │ │ ├── HoG paper.pdf │ │ └── Overview on Face Detection.pdf │ ├── images │ │ ├── kernel-trick-curve.png │ │ ├── kernel-trick-plane.png │ │ ├── neural-network-questions.png │ │ ├── neural-network-topography.png │ │ └── support-vector-machines.png │ └── notes │ │ └── welcome-to-the-mlnd-program.md └── model-evaluation-and-validation │ ├── managing-error-and-complexity.md │ └── evaluation-and-validation.md ├── statistics ├── bessels_correction.png └── cheatsheet.md ├── _layouts └── default.html └── README.md /projects/smartcab/smartcab/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /projects/smartcab/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'github-pages', group: :jekyll_plugins -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | launch.json 3 | *.pyc 4 | .ipynb_checkpoints 5 | _site 6 | Gemfile.lock -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal 2 | show_downloads: false 3 | google_analytics: UA-93538647-1 -------------------------------------------------------------------------------- /projects/image-classification/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | !*.html 4 | !.gitignore 5 | !*.py 6 | !*.ipynb 7 | -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/calculations.md: -------------------------------------------------------------------------------- 1 | ![](images/calculations.png) -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/domain-knowledge-fill.md: -------------------------------------------------------------------------------- 1 | ![](images/domain-knowledge-fill.png) -------------------------------------------------------------------------------- /projects/smartcab/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/logo.png -------------------------------------------------------------------------------- /statistics/bessels_correction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/statistics/bessels_correction.png -------------------------------------------------------------------------------- /projects/finding-donors/visuals.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/finding-donors/visuals.pyc -------------------------------------------------------------------------------- /projects/smartcab/images/car-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-red.png -------------------------------------------------------------------------------- /projects/customer_segments/visuals.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/customer_segments/visuals.pyc -------------------------------------------------------------------------------- /projects/smartcab/images/car-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-black.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-blue.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-cyan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-cyan.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-green.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-white.png -------------------------------------------------------------------------------- /projects/smartcab/images/east-west.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/east-west.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-magenta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-magenta.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-orange.png -------------------------------------------------------------------------------- /projects/smartcab/images/car-yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/car-yellow.png -------------------------------------------------------------------------------- /projects/smartcab/images/north-south.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/smartcab/images/north-south.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/t-sne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/t-sne.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/lstm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/lstm.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/ID3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/ID3.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/KNN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/KNN.png -------------------------------------------------------------------------------- /projects/boston-housing-prices/visuals.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/boston-housing-prices/visuals.pyc -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/pooling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/pooling.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-past.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-past.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/Entropy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/Entropy.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/margins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/margins.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/sigmoid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/sigmoid.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/summary.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/slc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/slc.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/cnn-stride.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/cnn-stride.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/challenges.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/challenges.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/embeddings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/embeddings.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/lstm-cell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/lstm-cell.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-final.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-intro.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-vs-cnn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-vs-cnn.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/DT-Graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/DT-Graph.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/summary.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/cnn-padding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/cnn-padding.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/max-pooling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/max-pooling.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/backprop-time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/backprop-time.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/beam-search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/beam-search.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/simple-memory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/simple-memory.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/minimax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/minimax.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/bayes-rule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/bayes-rule.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/example-spam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/example-spam.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/perceptron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/perceptron.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/similarity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/similarity.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/summary-svm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/summary-svm.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/ica-notes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/ica-notes.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/ica-vs-pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/ica-vs-pca.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/relevance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/relevance.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/uniform-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/uniform-1.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/uniform-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/uniform-2.png -------------------------------------------------------------------------------- /projects/titanic-survival-exploration/visuals.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/projects/titanic-survival-exploration/visuals.pyc -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/average-pooling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/average-pooling.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/convolutions-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/convolutions-1.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/convolutions-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/convolutions-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/convolutions-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/convolutions-3.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/word2vec-detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/word2vec-detail.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/word2vec-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/word2vec-intro.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/memory-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/memory-diagram.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-application.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-application.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-past-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-past-model.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-pred-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-pred-sample.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-stationary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-stationary.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/gt-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/gt-summary.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/mdp-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/mdp-summary.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/rl-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/rl-overview.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/rl-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/rl-summary.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/von-neumann.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/von-neumann.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/cancer-problem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/cancer-problem.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/svm-parameters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/svm-parameters.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/PCA-sklearn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/PCA-sklearn.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/alternatives.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/alternatives.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/ica-vs-pca-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/ica-vs-pca-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/1-1-convolutions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/1-1-convolutions.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/convnet-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/convnet-overview.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/inception-modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/inception-modules.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/embeddings-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/embeddings-intro.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/adagrad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/adagrad.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/softmax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/softmax.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/zero-mean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/zero-mean.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/gradient-problems.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/gradient-problems.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/image-captioning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/image-captioning.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/lstm-cell-detailed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/lstm-cell-detailed.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/speech-recognition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/speech-recognition.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/brief-history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/brief-history.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/estimating-q-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/estimating-q-2.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/estimating-q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/estimating-q.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/game-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/game-example.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/mixed-strategy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/mixed-strategy.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/more-rewards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/more-rewards.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/rl-approaches.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/rl-approaches.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/backpropagation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/backpropagation.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/bayesian-learning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/bayesian-learning.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/boosting-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/boosting-example.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/boosting-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/boosting-overview.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/gradient-descent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/gradient-descent.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/inference-rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/inference-rules.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/information-gain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/information-gain.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/kernel-trick-svm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/kernel-trick-svm.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/preference-bias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/preference-bias.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/restriction-bias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/restriction-bias.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/PCA-sklearn-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/PCA-sklearn-2.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/add-centroids.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/add-centroids.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/associate-step.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/associate-step.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/em-properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/em-properties.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/feature-scaling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/feature-scaling.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/move-centroids.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/move-centroids.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/soft-clustering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/soft-clustering.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/when-to-use-pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/when-to-use-pca.png -------------------------------------------------------------------------------- /classes/deep-learning/images/dmft/comparing-embeddings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/dmft/comparing-embeddings.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/gd-vs-sgd-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/gd-vs-sgd-1.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/gd-vs-sgd-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/gd-vs-sgd-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/helping-sgd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/helping-sgd.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/lstm-regularization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/lstm-regularization.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/machine-translation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/machine-translation.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/multiple-predictions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/multiple-predictions.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/bellman-equation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/bellman-equation.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/choosing-actions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/choosing-actions.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/finding-policies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/finding-policies.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/hidden-info-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/hidden-info-game.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/nash-equilibrium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/nash-equilibrium.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/q-value-function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/q-value-function.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/boosting-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/boosting-example-1.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/boosting-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/boosting-example-2.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/boosting-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/boosting-example-3.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/joint-distribution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/joint-distribution.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/kernel-trick-svm-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/kernel-trick-svm-2.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/optimizing-weights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/optimizing-weights.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/perceptron-training.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/perceptron-training.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/cnn-patch-feature-map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/cnn-patch-feature-map.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/convnets-weight-sharing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/convnets-weight-sharing.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/convolutional-pyramid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/convolutional-pyramid.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/statistical-invariance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/statistical-invariance.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/translation-invariance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/translation-invariance.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/relus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/relus.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/momentum-sgd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/momentum-sgd.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/recap-deeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/recap-deeper.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/backprop-time-problem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/backprop-time-problem.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-output-fixed-vector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-output-fixed-vector.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/fundamental-result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/fundamental-result.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/greedy-exploration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/greedy-exploration.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/hidden-info-game-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/hidden-info-game-2.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/mini-poker-result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/mini-poker-result.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/prisioners-dilemma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/prisioners-dilemma.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/what-is-game-theory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/what-is-game-theory.png -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/optimal-classifier.md: -------------------------------------------------------------------------------- 1 | ![Question](images/optimal-classifier-question.png) 2 | 3 | ![Solution](images/optimal-classifier.png) -------------------------------------------------------------------------------- /classes/supervised-learning/images/boosting-example-final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/boosting-example-final.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/kernel-trick-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/kernel-trick-overview.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/learning-query-times.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/learning-query-times.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/quadratic-programming.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/quadratic-programming.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/clustering-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/clustering-summary.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/filtering-wrapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/filtering-wrapping.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/references/HoG paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/references/HoG paper.pdf -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/famous-cnn-architectures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/famous-cnn-architectures.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/structure-helps-learning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/structure-helps-learning.png -------------------------------------------------------------------------------- /classes/deep-learning/images/cnns/translation-invariance-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/cnns/translation-invariance-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/sgd-black-magic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/sgd-black-magic.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/well-conditioned.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/well-conditioned.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/image-captioning-dataset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/image-captioning-dataset.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-input-output-variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-input-output-variable.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/bellman-quiz-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/bellman-quiz-example.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/utility-quiz-infinite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/utility-quiz-infinite.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/clustering-properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/clustering-properties.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/impossibility-theorem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/impossibility-theorem.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/minimum-features-quiz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/minimum-features-quiz.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/review-definition-PCA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/review-definition-PCA.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/chain-rule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/chain-rule.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/nn-features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/nn-features.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/cross-entropy-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/cross-entropy-intro.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/logistic-classifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/logistic-classifier.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/normalizing-images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/normalizing-images.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/optimization-steps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/optimization-steps.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/exploding-gradient-solution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/exploding-gradient-solution.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/rnn-output-variable-length.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/rnn-output-variable-length.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/markov-decision-process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/markov-decision-process.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/nash-equilibrium-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/nash-equilibrium-example.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/non-deterministic-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/non-deterministic-game.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/q-learning-convergence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/q-learning-convergence.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/solving-bellman-equation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/solving-bellman-equation.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/bayesian-learning-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/bayesian-learning-summary.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/minimum-description-length.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/minimum-description-length.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/naive-bayes-generalization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/naive-bayes-generalization.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/expectation-maximization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/expectation-maximization.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/min-max-rescaler-sklearn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/min-max-rescaler-sklearn.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/relevance-vs-usefulness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/relevance-vs-usefulness.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/images/kernel-trick-curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/images/kernel-trick-curve.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/images/kernel-trick-plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/images/kernel-trick-plane.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/dropout-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/dropout-intro.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/dropout-scale.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/dropout-scale.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/regularization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/regularization.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/learning-rate-tuning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/learning-rate-tuning.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/validation-test-size.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/validation-test-size.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/weight-initialization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/weight-initialization.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/comparison-types-learning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/comparison-types-learning.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/discounted-utility-rewards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/discounted-utility-rewards.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/maximal-discounted-rewards.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/maximal-discounted-rewards.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/solving-bellman-equation-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/solving-bellman-equation-2.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/comparison-of-learning-rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/comparison-of-learning-rules.png -------------------------------------------------------------------------------- /classes/supervised-learning/images/prior-posterior-probabilities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/images/prior-posterior-probabilities.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/back-propagation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/back-propagation.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/dropout-average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/dropout-average.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/dropout-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/dropout-example.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/dropout-redundant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/dropout-redundant.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/early-termination.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/early-termination.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/relus-derivative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/relus-derivative.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/simple-operations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/simple-operations.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/cross-entropy-definition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/cross-entropy-definition.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/gradient-descent-solver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/gradient-descent-solver.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/learning-rate-decay-sgd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/learning-rate-decay-sgd.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/one-hot-encoding-problem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/one-hot-encoding-problem.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/probabilities-classifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/probabilities-classifier.png -------------------------------------------------------------------------------- /classes/reinforcement-learning/images/nash-equilibrium-implications.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/reinforcement-learning/images/nash-equilibrium-implications.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/filtering-wrapping-comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/filtering-wrapping-comparison.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/maximal-variation-minimal-loss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/maximal-variation-minimal-loss.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/images/neural-network-questions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/images/neural-network-questions.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/images/neural-network-topography.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/images/neural-network-topography.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/images/support-vector-machines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/images/support-vector-machines.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-models-stay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-models-stay.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/wider-vs-deeper-nn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/wider-vs-deeper-nn.png -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/filtering-wrapping-comparison-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/filtering-wrapping-comparison-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/2-layer-neural-network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/2-layer-neural-network.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/adding-hidden-layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/adding-hidden-layers.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/graphical-chain-rule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/graphical-chain-rule.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-models-stay-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-models-stay-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/neural-network-relus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/neural-network-relus.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/loss-function-cross-entropy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/loss-function-cross-entropy.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/loss-function-representation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/loss-function-representation.png -------------------------------------------------------------------------------- /classes/deep-learning/images/rnns/vanishing-gradient-problem-explained.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/rnns/vanishing-gradient-problem-explained.png -------------------------------------------------------------------------------- /classes/supervised-learning/nonparametric-models.md: -------------------------------------------------------------------------------- 1 | # Nonparametric Models 2 | 3 | ## KNN 4 | 5 | ![KNN](images/knn.png) 6 | 7 | ## Learning and Query Times Comparison 8 | 9 | ![Tiems](images/learning-query-times.png) -------------------------------------------------------------------------------- /classes/unsupervised-learning/images/feature-transformation-definition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/unsupervised-learning/images/feature-transformation-definition.png -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/references/Overview on Face Detection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/welcome-to-the-nano-degree/references/Overview on Face Detection.pdf -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-model-complexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-model-complexity.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-models-are-linear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-models-are-linear.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/neural-network-question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/neural-network-question.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/not-very-deep-2-layer-nn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/not-very-deep-2-layer-nn.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/minimizing-cross-entropy-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/minimizing-cross-entropy-intro.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-models-are-efficient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-models-are-efficient.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-models-are-stable-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-models-are-stable-1.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/linear-models-are-stable-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/linear-models-are-stable-2.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/regularization-derivative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/regularization-derivative.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/regularization-skinny-jeans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/regularization-skinny-jeans.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/logistic-classifier-initialization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/logistic-classifier-initialization.png -------------------------------------------------------------------------------- /classes/deep-learning/images/deep-neural-networks/regularization-loss-function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/deep-neural-networks/regularization-loss-function.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/multinomial-logistic-classification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/multinomial-logistic-classification.png -------------------------------------------------------------------------------- /classes/deep-learning/images/from-ml-to-dl/multinomial-logistic-classification-recap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/deep-learning/images/from-ml-to-dl/multinomial-logistic-classification-recap.png -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/calculations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/calculations.png -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/optimal-classifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/optimal-classifier.png -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/domain-knowledge-fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/domain-knowledge-fill.png -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/optimal-classifier-question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedropb/machine-learning-nanodegree/HEAD/classes/supervised-learning/bayesian-methods-quizzes/mini-project/images/optimal-classifier-question.png -------------------------------------------------------------------------------- /classes/supervised-learning/neural-network-quizzes/layered-network-example.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | input = np.array([1,2,3]) 4 | h1 = np.array([1,1,-5]) 5 | h2 = np.array([3,-4,2]) 6 | ol = np.array([2,-1]) 7 | print np.array([input.dot(h1), input.dot(h2)]).dot(ol) 8 | # -25 9 | -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/joint-distribution-quiz.md: -------------------------------------------------------------------------------- 1 | | Storm | Lightning | Prob | 2 | |-------|-----------|------| 3 | | T | T | .25 | 4 | | T | F | .40 | 5 | | F | T | .05 | 6 | | F | F | .30 | 7 | 8 | **Question**: 9 | 1. P(¬storm)? .30 + .05 = .35 10 | 2. P(lightning | storm)? .25 / (.40 + .25) = .3846 -------------------------------------------------------------------------------- /classes/supervised-learning/neural-network-quizzes/linear-representational-power.md: -------------------------------------------------------------------------------- 1 | Given: 2 | - inputs: [x, y] 3 | - hidden layer: [[3,2], [-1,4], [3,-5]] 4 | - output layer: [1,2,-1] 5 | 6 | Write down a single node 2x1, that computes the same result as above. 7 | 8 | **Answer** 9 | 10 | 3x+2y + 2*(-x + 4y) - (3x -5y) 11 | 3x + 2y - 2x + 8y - 3x + 5y 12 | -2x + 15y -> [-2, 15] -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/domain-knowledge-quiz.md: -------------------------------------------------------------------------------- 1 | ## Given the corpus of text we have from our boss, we might like to identify some things he often says, and use that knowledge to make better predictions. 2 | 3 | ## What are some statements you see arising multiple times? 4 | ``` 5 | gonna need 6 | need you to go 7 | need you 8 | to go 9 | to go ahead 10 | go ahead and 11 | and come in 12 | ahh 13 | oh oh 14 | oh, oh 15 | ``` -------------------------------------------------------------------------------- /classes/supervised-learning/ensemble-learners.md: -------------------------------------------------------------------------------- 1 | # Ensemble Learners (Bagging & Boosting) 2 | 3 | ## Example: SPAM detection 4 | 5 | ![Example: SPAM detection](images/example-spam.png) 6 | 7 | ## Boosting 8 | 9 | ![Booting overview](images/boosting-overview.png) 10 | 11 | ## Boosting: an example 12 | 13 | ![](images/boosting-example.png) 14 | 15 | ![](images/boosting-example-1.png) 16 | 17 | ![](images/boosting-example-2.png) 18 | 19 | ![](images/boosting-example-3.png) 20 | 21 | ![](images/boosting-example-final.png) -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/joint-distirbution-probability.md: -------------------------------------------------------------------------------- 1 | ## If you wanted to measure the joint probability distribution of a missing word given its position relative to every other word in the document, how many probabilities would you need to measure? Say the document is N words long. 2 | 3 | - Number of words: `N` 4 | - Number of possible missing word's positions (i.e: first word missing, second word missing, etc.): `N` 5 | - Number of possible distances between missing word and the other words. For each possible position, we have `N` other words, so the final answer is: `N^2` -------------------------------------------------------------------------------- /classes/supervised-learning/support-vector-machines.md: -------------------------------------------------------------------------------- 1 | # Support Vector Machines 2 | 3 | ## Margins 4 | 5 | ![Margins](images/margins.png) 6 | 7 | ## Min Max in SVM with Quadratic Programming 8 | 9 | ![Quadratic Programming](images/quadratic-programming.png) 10 | 11 | ## Similarity concept 12 | 13 | ![Similarity](images/similarity.png) 14 | 15 | ## Kernel Trick in SVM 16 | 17 | ![Kernel Trick](images/kernel-trick-svm.png) 18 | 19 | ![Kernel Trick2](images/kernel-trick-svm-2.png) 20 | 21 | ![Kernel Trick Overview](images/kernel-trick-overview.png) 22 | 23 | ## SKLearn Parameters for SVM 24 | 25 | ![SVM Parameters](images/svm-parameters.png) 26 | 27 | ## Summary 28 | 29 | ![Summary](images/summary-svm.png) -------------------------------------------------------------------------------- /classes/unsupervised-learning/feature-rescaling-example.py: -------------------------------------------------------------------------------- 1 | from matplotlib import pyplot as plt 2 | from sklearn.preprocessing import MinMaxScaler 3 | 4 | data = [[175., 5.9], [115., 5.2]] 5 | chris_data = [[140., 6.1]] 6 | 7 | def plot_data(): 8 | for d in data: 9 | plt.scatter(d[0], d[1], color="red") 10 | 11 | plt.scatter(chris_data[0][0], chris_data[0][1], color="blue") 12 | 13 | 14 | 15 | plt.title('Before rescaling') 16 | plot_data() 17 | plt.show() 18 | plt.close() 19 | 20 | # rescale 21 | scaler = MinMaxScaler() 22 | scaler.fit(data) 23 | data = scaler.transform(data) 24 | chris_data = scaler.transform(chris_data) 25 | 26 | plt.title("After rescaling") 27 | plot_data() 28 | plt.show() 29 | plt.close() 30 | -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/bayesian-probabilities-on-your-own.py: -------------------------------------------------------------------------------- 1 | p_chris = 0.5 2 | p_sarah = 0.5 3 | 4 | p_words = {"chris": {"love": .1, "deal": .8, "life": .1}, 5 | "sarah": {"love": .5, "deal": .2, "life": .3}} 6 | 7 | p_joint_chris_love_deal = p_chris * p_words["chris"]["love"] * p_words["chris"]["deal"] 8 | p_joint_sarah_love_deal = p_sarah * p_words["sarah"]["love"] * p_words["sarah"]["deal"] 9 | 10 | p_love_deal = p_joint_chris_love_deal + p_joint_sarah_love_deal 11 | 12 | 13 | p_chris_love_deal = p_joint_chris_love_deal / p_love_deal 14 | p_sarah_love_deal = p_joint_sarah_love_deal / p_love_deal 15 | 16 | print "P(CHRIS|\"Love deal\")", p_chris_love_deal 17 | print "P(SARAH|\"Love deal\")", p_sarah_love_deal -------------------------------------------------------------------------------- /classes/supervised-learning/neural-network-quizzes/discretion-quiz.md: -------------------------------------------------------------------------------- 1 | How many combinations of outputs the perceptron network can produce with the following setup: 2 | 3 | 2 input perceptrons 4 | 2 hidden perceptrons 5 | 1 output perceptron 6 | 7 | ![Perceptron Network](http://g.gravizo.com/g? 8 | digraph G { 9 | "Input 1"; 10 | "Input 2"; 11 | "Input 1" -> "Hidden 1" [label="0,1"]; 12 | "Input 1" -> "Hidden 2" [label="0,1"]; 13 | "Input 2" -> "Hidden 1" [label="0,1"]; 14 | "Input 2" -> "Hidden 2" [label="0,1"]; 15 | "Hidden 1" -> "Output" [label="0,1"]; 16 | "Hidden 2" -> "Output" [label="0,1"]; 17 | } 18 | ) 19 | 20 | As we can see from the graph above, there are only 4 combinations of inputs to the output layer. This means that there are only 4 combinations of possible results to this network. -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods.md: -------------------------------------------------------------------------------- 1 | # Naive Bayes 2 | 3 | ## Quiz Cancer Test (Prior and Posterior Probabilities) 4 | 5 | ![Problem](images/cancer-problem.png) 6 | 7 | ![Prior and Posterior Probabilities (solution)](images/prior-posterior-probabilities.png) 8 | 9 | ## Bayes Rule 10 | 11 | ![Bayes Rule](images/bayes-rule.png) 12 | 13 | # Bayesian Learning 14 | 15 | ![Bayesian Learning](images/bayesian-learning.png) 16 | 17 | ## Minimum Description Length 18 | 19 | ![Minimum Description Length](images/minimum-description-length.png) 20 | 21 | ## Recovering Joint Distribution 22 | 23 | ![Recovering Joint Distribution](images/joint-distribution.png) 24 | 25 | ## Bayesian Learning Summary 26 | 27 | ![Bayesian Learning Summary](images/bayesian-learning-summary.png) 28 | 29 | ## Inference Rules 30 | 31 | ![Inference Rules](images/inference-rules.png) 32 | 33 | ## Naive Bayes: Generalization 34 | 35 | ![Naive Bayes Generalization](images/naive-bayes-generalization.png) -------------------------------------------------------------------------------- /classes/reinforcement-learning/reinforcement-learning.md: -------------------------------------------------------------------------------- 1 | # Reinforcement Learning 2 | 3 | ## Overview 4 | 5 | ![Overview](images/rl-overview.png) 6 | 7 | ## Brief History 8 | 9 | ![Brief History](images/brief-history.png) 10 | 11 | Side Note: Reinforcement is a misused term, because all we care is to maximize rewards. 12 | 13 | ## Reinforcement Learning Approaches 14 | 15 | ![RL Approaches](images/rl-approaches.png) 16 | 17 | ## Q Value Function 18 | 19 | ![Q Value Function](images/q-value-function.png) 20 | 21 | ## Estimating Q 22 | 23 | ![Estimating Q](images/estimating-q.png) 24 | 25 | ![Estimating Q 2](images/estimating-q-2.png) 26 | 27 | ## Q-Learning Convergence 28 | 29 | ![Q-Learning Convergence](images/q-learning-convergence.png) 30 | 31 | ## Choosing Actions 32 | 33 | ![Choosing Actions](images/choosing-actions.png) 34 | 35 | ## Greedy Exploration 36 | 37 | ![Greedy Exploration](images/greedy-exploration.png) 38 | 39 | ## Summary 40 | 41 | ![Summary](images/rl-summary.png) -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/calculating-nb-accuracy.py: -------------------------------------------------------------------------------- 1 | def NBAccuracy(features_train, labels_train, features_test, labels_test): 2 | """ compute the accuracy of your Naive Bayes classifier """ 3 | ### import the sklearn module for GaussianNB 4 | from sklearn.naive_bayes import GaussianNB 5 | 6 | ### create classifier 7 | clf = GaussianNB() 8 | 9 | ### fit the classifier on the training features and labels 10 | #TODO 11 | clf.fit(features_train, labels_train) 12 | 13 | ### use the trained classifier to predict labels for the test features 14 | pred = clf.predict(features_test) 15 | 16 | 17 | ### calculate and return the accuracy on the test data 18 | ### this is slightly different than the example, 19 | ### where we just print the accuracy 20 | ### you might need to import an sklearn module 21 | from sklearn.metrics import accuracy_score 22 | accuracy = accuracy_score(labels_test, pred) 23 | return accuracy -------------------------------------------------------------------------------- /classes/supervised-learning/svm-quizzes/coding-up-svm.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from class_vis import prettyPicture 3 | from prep_terrain_data import makeTerrainData 4 | 5 | import matplotlib.pyplot as plt 6 | import copy 7 | import numpy as np 8 | import pylab as pl 9 | 10 | 11 | features_train, labels_train, features_test, labels_test = makeTerrainData() 12 | 13 | 14 | ########################## SVM ################################# 15 | ### we handle the import statement and SVC creation for you here 16 | from sklearn.svm import SVC 17 | clf = SVC(kernel="linear") 18 | 19 | 20 | #### now your job is to fit the classifier 21 | #### using the training features/labels, and to 22 | #### make a set of predictions on the test data 23 | clf.fit(features_train, labels_train) 24 | 25 | 26 | #### store your predictions in a list named pred 27 | pred = clf.predict(features_test) 28 | 29 | 30 | 31 | 32 | 33 | from sklearn.metrics import accuracy_score 34 | acc = accuracy_score(pred, labels_test) 35 | 36 | def submitAccuracy(): 37 | return acc -------------------------------------------------------------------------------- /projects/smartcab/README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Engineer Nanodegree 2 | # Reinforcement Learning 3 | ## Project: Train a Smartcab How to Drive 4 | 5 | ### Install 6 | 7 | This project requires **Python 2.7** with the [pygame](https://www.pygame.org/wiki/GettingStarted 8 | ) library installed 9 | 10 | ### Code 11 | 12 | Template code is provided in the `smartcab/agent.py` python file. Additional supporting python code can be found in `smartcab/enviroment.py`, `smartcab/planner.py`, and `smartcab/simulator.py`. Supporting images for the graphical user interface can be found in the `images` folder. While some code has already been implemented to get you started, you will need to implement additional functionality for the `LearningAgent` class in `agent.py` when requested to successfully complete the project. 13 | 14 | ### Run 15 | 16 | In a terminal or command window, navigate to the top-level project directory `smartcab/` (that contains this README) and run one of the following commands: 17 | 18 | ```python smartcab/agent.py``` 19 | ```python -m smartcab.agent``` 20 | 21 | This will run the `agent.py` file and execute your agent code. 22 | -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/which-words-mediation.md: -------------------------------------------------------------------------------- 1 | ## What set of words in a memo do you think could help predict what a missing word might be? 2 | 3 | Based on my intuition on how humans interpret text, I would say that the set of words that can help predict what a missing word might be are **nouns, verbs, adverbs and adjectives**, because they are central to understanding the context of the sentence. For academic purposes, I would do research investigating statistically the words that have the better split on the following words. This would be empirically the best words to predict a missing word. Also note, that these conclusions may change regarding the language used during the study. 4 | 5 | ## What are some advantages and disadvantages of using more or fewer possible influences in prediction? 6 | 7 | The advantages of using **more influences** on prediction is the ability to **generalize better**. For instance, if the model can be built upon a vast vocabulary with lots of data to sample on, it might infer some relationships between words that a simpler model might not be able to infer. The disadvantage is that if the **model doesn't have enough data, it might overfit and be too sensitive to noise**, thus casting wrong predictions. -------------------------------------------------------------------------------- /classes/supervised-learning/nonparametric-quizzes/domain-knnowledge.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def manhattan_distance(p1, p2): 4 | return abs((p2[0] - p1[0])) + abs((p2[1] - p1[1])) 5 | 6 | def euclidean_distance(p1, p2): 7 | return math.sqrt(pow((p2[0] - p1[0]),2) + pow((p2[1] - p1[1]),2)) 8 | 9 | def compute_average(n_neighbors, distances, distance_idx): 10 | sum = 0 11 | i = 0 12 | while i < n_neighbors: 13 | cur = distances[i][2] 14 | sum += cur 15 | while distances[i+1][distance_idx] == distances[i][distance_idx] and i+1 < len(distances): 16 | sum += distances[i+1][2] 17 | i += 1 18 | i += 1 19 | return float(sum) / i 20 | 21 | data = [(1,6,7), (2,4,8), (3,7,16), (6,8,44), (7,1,50), (8,4,68)] 22 | query = (4,2) 23 | 24 | distances = [] 25 | for p in data: 26 | distances.append((euclidean_distance(p, query), manhattan_distance(p, query), p[2])) 27 | 28 | # sort by euclidean_distance 29 | euclidean = sorted(distances, key=lambda d: d[0]) 30 | print "euclidean 1: ", compute_average(1, euclidean, 0) 31 | print "euclidean 3: ", compute_average(3, euclidean, 0) 32 | 33 | manhattan = sorted(distances, key=lambda d: d[1]) 34 | print "manhattan 1: ", compute_average(1, manhattan, 1) 35 | print "manhattan 3: ", compute_average(3, manhattan, 1) 36 | -------------------------------------------------------------------------------- /classes/welcome-to-the-nano-degree/notes/welcome-to-the-mlnd-program.md: -------------------------------------------------------------------------------- 1 | # What is Machine Learning 2 | 3 | Machine Learning is a broad concept that involves AI, Statistics and Algorithms. 4 | 5 | - Like AI, Machine Learning is about processing and understanding data to react inteligently upon it. 6 | - Like Statistics, it is about applying complex formulas to make sense, compare, evaluate and summarize data. 7 | - Like Algorithms, it operates on data input and provides some output. 8 | 9 | In conclusion, Machine Learning is an evolution of all these areas. 10 | 11 | # Machine Learning vs Traditional Programming 12 | 13 | In traditional programming, we write decisions into the code. 14 | In machine learning, we create an agent that is trained and can figure patterns by itself. 15 | 16 | For example, in traditional programming, we would write code that would use a static set of algorithms to identify certain features in a image and figure out if it was a determinate person or not. In machine learning, we code an agent that is trained with a bunch of pictures and figure by itself how to identify a certain person. 17 | 18 | # Program Outline 19 | 20 | - Machine Learning and AI entire landscape 21 | - Building model and validation 22 | - Nuts and bolts of machine learning: different tools for different kinds of problems and when to use them 23 | - Personnal Project using all the knowledge gathered during the program. -------------------------------------------------------------------------------- /classes/deep-learning/exercises/softmax.py: -------------------------------------------------------------------------------- 1 | """Softmax.""" 2 | 3 | scores = [3.0, 1.0, 0.2] 4 | 5 | import numpy as np 6 | 7 | def softmax(x): 8 | """Compute softmax values for each sets of scores in x.""" 9 | return np.exp(x) / np.sum(np.exp(x), axis=0) 10 | 11 | 12 | def test_1(): 13 | scores = [1.0, 2.0, 3.0] 14 | print scores, softmax(scores) 15 | print "Test 1: " + ("passed" if [float("{:.8f}".format(i)) for i in softmax(scores)] == [ 0.09003057, 0.24472847, 0.66524096] else "failed") 16 | 17 | def test_2(): 18 | scores = np.array([[1, 2, 3, 6], 19 | [2, 4, 5, 6], 20 | [3, 8, 7, 6]]) 21 | 22 | result = softmax(scores) 23 | 24 | r = [] 25 | r1 = result.tolist() 26 | for i in r1: 27 | t = [] 28 | for j in i: 29 | t.append(float("{:.8f}".format(j))) 30 | r.append(t) 31 | 32 | print "Test 2: " + ("passed" if r == [[ 0.09003057, 0.00242826, 0.01587624, 0.33333333], 33 | [ 0.24472847, 0.01794253, 0.11731043, 0.33333333], 34 | [ 0.66524096, 0.97962921, 0.86681333, 0.33333333]] else "failed") 35 | 36 | test_1() 37 | 38 | test_2() 39 | 40 | def plot_graph(): 41 | # Plot softmax curves 42 | import matplotlib.pyplot as plt 43 | x = np.arange(-2.0, 6.0, 0.1) 44 | scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)]) 45 | 46 | plt.plot(x, softmax(scores).T, linewidth=2) 47 | plt.show() 48 | 49 | def scaling_scores(): 50 | scores = np.array([1.0, 2.0, 3.0]) 51 | print scores, softmax(scores) 52 | 53 | print softmax(scores * 10) 54 | 55 | print softmax(scores / 10) 56 | 57 | scaling_scores() -------------------------------------------------------------------------------- /classes/supervised-learning/nonparametric-quizzes/domain-knnowledge-sklearn.py: -------------------------------------------------------------------------------- 1 | from sklearn.neighbors import KNeighborsClassifier as KNN 2 | import numpy as np 3 | 4 | 5 | X_train = [[1,6], [2,4], [3,7], [6,8], [7,1], [8,4]] 6 | y_train = [7,8,16,44,50,68] 7 | 8 | euc1 = KNN(n_neighbors=1, p=2, algorithm='brute', weights='uniform') 9 | euc1.fit(X_train, y_train) 10 | print "euc1: ", euc1.predict([[4,2]]) 11 | print "euc1_neighbors: ", euc1.kneighbors([[4,2]], return_distance=False) 12 | 13 | euc3 = KNN(n_neighbors=3, p=2, algorithm='brute', weights='uniform') 14 | euc3.fit(X_train, y_train) 15 | print "euc3: ", euc3.predict([[4,2]]) 16 | print "euc3_neighbors: ", euc3.kneighbors([[4,2]], return_distance=False) 17 | 18 | man1 = KNN(n_neighbors=2, p=1, algorithm='brute', weights='uniform') 19 | man1.fit(X_train, y_train) 20 | print "man1: ", man1.predict([[4,2]]) 21 | print "man1_neighbors: ", man1.kneighbors([[4,2]], return_distance=False) 22 | 23 | man3 = KNN(n_neighbors=4, p=1, algorithm='brute', weights='uniform') 24 | man3.fit(X_train, y_train) 25 | print "man3: ", man3.predict([[4,2]]) 26 | print "man3_neighbors: ", man3.kneighbors([[4,2]], return_distance=False) 27 | 28 | # These outputs are not the expected answer to the quiz. 29 | 30 | import matplotlib.pyplot as plt 31 | 32 | x, y = zip(*X_train) 33 | 34 | plt.scatter(x, y) 35 | plt.scatter(4, 2, color="red") 36 | for label, xi, yi in zip(y_train, x, y): 37 | plt.annotate( 38 | label, 39 | xy = (xi, yi), 40 | xytext = (-20, 20), 41 | textcoords = 'offset points', ha = 'right', va = 'bottom', 42 | bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5), 43 | arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0')) 44 | plt.show() -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/maximum-likelihood.py: -------------------------------------------------------------------------------- 1 | sample_memo = ''' 2 | Milt, we're gonna need to go ahead and move you downstairs into storage B. We have some new people coming in, and we need all the space we can get. So if you could just go ahead and pack up your stuff and move it down there, that would be terrific, OK? 3 | Oh, and remember: next Friday... is Hawaiian shirt day. So, you know, if you want to, go ahead and wear a Hawaiian shirt and jeans. 4 | Oh, oh, and I almost forgot. Ahh, I'm also gonna need you to go ahead and come in on Sunday, too... 5 | Hello Peter, whats happening? Ummm, I'm gonna need you to go ahead and come in tomorrow. So if you could be here around 9 that would be great, mmmk... oh oh! and I almost forgot ahh, I'm also gonna need you to go ahead and come in on Sunday too, kay. We ahh lost some people this week and ah, we sorta need to play catch up. 6 | ''' 7 | 8 | # 9 | # Maximum Likelihood Hypothesis 10 | # 11 | # 12 | # In this quiz we will find the maximum likelihood word based on the preceding word 13 | # 14 | # Fill in the NextWordProbability procedure so that it takes in sample text and a word, 15 | # and returns a dictionary with keys the set of words that come after, whose values are 16 | # the number of times the key comes after that word. 17 | # 18 | # Just use .split() to split the sample_memo text into words separated by spaces. 19 | from collections import defaultdict 20 | import re 21 | 22 | def NextWordProbability(sampletext,word): 23 | text = str.lower(sampletext) 24 | text = re.sub(r"[^a-z '-]", "", text) 25 | 26 | words = text.split(' ') 27 | 28 | result = defaultdict(int) 29 | for idx, val in enumerate(words): 30 | if word == val: 31 | if idx+1 < len(words): 32 | result[words[idx+1]] += 1 33 | 34 | return result -------------------------------------------------------------------------------- /classes/reinforcement-learning/game-theory.md: -------------------------------------------------------------------------------- 1 | # Game Theory 2 | 3 | ## What is Game Theory? 4 | 5 | ![What is Game Theory](images/what-is-game-theory.png) 6 | 7 | ## Simple game 8 | 9 | Given the simple game below: 10 | 11 | ![A Simple Game](images/game-example.png) 12 | 13 | ### Minimax 14 | 15 | The game-matrix can be calculated as: 16 | 17 | ![Minimax](images/minimax.png) 18 | 19 | And the result of minimax for this game is `3`, because of the Fundamental Result Theorem. 20 | 21 | ### Fundamental Result Theorem 22 | 23 | ![Fundamental Result Theorem](images/fundamental-result.png) 24 | 25 | ## Non-deterministic Game 26 | 27 | ![Non-deterministic Game](images/non-deterministic-game.png) 28 | 29 | ### Von Neumann Theorem 30 | 31 | ![Von Neumann Theorem](images/von-neumann.png) 32 | 33 | The "Other Theorem" is the Fundamental Result Theorem. 34 | 35 | 36 | ## Hidden information Game 37 | 38 | ![Hidden information Game](images/hidden-info-game.png) 39 | 40 | ![Hidden information Game 2](images/hidden-info-game-2.png) 41 | 42 | ### Mixed Strategy 43 | 44 | ![Mixed Strategy](images/mixed-strategy.png) 45 | 46 | ### Mini poker result 47 | 48 | ![Mini Poker Result](images/mini-poker-result.png) 49 | 50 | ## Prisioner's Dilemma (Non Zero Sum Game) 51 | 52 | ![Prisioner's Dilemma](images/prisioners-dilemma.png) 53 | 54 | ## Nash Equilibrium 55 | 56 | ![Nash Equilibrium](images/nash-equilibrium.png) 57 | 58 | ### Nash Equilibrium Example 59 | 60 | ![Nash Equilibrium Example](images/nash-equilibrium-example.png) 61 | 62 | ### Nash Equilibrium Implications 63 | 64 | ![Nash Equilibrium Implications](images/nash-equilibrium-implications.png) 65 | 66 | ## Summary 67 | 68 | ![Game theory summary](images/gt-summary.png) 69 | 70 | Additional References: 71 | - [Andrew Moore's slides on Zero-Sum Games](http://www.autonlab.org/tutorials/gametheory.html) 72 | - [Andrew Moore's slides on Non-Zero-Sum Games](http://www.autonlab.org/tutorials/nonzerosum.html) 73 | 74 | 75 | -------------------------------------------------------------------------------- /classes/model-evaluation-and-validation/managing-error-and-complexity.md: -------------------------------------------------------------------------------- 1 | # Managing error and complexity 2 | 3 | ## Causes of error 4 | 5 | Errors are mainly due to 2 common causes: 6 | 7 | - Bias: which means a model is unable to represent the whole complexity of the underlying data. 8 | - Variance: whcih means a model is too sensitive due to the limited data it was trained on. 9 | 10 | ## Error due to Bias - Accuracy and Underfitting 11 | 12 | Bias occurs when a model has enough data but is not complex enough to capture the underlying relationships. As a result, the model consistently and systematically misrepresents the data, leading to low accuracy in prediction. This is known as *underfitting*. 13 | 14 | To overcome error from bias, we need a more complex model. 15 | 16 | ## Error due to Variance - Precision and Overfitting 17 | 18 | Some variance is normal, but too much variance indicates that the model is unable to generalize its predictions to the larger population. High sensitivity to the training set is also known as *overfitting*, and generally occurs when either the model is too complex or when we do not have enough data to support it. 19 | 20 | We can typically reduce the variability of a model's predictions and increase precision by training on more data. If more data is unavailable, we can also control variance by limiting our model's complexity. 21 | 22 | ## Overfitting vs Underfitting 23 | 24 | ![](http://scikit-learn.org/stable/_images/sphx_glr_plot_underfitting_overfitting_0011.png) 25 | 26 | ## Curse of Dimensionality 27 | 28 | As the number of features or dimensions grows, the amount of data we need to generalize accurately grows exponentially. 29 | 30 | ## Learning Curves - Identifying Bias and Variance 31 | 32 | ### Bias 33 | When the training and testing errors converge and are quite high this usually means the model is biased. No matter how much data we feed it, the model cannot represent the underlying relationship and therefore has systematic high errors. 34 | 35 | ### Variance 36 | When there is a large gap between the training and testing error this generally means the model suffers from high variance. Unlike a biased model, models that suffer from variance generally require more data to improve. We can also limit variance by simplifying the model to represent only the most important features of the data. -------------------------------------------------------------------------------- /classes/supervised-learning/artificial-neural-networks.md: -------------------------------------------------------------------------------- 1 | # Artificial Neural Networks 2 | 3 | ## Perceptrons 4 | 5 | ![Perceptron](images/perceptron.png) 6 | 7 | ### Boolean Operation Perceptrons 8 | 9 | These perceptrons can be defined by the W and Θ values. Also note that there are multiple values of W and Θ that implement these operators. 10 | 11 | #### AND 12 | 13 | | X1 | X2 | W1 | W2 | Θ | Σ X*W | Y | AND | 14 | |----|----|----|----|---|-------|---|-----| 15 | | 0 | 0 | 1 | 1 | 2 | 0 | 0 | 0 | 16 | | 1 | 0 | 1 | 1 | 2 | 1 | 0 | 0 | 17 | | 0 | 1 | 1 | 1 | 2 | 1 | 0 | 0 | 18 | | 1 | 1 | 1 | 1 | 2 | 2 | 1 | 1 | 19 | 20 | #### OR 21 | 22 | | X1 | X2 | W1 | W2 | Θ | Σ X*W | Y | OR | 23 | |----|----|----|----|---|-------|---|-----| 24 | | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 25 | | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 26 | | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 27 | | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 1 | 28 | 29 | #### NOT 30 | 31 | | X1 | W1 | Θ | Σ X*W | Y | NOT | 32 | |----|----|---|-------|---|-----| 33 | | 0 | -1 | 0 | 0 | 1 | 1 | 34 | | 1 | -1 | 0 | -1 | 0 | 0 | 35 | 36 | #### XOR 37 | 38 | | X1 | X2 | X3 (X1 AND X2) | W1 | W2 | W3 | Θ | Σ X*W | Y | XOR | 39 | |----|----|----------------|----|----|----|---|-------|---|-----| 40 | | 0 | 0 | 0 | 1 | 1 | -2 | 1 | 0 | 0 | 0 | 41 | | 1 | 0 | 0 | 1 | 1 | -2 | 1 | 1 | 1 | 1 | 42 | | 0 | 1 | 0 | 1 | 1 | -2 | 1 | 1 | 1 | 1 | 43 | | 1 | 1 | 1 | 1 | 1 | -2 | 1 | 0 | 0 | 0 | 44 | 45 | ## Perceptron Training Rule 46 | 47 | ![Perceptron Training](images/perceptron-training.png) 48 | 49 | ## Gradient Descent Rule 50 | 51 | ![Gradient Descent](images/gradient-descent.png) 52 | 53 | ## Comparison of Learning Rules 54 | 55 | ![Comparison](images/comparison-of-learning-rules.png) 56 | 57 | ## Sigmoid 58 | 59 | ![Sigmoid](images/sigmoid.png) 60 | 61 | ## Neural Network Sketch / Backpropagation 62 | 63 | ![Backpropagation](images/backpropagation.png) 64 | 65 | ## Optimizing Weights 66 | 67 | ![Optimizing Weights](images/optimizing-weights.png) 68 | 69 | ## Restriction Bias 70 | 71 | ![Restriction Bias](images/restriction-bias.png) 72 | 73 | ## Preference Bias 74 | ![Preference Bias](images/preference-bias.png) 75 | 76 | ## Summary 77 | ![Summary](images/summary.png) -------------------------------------------------------------------------------- /projects/boston-housing-prices/README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Engineer Nanodegree 2 | # Model Evaluation and Validation 3 | ## Project: Predicting Boston Housing Prices 4 | 5 | ### Install 6 | 7 | This project requires **Python 2.7** and the following Python libraries installed: 8 | 9 | - [NumPy](http://www.numpy.org/) 10 | - [Pandas](http://pandas.pydata.org/) 11 | - [matplotlib](http://matplotlib.org/) 12 | - [scikit-learn](http://scikit-learn.org/stable/) 13 | 14 | You will also need to have software installed to run and execute a [Jupyter Notebook](http://ipython.org/notebook.html) 15 | 16 | If you do not have Python installed yet, it is highly recommended that you install the [Anaconda](http://continuum.io/downloads) distribution of Python, which already has the above packages and more included. Make sure that you select the Python 2.7 installer and not the Python 3.x installer. 17 | 18 | ### Code 19 | 20 | Template code is provided in the `boston_housing.ipynb` notebook file. You will also be required to use the included `visuals.py` Python file and the `housing.csv` dataset file to complete your work. While some code has already been implemented to get you started, you will need to implement additional functionality when requested to successfully complete the project. Note that the code included in `visuals.py` is meant to be used out-of-the-box and not intended for students to manipulate. If you are interested in how the visualizations are created in the notebook, please feel free to explore this Python file. 21 | 22 | ### Run 23 | 24 | In a terminal or command window, navigate to the top-level project directory `boston_housing/` (that contains this README) and run one of the following commands: 25 | 26 | ```bash 27 | ipython notebook boston_housing.ipynb 28 | ``` 29 | or 30 | ```bash 31 | jupyter notebook boston_housing.ipynb 32 | ``` 33 | 34 | This will open the Jupyter Notebook software and project file in your browser. 35 | 36 | ### Data 37 | 38 | The modified Boston housing dataset consists of 490 data points, with each datapoint having 3 features. This dataset is a modified version of the Boston Housing dataset found on the [UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets/Housing). 39 | 40 | **Features** 41 | 1. `RM`: average number of rooms per dwelling 42 | 2. `LSTAT`: percentage of population considered lower status 43 | 3. `PTRATIO`: pupil-student ratio by town 44 | 45 | **Target Variable** 46 | 4. `MEDV`: median value of owner-occupied homes -------------------------------------------------------------------------------- /projects/titanic-survival-exploration/README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Engineer Nanodegree 2 | ## Introduction and Foundations 3 | ## Project: Titanic Survival Exploration 4 | 5 | ### Install 6 | 7 | This project requires **Python 2.7** and the following Python libraries installed: 8 | 9 | - [NumPy](http://www.numpy.org/) 10 | - [Pandas](http://pandas.pydata.org) 11 | - [matplotlib](http://matplotlib.org/) 12 | - [scikit-learn](http://scikit-learn.org/stable/) 13 | 14 | You will also need to have software installed to run and execute a [Jupyter Notebook](http://ipython.org/notebook.html) 15 | 16 | If you do not have Python installed yet, it is highly recommended that you install the [Anaconda](http://continuum.io/downloads) distribution of Python, which already has the above packages and more included. Make sure that you select the Python 2.7 installer and not the Python 3.x installer. 17 | 18 | ### Code 19 | 20 | Template code is provided in the notebook `titanic_survival_exploration.ipynb` notebook file. Additional supporting code can be found in `visuals.py`. While some code has already been implemented to get you started, you will need to implement additional functionality when requested to successfully complete the project. Note that the code included in `visuals.py` is meant to be used out-of-the-box and not intended for students to manipulate. If you are interested in how the visualizations are created in the notebook, please feel free to explore this Python file. 21 | 22 | ### Run 23 | 24 | In a terminal or command window, navigate to the top-level project directory `titanic_survival_exploration/` (that contains this README) and run one of the following commands: 25 | 26 | ```bash 27 | jupyter notebook titanic_survival_exploration.ipynb 28 | ``` 29 | or 30 | ```bash 31 | ipython notebook titanic_survival_exploration.ipynb 32 | ``` 33 | 34 | This will open the Jupyter Notebook software and project file in your web browser. 35 | 36 | ### Data 37 | 38 | The dataset used in this project is included as `titanic_data.csv`. This dataset is provided by Udacity and contains the following attributes: 39 | 40 | **Features** 41 | - `pclass` : Passenger Class (1 = 1st; 2 = 2nd; 3 = 3rd) 42 | - `name` : Name 43 | - `sex` : Sex 44 | - `age` : Age 45 | - `sibsp` : Number of Siblings/Spouses Aboard 46 | - `parch` : Number of Parents/Children Aboard 47 | - `ticket` : Ticket Number 48 | - `fare` : Passenger Fare 49 | - `cabin` : Cabin 50 | - `embarked` : Port of Embarkation (C = Cherbourg; Q = Queenstown; S = Southampton) 51 | 52 | **Target Variable** 53 | - `survival` : Survival (0 = No; 1 = Yes) -------------------------------------------------------------------------------- /classes/unsupervised-learning/clustering.md: -------------------------------------------------------------------------------- 1 | # Clustering 2 | 3 | ## K-Means 4 | 5 | ### K-Means Algorithm 6 | 7 | 1. Add `K` centroids to the data at random positions. 8 | 9 | ![Add centroids](images/add-centroids.png) 10 | 11 | 2. Associate each data point to the closest centroid (aka association step) 12 | 13 | ![Associate step](images/associate-step.png) 14 | 15 | 3. Move the centroids to the mean distance between all associated points 16 | 17 | ![Move centroids](images/move-centroids.png) 18 | 19 | 4. Repeat step 2 and 3 `n` times, or until some other stop-condition has been met. 20 | 21 | ### K-Means is not deterministic 22 | 23 | The initial position of the centroids will influence the final outcome of the algorithm. See the example below: 24 | 25 | ![uniform 1](images/uniform-1.png) 26 | 27 | ![uniform 2](images/uniform-2.png) 28 | 29 | To solve this problem, we run the algorithm multiple times and average the results. 30 | 31 | ### K-Means and sklearn 32 | 33 | ```python 34 | class sklearn.cluster.KMeans(n_clusters=8, init='k-means++', n_init=10, max_iter=300, 35 | tol=0.0001, precompute_distances='auto', verbose=0, 36 | random_state=None, copy_x=True, n_jobs=1, algorithm='auto') 37 | ``` 38 | 39 | - `n_clusters`: number of centroids to initialize. Also defines the number of clusters to be found. This should be set using domain knowledge of the problem. 40 | - `max_iter`: number of iterations (associate points, move centroids, repeat) to be run. 41 | - `n_init`: number of times the algorithm will run before outputing the results. 42 | 43 | ### K-means references 44 | - [Sci-kit learn documentation](http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html) 45 | - [Visualizing K-means](https://www.naftaliharris.com/blog/visualizing-k-means-clustering/) 46 | 47 | 48 | ## Single Linkage Clustering 49 | 50 | ### Single Linkage Clustering Algorithm 51 | 52 | ![Single Linkage Clustering](images/slc.png) 53 | 54 | ## Soft Clustering 55 | 56 | ![soft clustering](images/soft-clustering.png) 57 | 58 | - Can assign the same point to multiple clusters 59 | - Probabilistic approach 60 | 61 | ### Expectation Maximization 62 | 63 | ![Expectation Maximization formula](images/expectation-maximization.png) 64 | 65 | ### Expectation Maximization Properties 66 | 67 | ![Expectation Maximization Properties](images/em-properties.png) 68 | 69 | ## Clustering Properties 70 | 71 | ![Clustering Properties](images/clustering-properties.png) 72 | 73 | ## Impossibility Theorem 74 | 75 | ![Impossibility Theorem](images/impossibility-theorem.png) 76 | 77 | ## Summary 78 | 79 | ![Summary](images/clustering-summary.png) -------------------------------------------------------------------------------- /_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{ site.title | default: site.github.repository_name }} by {{ site.github.owner_name }} 7 | 8 | 9 | 10 | 13 | 14 | 15 |
16 |
17 |

{{ site.title | default: site.github.repository_name }}

18 |

{{ site.description | default: site.github.project_tagline }}

19 | 20 | {% if site.github.is_project_page %} 21 |

{{ github_name }}

22 | {% endif %} 23 | 24 | Go to Index 25 | 26 | {% if site.github.is_user_page %} 27 |

View My GitHub Profile

28 | {% endif %} 29 | 30 | {% if site.show_downloads %} 31 | 36 | {% endif %} 37 |
38 |
39 | 40 | {{ content }} 41 | 42 |
43 | 49 |
50 | 51 | 52 | 53 | {% if site.google_analytics %} 54 | 63 | {% endif %} 64 | 65 | 66 | -------------------------------------------------------------------------------- /projects/customer_segments/README.md: -------------------------------------------------------------------------------- 1 | # Content: Unsupervised Learning 2 | ## Project: Creating Customer Segments 3 | 4 | ### Install 5 | 6 | This project requires **Python 2.7** and the following Python libraries installed: 7 | 8 | - [NumPy](http://www.numpy.org/) 9 | - [Pandas](http://pandas.pydata.org) 10 | - [matplotlib](http://matplotlib.org/) 11 | - [scikit-learn](http://scikit-learn.org/stable/) 12 | 13 | You will also need to have software installed to run and execute a [Jupyter Notebook](http://ipython.org/notebook.html) 14 | 15 | If you do not have Python installed yet, it is highly recommended that you install the [Anaconda](http://continuum.io/downloads) distribution of Python, which already has the above packages and more included. Make sure that you select the Python 2.7 installer and not the Python 3.x installer. 16 | 17 | ### Code 18 | 19 | Template code is provided in the `customer_segments.ipynb` notebook file. You will also be required to use the included `visuals.py` Python file and the `housing.csv` dataset file to complete your work. While some code has already been implemented to get you started, you will need to implement additional functionality when requested to successfully complete the project. Note that the code included in `visuals.py` is meant to be used out-of-the-box and not intended for students to manipulate. If you are interested in how the visualizations are created in the notebook, please feel free to explore this Python file. 20 | 21 | ### Run 22 | 23 | In a terminal or command window, navigate to the top-level project directory `customer_segments/` (that contains this README) and run one of the following commands: 24 | 25 | ```bash 26 | ipython notebook customer_segments.ipynb 27 | ``` 28 | or 29 | ```bash 30 | jupyter notebook customer_segments.ipynb 31 | ``` 32 | 33 | This will open the Jupyter Notebook software and project file in your browser. 34 | 35 | ## Data 36 | 37 | The customer segments data is included as a selection of 440 data points collected on data found from clients of a wholesale distributor in Lisbon, Portugal. More information can be found on the [UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets/Wholesale+customers). 38 | 39 | Note (m.u.) is shorthand for *monetary units*. 40 | 41 | **Features** 42 | 1) `Fresh`: annual spending (m.u.) on fresh products (Continuous); 43 | 2) `Milk`: annual spending (m.u.) on milk products (Continuous); 44 | 3) `Grocery`: annual spending (m.u.) on grocery products (Continuous); 45 | 4) `Frozen`: annual spending (m.u.) on frozen products (Continuous); 46 | 5) `Detergents_Paper`: annual spending (m.u.) on detergents and paper products (Continuous); 47 | 6) `Delicatessen`: annual spending (m.u.) on and delicatessen products (Continuous); 48 | 7) `Channel`: {Hotel/Restaurant/Cafe - 1, Retail - 2} (Nominal) 49 | 8) `Region`: {Lisnon - 1, Oporto - 2, or Other - 3} (Nominal) -------------------------------------------------------------------------------- /classes/supervised-learning/neural-network-quizzes/xor-network.py: -------------------------------------------------------------------------------- 1 | # ---------- 2 | # 3 | # In this exercise, you will create a network of perceptrons that can represent 4 | # the XOR function, using a network structure like those shown in the previous 5 | # quizzes. 6 | # 7 | # You will need to do two things: 8 | # First, create a network of perceptrons with the correct weights 9 | # Second, define a procedure EvalNetwork() which takes in a list of inputs and 10 | # outputs the value of this network. 11 | # 12 | # ---------- 13 | 14 | import numpy as np 15 | 16 | class Perceptron: 17 | """ 18 | This class models an artificial neuron with step activation function. 19 | """ 20 | 21 | def __init__(self, weights = np.array([1]), threshold = 0): 22 | """ 23 | Initialize weights and threshold based on input arguments. Note that no 24 | type-checking is being performed here for simplicity. 25 | """ 26 | self.weights = weights 27 | self.threshold = threshold 28 | 29 | 30 | def activate(self, values): 31 | """ 32 | Takes in @param values, a list of numbers equal to length of weights. 33 | @return the output of a threshold perceptron with given inputs based on 34 | perceptron weights and threshold. 35 | """ 36 | 37 | # First calculate the strength with which the perceptron fires 38 | strength = np.dot(values,self.weights) 39 | 40 | # Then return 0 or 1 depending on strength compared to threshold 41 | return int(strength > self.threshold) 42 | 43 | 44 | # Part 1: Set up the perceptron network 45 | Network = [ 46 | # input layer, declare input layer perceptrons here 47 | # Input Layer: X1, X2, X3 (X1 AND X2) 48 | [ Perceptron(np.array([1,0]), 0), Perceptron(np.array([0,1]), 0), Perceptron(np.array([1,1]), 1) ], \ 49 | # output node, declare output layer perceptron here 50 | [ Perceptron(np.array([1,1,-2]), 0) ] 51 | ] 52 | 53 | # Part 2: Define a procedure to compute the output of the network, given inputs 54 | def EvalNetwork(inputValues, Network): 55 | """ 56 | Takes in @param inputValues, a list of input values, and @param Network 57 | that specifies a perceptron network. @return the output of the Network for 58 | the given set of inputs. 59 | """ 60 | 61 | inputData = inputValues 62 | # YOUR CODE HERE 63 | for layer in Network: 64 | tempInput = [] 65 | for perceptron in layer: 66 | tempInput.append(perceptron.activate(inputData)) 67 | inputData = np.array(tempInput) 68 | 69 | # Be sure your output value is a single number 70 | return inputData[0] 71 | 72 | 73 | def test(): 74 | """ 75 | A few tests to make sure that the perceptron class performs as expected. 76 | """ 77 | print "0 XOR 0 = 0?:", EvalNetwork(np.array([0,0]), Network) 78 | print "0 XOR 1 = 1?:", EvalNetwork(np.array([0,1]), Network) 79 | print "1 XOR 0 = 1?:", EvalNetwork(np.array([1,0]), Network) 80 | print "1 XOR 1 = 0?:", EvalNetwork(np.array([1,1]), Network) 81 | 82 | if __name__ == "__main__": 83 | test() -------------------------------------------------------------------------------- /classes/unsupervised-learning/dimensionality-reduction.md: -------------------------------------------------------------------------------- 1 | # Dimensionality Reduction 2 | 3 | ## Principal Component Analysis 4 | 5 | ### Definition 6 | 7 | ![PCA Definition](images/review-definition-PCA.png) 8 | 9 | ![Maximal Variation and Minimal Loss](images/maximal-variation-minimal-loss.png) 10 | 11 | ### When to use PCA 12 | 13 | ![When to use PCA](images/when-to-use-pca.png) 14 | 15 | ### PCA in sklearn 16 | 17 | ![PCA in sklearn](images/PCA-sklearn.png) 18 | 19 | ![PCA in sklearn 2](images/PCA-sklearn-2.png) 20 | 21 | ## Feature Transformation 22 | 23 | ### Definition 24 | 25 | ![Feature Transformation Definition](images/feature-transformation-definition.png) 26 | 27 | ### Independent Component Analysis 28 | 29 | Independent component analysis (ICA) is a method in which the goal is to find a linear representation of nongaussian data so that the components are statistically independent, or as independent as possible. [This paper](http://mlsp.cs.cmu.edu/courses/fall2012/lectures/ICA_Hyvarinen.pdf) describes ICA in detail. ICA has also been applied to the information retrieval problem, in a [paper](http://www.cc.gatech.edu/~isbell/papers/isbell-ica-nips-1999.pdf) written by Charles himself. 30 | 31 | [The cocktail party demo](http://research.ics.aalto.fi/ica/cocktail/cocktail_en.cgi) is an example of ICA application 32 | 33 | ![ICA notes](images/ica-notes.png) 34 | 35 | ### ICA vs PCA 36 | 37 | - ICA: 38 | - finds hidden features 39 | - finds *statistically independent* features 40 | - maximizes mutual information 41 | - order between found features don't matter 42 | - works better on nongaussian distributions 43 | - is a probabilistic analysis 44 | - PCA: 45 | - decomposes the data onto orthogonal dimensions 46 | - maximizes variance 47 | - maximizes reconstruction 48 | - order between found features matters - former features cover more variance than latter features 49 | - works better on gaussian distributions 50 | - is a linear algebra analysis 51 | 52 | ![ICA vs PCA examples](images/ica-vs-pca.png) 53 | 54 | In the image above: 55 | - *BSS* stands for Blind Source Separation problem (ie: Cocktail Party). 56 | - Directional means that ICA input direction is meaningful. For example, ICA will output two different results for a matrix M and MT, while, PCA will output the same result for both inputs. 57 | - Faces: PCA will find Brightness, then Average Face (*eigenfaces*), while ICA will find feature selectors like noses, mouths, eyes, etc. 58 | - Natural Scenes: ICA will find edges. 59 | - Documents: ICA will find topics. 60 | 61 | ![ICA vs PCA quiz](images/ica-vs-pca-2.png) 62 | 63 | ### Alternatives 64 | 65 | - RCA: Random Component Analysis consists on projecting the data into random dimensions. It works in both cases, when M < N and also where M > N (for example: Kernel Methods) 66 | - LDA: Linear Discriminant Analysis consists of using labels to find projections that summarize the data. 67 | 68 | ![Alternatives to PCA and ICA](images/alternatives.png) 69 | 70 | ### Summary 71 | 72 | [This excellent paper](http://computation.llnl.gov/casc/sapphire/pubs/148494.pdf) is a great resource for the Feature Transformation methods from this course, and beyond 73 | 74 | 75 | ![Summary](images/summary.png) -------------------------------------------------------------------------------- /classes/supervised-learning/neural-network-quizzes/perceptron-learning.py: -------------------------------------------------------------------------------- 1 | # ---------- 2 | # 3 | # In this exercise, you will update the perceptron class so that it can update 4 | # its weights. 5 | # 6 | # Finish writing the update() method so that it updates the weights according 7 | # to the perceptron update rule. Updates should be performed online, revising 8 | # the weights after each data point. 9 | # 10 | # ---------- 11 | 12 | import numpy as np 13 | 14 | 15 | class Perceptron: 16 | """ 17 | This class models an artificial neuron with step activation function. 18 | """ 19 | 20 | def __init__(self, weights = np.array([1]), threshold = 0): 21 | """ 22 | Initialize weights and threshold based on input arguments. Note that no 23 | type-checking is being performed here for simplicity. 24 | """ 25 | self.weights = weights 26 | self.threshold = threshold 27 | 28 | 29 | def activate(self, values): 30 | """ 31 | Takes in @param values, a list of numbers equal to length of weights. 32 | @return the output of a threshold perceptron with given inputs based on 33 | perceptron weights and threshold. 34 | """ 35 | 36 | # First calculate the strength with which the perceptron fires 37 | strength = np.dot(values,self.weights) 38 | 39 | # Then return 0 or 1 depending on strength compared to threshold 40 | return int(strength > self.threshold) 41 | 42 | 43 | def update(self, values, train, eta=.1): 44 | """ 45 | Takes in a 2D array @param values consisting of a LIST of inputs and a 46 | 1D array @param train, consisting of a corresponding list of expected 47 | outputs. Updates internal weights according to the perceptron training 48 | rule using these values and an optional learning rate, @param eta. 49 | """ 50 | 51 | # YOUR CODE HERE 52 | 53 | # TODO: for each data point... 54 | i = 0 55 | for dp in values: 56 | # TODO: obtain the neuron's prediction for that point 57 | pred = np.array(self.activate(dp)) 58 | 59 | # TODO: update self.weights based on prediction accuracy, learning 60 | # rate and input value 61 | self.weights = self.weights + eta*(train[i] - pred)*dp 62 | i += 1 63 | 64 | def test(): 65 | """ 66 | A few tests to make sure that the perceptron class performs as expected. 67 | Nothing should show up in the output if all the assertions pass. 68 | """ 69 | def sum_almost_equal(array1, array2, tol = 1e-6): 70 | return sum(abs(array1 - array2)) < tol 71 | 72 | p1 = Perceptron(np.array([1,1,1]),0) 73 | p1.update(np.array([[2,0,-3]]), np.array([1])) 74 | assert sum_almost_equal(p1.weights, np.array([1.2, 1, 0.7])) 75 | 76 | p2 = Perceptron(np.array([1,2,3]),0) 77 | print p2.weights 78 | p2.update(np.array([[3,2,1],[4,0,-1]]),np.array([0,0])) 79 | print p2.weights 80 | assert sum_almost_equal(p2.weights, np.array([0.7, 1.8, 2.9])) 81 | 82 | p3 = Perceptron(np.array([3,0,2]),0) 83 | print p3.weights 84 | p3.update(np.array([[2,-2,4],[-1,-3,2],[0,2,1]]),np.array([0,1,0])) 85 | print p3.weights 86 | assert sum_almost_equal(p3.weights, np.array([2.7, -0.3, 1.7])) 87 | 88 | if __name__ == "__main__": 89 | test() -------------------------------------------------------------------------------- /classes/supervised-learning/decision-trees.md: -------------------------------------------------------------------------------- 1 | # Classification Learning 2 | 3 | ## Terms 4 | 5 | - **Instances** (aka input) are vector of attributes that defines whatever the input space is. 6 | - **Concept** is a function that maps the inputs into outputs. 7 | - **Target Concept** is the actual answer. It is the concrete function that maps the inputs into outputs. 8 | - **Hypothesis class** is the set of all concepts that we are willing to study to find the target concept. 9 | - **Sample** (aka training set) is a set of all the inputs paired with their expected output that will be used to improve the concept. 10 | - **Candidate** is a concept that might be the target concept 11 | - **Testing Set** is a set of all inputs paired with their expected output that will be used to validate the candidate. 12 | 13 | ## Decision Trees: Learning 14 | 15 | Decision Trees algorithms are as following: 16 | 17 | 1. Pick the attribute that splits the data the best. 18 | 2. Ask the question about the attribute. 19 | 3. Follow the answer path 20 | 4. Go to 1, until the answer is found. 21 | 22 | ## ID3 23 | 24 | A top down learning algorithm. 25 | 26 | ![ID3 Algorithm](images/ID3.png) 27 | 28 | ### Bias of ID3 29 | 30 | ## Decision Trees: Other considerations 31 | 32 | Dealing with overfitting 33 | 34 | For continuous 35 | - For continuous inputs, we create discrete attributes by using ranges of values. Example: age between 20 and 30 - age is continuous but ages between 20 and 30 is a true-false question. 36 | - Prunning: collapse leaves if errors are acceptable. 37 | 38 | ### Pruning 39 | 40 | Pruning is a technique in machine learning that reduces the size of decision trees by removing sections of the tree that provide little power to classify instances. Pruning reduces the complexity of the final classifier, and hence improves predictive accuracy by the reduction of overfitting. 41 | 42 | - [Wikipedia](https://en.wikipedia.org/wiki/Pruning_(decision_trees)) 43 | 44 | ## Decision Trees: Wrap up 45 | 46 | - Decision tree representation 47 | - Top down algorithm for inducing a decision tree (ID3) 48 | - Expressiveness of DTs 49 | - Bias of ID3 50 | - Best attributes (`Gain(S,A)`) 51 | - Dealing with overfitting (pruning) 52 | 53 | 54 | # More decision trees 55 | 56 | ## Decision tree graph representation 57 | 58 | ![Graph representation](images/DT-Graph.png) 59 | 60 | ## Decision Trees Accuracy 61 | 62 | ```python 63 | from sklearn import tree 64 | clf = tree.DecisionTreeClassifier(min_samples_split=10) 65 | clf = clf.fit(features_train, labels_train) 66 | 67 | from sklearn.metrics import accuracy_score 68 | acc = accuracy_score(labels_test, clf.predict(features_test)) 69 | ``` 70 | 71 | ## Entropy 72 | 73 | ![Entropy](images/Entropy.png) 74 | 75 | ### Calculating Entropy Example 76 | 77 | Suppose we have a sample like: `S S F F`, where S is slow and F is fast. 78 | From this sample, we can infer that pi of slow is 0.5 79 | 80 | So the entropy could be calculated like: 81 | ```python 82 | import math 83 | entropy = 2*( (-0.5) * math.log(0.5, 2)) # resulting in 1 84 | ``` 85 | 86 | ## Information Gain 87 | 88 | ![Information Gain](images/information-gain.png) 89 | 90 | ## sklearn.tree DecisionTreeClassifier default criterion 91 | 92 | Scikit learn uses Gini impurity as default criterion for creating Decision Trees Classifiers. To use the Entropy criterion instead, one should do the following: 93 | 94 | ```python 95 | from sklearn.tree import DecisionTreeClassifier 96 | clf = DecisionTreeClassifier(criterion='entropy') 97 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Nanodegree Class Notes 2 | 3 | This repo stores all my class notes, exercises and projects for [Udacity's Machine Learning Nanodegree](https://www.udacity.com/course/machine-learning-engineer-nanodegree--nd009/) starting on November 5th 2016. 4 | 5 | ## Class Notes 6 | 7 | 1. [Welcome to the Nanodegree](classes/welcome-to-the-nano-degree/notes/welcome-to-the-mlnd-program.md) 8 | 1. [Welcome to the Machine Learning Nanodegree Program](classes/welcome-to-the-nano-degree/notes/welcome-to-the-mlnd-program.md) 9 | 2. [What is Machine Learning](classes/welcome-to-the-nano-degree/notes/what-is-machine-learning.md) 10 | 2. [Model Evaluation and Validation](classes/model-evaluation-and-validation/evaluation-and-validation.md) 11 | 1. [Evaluation and Validation](classes/model-evaluation-and-validation/evaluation-and-validation.md) 12 | 2. [Managing Error and Complexity](classes/model-evaluation-and-validation/managing-error-and-complexity.md) 13 | 3. [Supervised Learning](classes/supervised-learning/supervised-learning.md) 14 | 1. [Supervised Learning Tasks](classes/supervised-learning/supervised-learning.md) 15 | 2. [Decision Trees](classes/supervised-learning/decision-trees.md) 16 | 3. [Artificial Neural Networks](classes/supervised-learning/artificial-neural-networks.md) 17 | 4. [Support Vector Machines](classes/supervised-learning/support-vector-machines.md) 18 | 5. [Non Parametric Models](classes/supervised-learning/nonparametric-models.md) 19 | 6. [Bayesian Methods](classes/supervised-learning/bayesian-methods.md) 20 | 7. [Ensemble of Learners](classes/supervised-learning/ensemble-learners.md) 21 | 4. [Unsupervised Learning](classes/unsupervised-learning/clustering.md) 22 | 1. [Clustering](classes/unsupervised-learning/clustering.md) 23 | 2. [Feature Engineering](classes/unsupervised-learning/feature-engineering.md) 24 | 3. [Dimesionality Reduction](classes/unsupervised-learning/dimensionality-reduction.md) 25 | 5. [Reinforcement Learning](classes/reinforcement-learning/markov-decision-process.md) 26 | 1. [Markov Decision Process](classes/reinforcement-learning/markov-decision-process.md) 27 | 2. [Reinforcement Learning](classes/reinforcement-learning/reinforcement-learning.md) 28 | 3. [Game Theory](classes/reinforcement-learning/game-theory.md) 29 | 6. [Deep Learning](classes/deep-learning/from-machine-learning-to-deep-learning.md) 30 | 1. [From Machine Learning to Deep Learning](classes/deep-learning/from-machine-learning-to-deep-learning.md) 31 | 2. [Deep Neural Networks](classes/deep-learning/deep-neural-networks.md) 32 | 3. [Convolutional Neural Networks](classes/deep-learning/convolutional-neural-networks.md) 33 | 4. [Deep Models for Text and Sequences](classes/deep-learning/deep-models-for-text-and-sequences.md) 34 | 35 | ## Projects 36 | 1. Exploratory Project: [Titanic Survival](projects/titanic-survival-exploration/report.html) 37 | 2. Model and Evaluation Project: [Boston Housing Prices](projects/boston-housing-prices/report.html) 38 | 3. Supervised Learning Project: [Finding Donors for CharityML](projects/finding-donors/report.html) 39 | 4. Unsupervised Learning Project: [Creating Customers Segment](projects/customer_segments/report.html) 40 | 5. Reinforcement Learning Project: [Train a Smartcab to Drive](projects/smartcab/report.html) 41 | 6. Deep Learning Project 1: Build a Digit Recognition Program 42 | 6. Deep Learning Project 2: [Image Classification](projects/image-classification/report.html) 43 | 7. Capstone Project: TBA 44 | 45 | ## Extra 46 | 47 | - [Statistics Cheatsheet](statistics/cheatsheet.md) 48 | -------------------------------------------------------------------------------- /projects/smartcab/smartcab/planner.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | class RoutePlanner(object): 4 | """ Complex route planner that is meant for a perpendicular grid network. """ 5 | 6 | def __init__(self, env, agent): 7 | self.env = env 8 | self.agent = agent 9 | self.destination = None 10 | 11 | def route_to(self, destination=None): 12 | """ Select the destination if one is provided, otherwise choose a random intersection. """ 13 | 14 | self.destination = destination if destination is not None else random.choice(self.env.intersections.keys()) 15 | 16 | def next_waypoint(self): 17 | """ Creates the next waypoint based on current heading, location, 18 | intended destination and L1 distance from destination. """ 19 | 20 | # Collect global location details 21 | bounds = self.env.grid_size 22 | location = self.env.agent_states[self.agent]['location'] 23 | heading = self.env.agent_states[self.agent]['heading'] 24 | 25 | delta_a = (self.destination[0] - location[0], self.destination[1] - location[1]) 26 | delta_b = (bounds[0] + delta_a[0] if delta_a[0] <= 0 else delta_a[0] - bounds[0], \ 27 | bounds[1] + delta_a[1] if delta_a[1] <= 0 else delta_a[1] - bounds[1]) 28 | 29 | # Calculate true difference in location based on world-wrap 30 | # This will pre-determine the need for U-turns from improper headings 31 | dx = delta_a[0] if abs(delta_a[0]) < abs(delta_b[0]) else delta_b[0] 32 | dy = delta_a[1] if abs(delta_a[1]) < abs(delta_b[1]) else delta_b[1] 33 | 34 | # First check if destination is at location 35 | if dx == 0 and dy == 0: 36 | return None 37 | 38 | # Next check if destination is cardinally East or West of location 39 | elif dx != 0: 40 | 41 | if dx * heading[0] > 0: # Heading the correct East or West direction 42 | return 'forward' 43 | elif dx * heading[0] < 0 and heading[0] < 0: # Heading West, destination East 44 | if dy > 0: # Destination also to the South 45 | return 'left' 46 | else: 47 | return 'right' 48 | elif dx * heading[0] < 0 and heading[0] > 0: # Heading East, destination West 49 | if dy < 0: # Destination also to the North 50 | return 'left' 51 | else: 52 | return 'right' 53 | elif dx * heading[1] > 0: # Heading North destination West; Heading South destination East 54 | return 'left' 55 | else: 56 | return 'right' 57 | 58 | # Finally, check if destination is cardinally North or South of location 59 | elif dy != 0: 60 | 61 | if dy * heading[1] > 0: # Heading the correct North or South direction 62 | return 'forward' 63 | elif dy * heading[1] < 0 and heading[1] < 0: # Heading North, destination South 64 | if dx < 0: # Destination also to the West 65 | return 'left' 66 | else: 67 | return 'right' 68 | elif dy * heading[1] < 0 and heading[1] > 0: # Heading South, destination North 69 | if dx > 0: # Destination also to the East 70 | return 'left' 71 | else: 72 | return 'right' 73 | elif dy * heading[0] > 0: # Heading West destination North; Heading East destination South 74 | return 'right' 75 | else: 76 | return 'left' -------------------------------------------------------------------------------- /classes/supervised-learning/bayesian-methods-quizzes/mini-project/optimal-classifier.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------ 2 | 3 | # 4 | # Bayes Optimal Classifier 5 | # 6 | # In this quiz we will compute the optimal label for a second missing word in a row 7 | # based on the possible words that could be in the first blank 8 | # 9 | # Finish the procedure, LaterWords(), below 10 | # 11 | # You may want to import your code from the previous programming exercise! 12 | # 13 | 14 | import operator 15 | import collections 16 | # import re 17 | 18 | sample_memo = ''' 19 | Milt, we're gonna need to go ahead and move you downstairs into storage B. We have some new people coming in, and we need all the space we can get. So if you could just go ahead and pack up your stuff and move it down there, that would be terrific, OK? 20 | Oh, and remember: next Friday... is Hawaiian shirt day. So, you know, if you want to, go ahead and wear a Hawaiian shirt and jeans. 21 | Oh, oh, and I almost forgot. Ahh, I'm also gonna need you to go ahead and come in on Sunday, too... 22 | Hello Peter, whats happening? Ummm, I'm gonna need you to go ahead and come in tomorrow. So if you could be here around 9 that would be great, mmmk... oh oh! and I almost forgot ahh, I'm also gonna need you to go ahead and come in on Sunday too, kay. We ahh lost some people this week and ah, we sorta need to play catch up. 23 | ''' 24 | 25 | corrupted_memo = ''' 26 | Yeah, I'm gonna --- you to go ahead --- --- complain about this. Oh, and if you could --- --- and sit at the kids' table, that'd be --- 27 | ''' 28 | 29 | data_list = sample_memo.strip().split() 30 | 31 | words_to_guess = ["ahead","could"] 32 | 33 | def LaterWords(sample,word,distance): 34 | '''@param sample: a sample of text to draw from 35 | @param word: a word occuring before a corrupted sequence 36 | @param distance: how many words later to estimate (i.e. 1 for the next word, 2 for the word after that) 37 | @returns: a single word which is the most likely possibility 38 | ''' 39 | 40 | # These are commented out because the test assumes "Sunday" <> "sunday" 41 | # text = str.lower(sample) 42 | # text = re.sub(r"[^a-z '-]", "", text) 43 | text = sample 44 | 45 | words = text.split(' ') 46 | word_count = len(words) 47 | 48 | # Given a word, collect the relative probabilities of possible following words 49 | # from @sample. You may want to import your code from the maximum likelihood exercise. 50 | 51 | def NextWordProbability(w): 52 | result = collections.defaultdict(int) 53 | for idx, val in enumerate(words): 54 | if w == val: 55 | if idx+1 < len(words): 56 | result[words[idx+1]] += 1 57 | 58 | return result 59 | 60 | # Repeat the above process--for each distance beyond 1, evaluate the words that 61 | # might come after each word, and combine them weighting by relative probability 62 | # into an estimate of what might appear next. 63 | 64 | 65 | leafs = [] 66 | def ComputeProbabilities(w, d): 67 | nextWordProbs = NextWordProbability(w) 68 | probs = {k: float(v) / float(word_count) for k, v in nextWordProbs.items()} 69 | if d == 1: 70 | leafs.append(probs) 71 | return probs 72 | else: 73 | r = {} 74 | for k, v in probs.items(): 75 | r[k] = {i: float(v) * float(j) for i, j in ComputeProbabilities(k, d-1).items()} 76 | return r 77 | 78 | probs = ComputeProbabilities(word, distance) 79 | 80 | # Find the word with highest probability 81 | counter = reduce(operator.add, map(collections.Counter, leafs)) 82 | 83 | return counter.most_common(1)[0][0] 84 | 85 | print LaterWords(sample_memo,"ahead",2) 86 | print LaterWords(sample_memo,"in",2) -------------------------------------------------------------------------------- /classes/model-evaluation-and-validation/evaluation-and-validation.md: -------------------------------------------------------------------------------- 1 | # Evaluation and Validation 2 | 3 | ## SKLearn: Train and Test split data 4 | 5 | We split data into training sets and testing sets, so we don't overfit the model to a single set of data. That way our model is more resilient to changes in the data and can infer better results onto data not seen before. 6 | 7 | ```python 8 | # scikit 0.17 9 | from sklearn.cross_validation import train_test_split 10 | train_x, test_x, train_y, test_y = \ 11 | train_test_split(data, target, test_size, random_state) 12 | 13 | # scikit 0.18 14 | from sklearn.model_selection import train_test_split 15 | train_x, test_x, train_y, test_y = \ 16 | train_test_split(data, target, test_size, random_state) 17 | ``` 18 | 19 | [Official Documentation](http://scikit-learn.org/stable/modules/cross_validation.html) 20 | 21 | ## Confusion Matrix 22 | 23 | Confusion Matrix is the matrix composed by the results plotted on predicted vs real axis. For example, given the following matrix: 24 | 25 | ``` 26 | 45 32 27 | 20 67 28 | ``` 29 | 30 | We can observe that: 31 | - 45 were labeled correctly as Negative (aka `True Negative`) 32 | - 32 were labeled incorrectly as Positive (aka `False Positive`) 33 | - 20 were labeled incorrectly as Negative (aka `False Negative`) 34 | - 67 were labeled correctly as Positive (aka `True Positive`) 35 | 36 | ## Recall 37 | 38 | **Recall** is the fraction given by: `True Positives / (True Positives + False Negatives)` 39 | 40 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html) 41 | 42 | ## Precision 43 | 44 | **Precision** is the fraction given by: `True Positives / (True Positives + False Positives)` 45 | 46 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html) 47 | 48 | ## F1 Score 49 | 50 | **F1 score** is the weighted average between precision and recall: `F1 = 2 * (precision * recall) / (precision + recall)` 51 | 52 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html#sklearn.metrics.f1_score) 53 | 54 | ## Mean Absolute Error 55 | 56 | For continuous data, we need to care how close the prediction is. For this, we can use **Mean Absolute Error**, which is the sum of the absolute deviations from the corresponding data points divided by the number of data points. 57 | 58 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_error.html#sklearn.metrics.mean_absolute_error) 59 | 60 | ## Mean Squared Error 61 | 62 | Mean squared is the most common metric to measure model performance. In contrast with absolute error, the residual error (the difference between predicted and the true value) is squared. 63 | 64 | Some benefits of squaring the residual error is that error terms are positive, it emphasizes larger errors over smaller errors, and is differentiable. Being differentiable allows us to use calculus to find minimum or maximum values, often resulting in being more computationally efficient. 65 | 66 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html#sklearn.metrics.mean_squared_error) 67 | 68 | 69 | ## Regressing Score Functions 70 | 71 | ## R2 Score 72 | 73 | Computes the coefficient of determination of predictions for true values. This is the default scoring method for regression learners in scikit-learn 74 | 75 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html#sklearn.metrics.r2_score) 76 | 77 | ## Explained variance score 78 | 79 | Measures the proportion to which a mathematical model accounts for the variation (dispersion) of a given data set. 80 | 81 | [Scikit reference](http://scikit-learn.org/stable/modules/generated/sklearn.metrics.explained_variance_score.html#sklearn.metrics.explained_variance_score) -------------------------------------------------------------------------------- /projects/finding-donors/README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Engineer Nanodegree 2 | # Supervised Learning 3 | ## Project: Finding Donors for CharityML 4 | 5 | ### Install 6 | 7 | This project requires **Python 2.7** and the following Python libraries installed: 8 | 9 | - [NumPy](http://www.numpy.org/) 10 | - [Pandas](http://pandas.pydata.org) 11 | - [matplotlib](http://matplotlib.org/) 12 | - [scikit-learn](http://scikit-learn.org/stable/) 13 | 14 | You will also need to have software installed to run and execute an [iPython Notebook](http://ipython.org/notebook.html) 15 | 16 | We recommend students install [Anaconda](https://www.continuum.io/downloads), a pre-packaged Python distribution that contains all of the necessary libraries and software for this project. 17 | 18 | ### Code 19 | 20 | Template code is provided in the `finding_donors.ipynb` notebook file. You will also be required to use the included `visuals.py` Python file and the `census.csv` dataset file to complete your work. While some code has already been implemented to get you started, you will need to implement additional functionality when requested to successfully complete the project. Note that the code included in `visuals.py` is meant to be used out-of-the-box and not intended for students to manipulate. If you are interested in how the visualizations are created in the notebook, please feel free to explore this Python file. 21 | 22 | ### Run 23 | 24 | In a terminal or command window, navigate to the top-level project directory `finding_donors/` (that contains this README) and run one of the following commands: 25 | 26 | ```bash 27 | ipython notebook finding_donors.ipynb 28 | ``` 29 | or 30 | ```bash 31 | jupyter notebook finding_donors.ipynb 32 | ``` 33 | 34 | This will open the iPython Notebook software and project file in your browser. 35 | 36 | ### Data 37 | 38 | The modified census dataset consists of approximately 32,000 data points, with each datapoint having 13 features. This dataset is a modified version of the dataset published in the paper *"Scaling Up the Accuracy of Naive-Bayes Classifiers: a Decision-Tree Hybrid",* by Ron Kohavi. You may find this paper [online](https://www.aaai.org/Papers/KDD/1996/KDD96-033.pdf), with the original dataset hosted on [UCI](https://archive.ics.uci.edu/ml/datasets/Census+Income). 39 | 40 | **Features** 41 | - `age`: Age 42 | - `workclass`: Working Class (Private, Self-emp-not-inc, Self-emp-inc, Federal-gov, Local-gov, State-gov, Without-pay, Never-worked) 43 | - `education_level`: Level of Education (Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool) 44 | - `education-num`: Number of educational years completed 45 | - `marital-status`: Marital status (Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-AF-spouse) 46 | - `occupation`: Work Occupation (Tech-support, Craft-repair, Other-service, Sales, Exec-managerial, Prof-specialty, Handlers-cleaners, Machine-op-inspct, Adm-clerical, Farming-fishing, Transport-moving, Priv-house-serv, Protective-serv, Armed-Forces) 47 | - `relationship`: Relationship Status (Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried) 48 | - `race`: Race (White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black) 49 | - `sex`: Sex (Female, Male) 50 | - `capital-gain`: Monetary Capital Gains 51 | - `capital-loss`: Monetary Capital Losses 52 | - `hours-per-week`: Average Hours Per Week Worked 53 | - `native-country`: Native Country (United-States, Cambodia, England, Puerto-Rico, Canada, Germany, Outlying-US(Guam-USVI-etc), India, Japan, Greece, South, China, Cuba, Iran, Honduras, Philippines, Italy, Poland, Jamaica, Vietnam, Mexico, Portugal, Ireland, France, Dominican-Republic, Laos, Ecuador, Taiwan, Haiti, Columbia, Hungary, Guatemala, Nicaragua, Scotland, Thailand, Yugoslavia, El-Salvador, Trinadad&Tobago, Peru, Hong, Holand-Netherlands) 54 | 55 | **Target Variable** 56 | - `income`: Income Class (<=50K, >50K) 57 | -------------------------------------------------------------------------------- /statistics/cheatsheet.md: -------------------------------------------------------------------------------- 1 | # Mean 2 | 3 | ## Arithmetic Mean 4 | 5 | ![Arithmetic Mean](https://wikimedia.org/api/rest_v1/media/math/render/svg/bd2f5fb530fc192e4db7a315777f5bbb5d462c90 "Arithmetic Mean") 6 | 7 | ## Geometric Mean 8 | 9 | ![Geometric Mean](https://wikimedia.org/api/rest_v1/media/math/render/svg/c482dedc20fd9f965ef75ac9afa9956a31fc7deb "Geometric Mean") 10 | 11 | ## Harmonic Mean 12 | 13 | ![Harmonic Mean](https://wikimedia.org/api/rest_v1/media/math/render/svg/4e103f01f5bca6d830b9dcdfc5e204e57d6af091 "Harmonic Mean") 14 | 15 | ## Mean of Probability Distribution 16 | 17 | ![Discrete Probability Mean](https://wikimedia.org/api/rest_v1/media/math/render/svg/45a64aeb8b74f6b169ebfc01dc05a29eacba265c "Discrete Probability Mean") 18 | 19 | ![Continuous Probability Mean](https://wikimedia.org/api/rest_v1/media/math/render/svg/51dac384678e6d7d8429be3ec160f0feaa1151f3 "Continuous Probability Mean") 20 | 21 | --- 22 | 23 | # Mode 24 | 25 | The mode of a sample is the element that occurs most often in the collection. For example, the mode of the sample [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17] is 6. 26 | 27 | --- 28 | 29 | # Median 30 | 31 | ![Median](https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Finding_the_median.png/220px-Finding_the_median.png "Median") 32 | 33 | --- 34 | 35 | # Standard Deviation and Variance 36 | 37 | ## Variance 38 | 39 | The variance of a random variable `X` is the [expected value](https://en.wikipedia.org/wiki/Expected_value) of the squared deviation from the [mean](https://en.wikipedia.org/wiki/Mean) of `X`: 40 | 41 | Var(X) = E[(X - μ)²] 42 | 43 | Usually the expected value for most distributions is the arithmetic mean: 44 | 45 | ![Variance with arithmetic mean](http://latex.codecogs.com/gif.latex?Var(X)%3D%5Csum%7B(x_i-%5cbar%7bx%7d)^2%7D) 46 | 47 | ## Standard Deviation 48 | 49 | Standard deviation is the square root of the variance. 50 | 51 | ## Example 52 | 53 | Example: 54 | The marks of a class of eight students (that is, a population) are the following eight values: 55 | 56 | For example, the marks of a class of eight students (that is, a **[population](https://en.wikipedia.org/wiki/Statistical_population)**) are the following eight values: 57 | 58 | ![2,\ 4,\ 4,\ 4,\ 5,\ 5,\ 7,\ 9.](https://wikimedia.org/api/rest_v1/media/math/render/svg/e7c0d44f87d7dcc46301efa28031639498d4313e) 59 | 60 | These eight data points have the mean (average) of 5: 61 | ![{\frac {2+4+4+4+5+5+7+9}{8}}=5.](https://wikimedia.org/api/rest_v1/media/math/render/svg/694f1dcd96000d87a5517614ca9348272e0e993f) 62 | 63 | First, calculate the deviations of each data point from the mean, and square the result of each: 64 | 65 | ![{\begin{array}{lll}(2-5)^{2}=(-3)^{2}=9&&(5-5)^{2}=0^{2}=0\\(4-5)^{2}=(-1)^{2}=1&&(5-5)^{2}=0^{2}=0\\(4-5)^{2}=(-1)^{2}=1&&(7-5)^{2}=2^{2}=4\\(4-5)^{2}=(-1)^{2}=1&&(9-5)^{2}=4^{2}=16.\\\end{array}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/7548c1617a8a3dfc34abc1cb0dd3001cf2b692ed) 66 | 67 | The [variance](https://en.wikipedia.org/wiki/Variance) is the mean of these values: 68 | 69 | ![{\frac {9+1+1+1+0+0+4+16}{8}}=4.](https://wikimedia.org/api/rest_v1/media/math/render/svg/efda3aa8d60d798bfef00fe9f88d0af6e6bdce9d) 70 | 71 | and the _population_ standard deviation is equal to the square root of the variance: 72 | 73 | ![{\sqrt {4}}=2.](https://wikimedia.org/api/rest_v1/media/math/render/svg/cbc0d5f0364ae38fb392369f4f6154e741a50089) 74 | 75 | 76 | --- 77 | 78 | # Normal Distribution 79 | 80 | ## Probability Density 81 | 82 | ![Probability Density of a Normal Distribution](https://wikimedia.org/api/rest_v1/media/math/render/svg/6404a4c69c536278a5933085f0d5f4a9ca9f2b2a "Probability Density of a Normal Distribution") 83 | 84 | 85 | --- 86 | 87 | # Bessels Correction 88 | 89 | ## Sample standard deviation 90 | 91 | ![Bessels Correction](bessels_correction.png) 92 | 93 | This is used to approximate standard deviation of the population, from a standar deviation of a sample. 94 | 95 | 96 | **Reference:** [Wikipedia](https://en.wikipedia.org/wiki/Statistical_dispersion) 97 | -------------------------------------------------------------------------------- /classes/supervised-learning/neural-network-quizzes/sigmoid-programming-exercise.py: -------------------------------------------------------------------------------- 1 | # ---------- 2 | # 3 | # As with the previous perceptron exercises, you will complete some of the core 4 | # methods of a sigmoid unit class. 5 | # 6 | # There are two functions for you to finish: 7 | # First, in activate(), write the sigmoid activation function. 8 | # Second, in update(), write the gradient descent update rule. Updates should be 9 | # performed online, revising the weights after each data point. 10 | # 11 | # ---------- 12 | 13 | import numpy as np 14 | 15 | 16 | class Sigmoid: 17 | """ 18 | This class models an artificial neuron with sigmoid activation function. 19 | """ 20 | 21 | def __init__(self, weights = np.array([1])): 22 | """ 23 | Initialize weights based on input arguments. Note that no type-checking 24 | is being performed here for simplicity of code. 25 | """ 26 | self.weights = weights 27 | 28 | # NOTE: You do not need to worry about these two attribues for this 29 | # programming quiz, but these will be useful for if you want to create 30 | # a network out of these sigmoid units! 31 | self.last_input = 0 # strength of last input 32 | self.delta = 0 # error signal 33 | 34 | @staticmethod 35 | def logistic(activation): 36 | return 1/(1+np.exp(-activation)) 37 | 38 | def activate(self, values): 39 | """ 40 | Takes in @param values, a list of numbers equal to length of weights. 41 | @return the output of a sigmoid unit with given inputs based on unit 42 | weights. 43 | """ 44 | 45 | # YOUR CODE HERE 46 | 47 | # First calculate the strength of the input signal. 48 | strength = np.dot(values, self.weights) 49 | self.last_input = strength 50 | 51 | # TODO: Modify strength using the sigmoid activation function and 52 | # return as output signal. 53 | # HINT: You may want to create a helper function to compute the 54 | # logistic function since you will need it for the update function. 55 | 56 | return Sigmoid.logistic(strength) 57 | 58 | def update(self, values, train, eta=.1): 59 | """ 60 | Takes in a 2D array @param values consisting of a LIST of inputs and a 61 | 1D array @param train, consisting of a corresponding list of expected 62 | outputs. Updates internal weights according to gradient descent using 63 | these values and an optional learning rate, @param eta. 64 | """ 65 | 66 | # TODO: for each data point... 67 | for X, y_true in zip(values, train): 68 | # obtain the output signal for that point 69 | y_pred = self.activate(X) 70 | 71 | # YOUR CODE HERE 72 | 73 | # TODO: compute derivative of logistic function at input strength 74 | # Recall: d/dx logistic(x) = logistic(x)*(1-logistic(x)) 75 | derivative = Sigmoid.logistic(self.last_input)*(1-Sigmoid.logistic(self.last_input)) 76 | 77 | # TODO: update self.weights based on learning rate, signal accuracy, 78 | # function slope (derivative) and input value 79 | self.weights = self.weights + eta*(y_true - y_pred)*derivative*X 80 | 81 | 82 | 83 | def test(): 84 | """ 85 | A few tests to make sure that the perceptron class performs as expected. 86 | Nothing should show up in the output if all the assertions pass. 87 | """ 88 | def sum_almost_equal(array1, array2, tol = 1e-5): 89 | return sum(abs(array1 - array2)) < tol 90 | 91 | u1 = Sigmoid(weights=[3,-2,1]) 92 | assert abs(u1.activate(np.array([1,2,3])) - 0.880797) < 1e-5 93 | 94 | u1.update(np.array([[1,2,3]]),np.array([0])) 95 | assert sum_almost_equal(u1.weights, np.array([2.990752, -2.018496, 0.972257])) 96 | 97 | u2 = Sigmoid(weights=[0,3,-1]) 98 | u2.update(np.array([[-3,-1,2],[2,1,2]]),np.array([1,0])) 99 | assert sum_almost_equal(u2.weights, np.array([-0.030739, 2.984961, -1.027437])) 100 | 101 | if __name__ == "__main__": 102 | test() -------------------------------------------------------------------------------- /classes/reinforcement-learning/markov-decision-process.md: -------------------------------------------------------------------------------- 1 | # Markov Decision Process 2 | 3 | ## Comparison of Learning Types 4 | 5 | ![Comparison of Learning Types](images/comparison-types-learning.png) 6 | 7 | In *Supervised Learning*, we are given `y` and `x` and we try to find the best function `f` that fits `f(x) = y`. 8 | 9 | In *Unsupervised Learning*, we are given `x` and we try to find the best function `f` that produces a compact description of `x` in the form of `f(x)` clusters. 10 | 11 | In *Reinforcement Learning*, we are given `x` and `z` and we try to find `f` and `y`, where `f(x) = y`. It looks a lot like supervised learning, but the main difference is that we are not given the labels (`y`), but instead the reinforcers and punishers (`z`) to adjust the function `f`. 12 | 13 | ## Markov Decision Process Explained 14 | 15 | ![Explanation of Markov Decision Process](images/markov-decision-process.png) 16 | 17 | ### Markov Assumptions 18 | - Stationary. Actions, states and the model can't change. The agent is the only element of change on the model. 19 | - Only present matters. The transition function should only evaluate the current state to determine the probability of the outcome. 20 | 21 | ### Image Explained 22 | 23 | - States: `S` - represents all the possible states that the agent may be in. 24 | - Model: `T(s, a, s') -> Pr(s' | s, a)` - represents the transition function, which outputs the probability of the agent reaching state `s'` by taking action `a`, given that it is in state `s`. 25 | - Actions: `A(s) or A` - represents all possible actions for each state. Actions are usually constant for all states, so they are represented by `A`. 26 | - Reward - represents the agent's reward 27 | - `R(s)`: being on state `s` 28 | - `R(s,a)`: being on state `s` and taking action `a` 29 | - `R(s,a,s')`: being on state `s`, taking action `a` and achieving state `s'`. 30 | - All these representations provide the same mathematical value and can be modeled by `R(s)` alone. 31 | - Policy - represents the "master plan" to solve the problem. It is represented by a mapping of states to actions `π(s) -> a`, where for any given state `s` it outputs the best course of action `a` to take. 32 | - `π*` represents the optimal solution - the mapping that maximizes the rewards. 33 | 34 | ## More on rewards 35 | 36 | Some examples of Policies affected by different rewards: 37 | 38 | ![Rewards affecting policies](images/more-rewards.png) 39 | 40 | ## Sequence of Rewards: Assumptions 41 | 42 | ### Infinite Horizons 43 | 44 | *Infinite Horizons* means we can take as many steps as we want through the MDP. 45 | 46 | ### Utility of Sequences 47 | 48 | *Utility of Sequences* measures the total reward value of a given sequence of steps. 49 | 50 | #### Sum of each step reward 51 | 52 | ![Sum of each step reward](http://latex.codecogs.com/gif.latex?$$%5Csum_%7Bt=0%7D%5E%7B%5Cinfty%7DR(S_t)) 53 | 54 | The sum of all rewards for each step is not a good measure of utility because, assuming we are working with infinite horizons, we will have infinite and all sequences will always provide infinite utility, as shown below. 55 | 56 | ![Quiz example](images/utility-quiz-infinite.png) 57 | 58 | #### Discounted Rewards 59 | 60 | ![Discounted Rewards](http://latex.codecogs.com/gif.latex?$$%5Csum_%7Bt=0%7D%5E%7B%5Cinfty%7D%5Cgamma%5EtR(S_t)) 61 | 62 | Discounted rewards is a geometric sequence that provides a finite number to measure the utility against sequences. 63 | 64 | ![Discounted Rewards Explained](images/discounted-utility-rewards.png) 65 | 66 | Maximization of discounted rewards: 67 | 68 | ![Maximal Discounted Rewards](http://latex.codecogs.com/gif.latex?$$%5Cfrac%7BR_%7Bmax%7D%7D%7B1-%5Cgamma%7D) 69 | 70 | which is demonstrated by: 71 | 72 | ![Maximal Discounted Rewards Demonstrated](images/maximal-discounted-rewards.png) 73 | 74 | 75 | ## Bellman Equation 76 | 77 | ![Bellman Equation](images/bellman-equation.png) 78 | 79 | ### Algorithmic Solution 80 | 81 | ![Algorithmic Solution for Bellman Equation](images/solving-bellman-equation.png) 82 | 83 | ![Algorithmic Solution for Bellman Equation Continuation](images/solving-bellman-equation-2.png) 84 | 85 | ### Example (Quiz) 86 | 87 | ![Quiz Example](images/bellman-quiz-example.png) 88 | 89 | ### Finding the Policies 90 | 91 | While the solutions presented above find the true Utility Values for each state, we are not interested in finding these values, but instead we are interested in finding the Optimal Policy. 92 | 93 | The image below shows a simplification of the solutions elaborated previously to solve this. 94 | 95 | ![Finding Policies](images/finding-policies.png) 96 | 97 | 98 | 99 | ## Summary 100 | 101 | ![Summary](images/mdp-summary.png) -------------------------------------------------------------------------------- /projects/capstone/proposal.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Engineer Nanodegree 2 | ## Capstone Proposal 3 | Joe Udacity 4 | December 31st, 2050 5 | 6 | ## Proposal 7 | _(approx. 2-3 pages)_ 8 | 9 | ### Domain Background 10 | _(approx. 1-2 paragraphs)_ 11 | 12 | In this section, provide brief details on the background information of the domain from which the project is proposed. Historical information relevant to the project should be included. It should be clear how or why a problem in the domain can or should be solved. Related academic research should be appropriately cited in this section, including why that research is relevant. Additionally, a discussion of your personal motivation for investigating a particular problem in the domain is encouraged but not required. 13 | 14 | ### Problem Statement 15 | _(approx. 1 paragraph)_ 16 | 17 | In this section, clearly describe the problem that is to be solved. The problem described should be well defined and should have at least one relevant potential solution. Additionally, describe the problem thoroughly such that it is clear that the problem is quantifiable (the problem can be expressed in mathematical or logical terms) , measurable (the problem can be measured by some metric and clearly observed), and replicable (the problem can be reproduced and occurs more than once). 18 | 19 | ### Datasets and Inputs 20 | _(approx. 2-3 paragraphs)_ 21 | 22 | In this section, the dataset(s) and/or input(s) being considered for the project should be thoroughly described, such as how they relate to the problem and why they should be used. Information such as how the dataset or input is (was) obtained, and the characteristics of the dataset or input, should be included with relevant references and citations as necessary It should be clear how the dataset(s) or input(s) will be used in the project and whether their use is appropriate given the context of the problem. 23 | 24 | ### Solution Statement 25 | _(approx. 1 paragraph)_ 26 | 27 | In this section, clearly describe a solution to the problem. The solution should be applicable to the project domain and appropriate for the dataset(s) or input(s) given. Additionally, describe the solution thoroughly such that it is clear that the solution is quantifiable (the solution can be expressed in mathematical or logical terms) , measurable (the solution can be measured by some metric and clearly observed), and replicable (the solution can be reproduced and occurs more than once). 28 | 29 | ### Benchmark Model 30 | _(approximately 1-2 paragraphs)_ 31 | 32 | In this section, provide the details for a benchmark model or result that relates to the domain, problem statement, and intended solution. Ideally, the benchmark model or result contextualizes existing methods or known information in the domain and problem given, which could then be objectively compared to the solution. Describe how the benchmark model or result is measurable (can be measured by some metric and clearly observed) with thorough detail. 33 | 34 | ### Evaluation Metrics 35 | _(approx. 1-2 paragraphs)_ 36 | 37 | In this section, propose at least one evaluation metric that can be used to quantify the performance of both the benchmark model and the solution model. The evaluation metric(s) you propose should be appropriate given the context of the data, the problem statement, and the intended solution. Describe how the evaluation metric(s) are derived and provide an example of their mathematical representations (if applicable). Complex evaluation metrics should be clearly defined and quantifiable (can be expressed in mathematical or logical terms). 38 | 39 | ### Project Design 40 | _(approx. 1 page)_ 41 | 42 | In this final section, summarize a theoretical workflow for approaching a solution given the problem. Provide thorough discussion for what strategies you may consider employing, what analysis of the data might be required before being used, or which algorithms will be considered for your implementation. The workflow and discussion that you provide should align with the qualities of the previous sections. Additionally, you are encouraged to include small visualizations, pseudocode, or diagrams to aid in describing the project design, but it is not required. The discussion should clearly outline your intended workflow of the capstone project. 43 | 44 | ----------- 45 | 46 | **Before submitting your proposal, ask yourself. . .** 47 | 48 | - Does the proposal you have written follow a well-organized structure similar to that of the project template? 49 | - Is each section (particularly **Solution Statement** and **Project Design**) written in a clear, concise and specific fashion? Are there any ambiguous terms or phrases that need clarification? 50 | - Would the intended audience of your project be able to understand your proposal? 51 | - Have you properly proofread your proposal to assure there are minimal grammatical and spelling mistakes? 52 | - Are all the resources used for this project correctly cited and referenced? 53 | -------------------------------------------------------------------------------- /projects/finding-donors/project_description.md: -------------------------------------------------------------------------------- 1 | # Content: Supervised Learning 2 | ## Project: Finding Donors for CharityML 3 | 4 | ## Project Overview 5 | In this project, you will apply supervised learning techniques and an analytical mind on data collected for the U.S. census to help CharityML (a fictitious charity organization) identify people most likely to donate to their cause. You will first explore the data to learn how the census data is recorded. Next, you will apply a series of transformations and preprocessing techniques to manipulate the data into a workable format. You will then evaluate several supervised learners of your choice on the data, and consider which is best suited for the solution. Afterwards, you will optimize the model you've selected and present it as your solution to CharityML. Finally, you will explore the chosen model and its predictions under the hood, to see just how well it's performing when considering the data it's given. 6 | predicted selling price to your statistics. 7 | 8 | ## Project Highlights 9 | This project is designed to get you acquainted with the many supervised learning algorithms available in sklearn, and to also provide for a method of evaluating just how each model works and performs on a certain type of data. It is important in machine learning to understand exactly when and where a certain algorithm should be used, and when one should be avoided. 10 | 11 | Things you will learn by completing this project: 12 | - How to identify when preprocessing is needed, and how to apply it. 13 | - How to establish a benchmark for a solution to the problem. 14 | - What each of several supervised learning algorithms accomplishes given a specific dataset. 15 | - How to investigate whether a candidate solution model is adequate for the problem. 16 | 17 | ## Software Requirements 18 | 19 | This project uses the following software and Python libraries: 20 | 21 | - [Python 2.7](https://www.python.org/download/releases/2.7/) 22 | - [NumPy](http://www.numpy.org/) 23 | - [Pandas](http://pandas.pydata.org/) 24 | - [scikit-learn](http://scikit-learn.org/stable/) 25 | - [matplotlib](http://matplotlib.org/) 26 | 27 | You will also need to have software installed to run and execute a [Jupyter Notebook](http://ipython.org/notebook.html) 28 | 29 | If you do not have Python installed yet, it is highly recommended that you install the [Anaconda](http://continuum.io/downloads) distribution of Python, which already has the above packages and more included. Make sure that you select the Python 2.7 installer and not the Python 3.x installer. 30 | 31 | ## Starting the Project 32 | 33 | For this assignment, you can find the `finding_donors` folder containing the necessary project files on the [Machine Learning projects GitHub](https://github.com/udacity/machine-learning), under the `projects` folder. You may download all of the files for projects we'll use in this Nanodegree program directly from this repo. Please make sure that you use the most recent version of project files when completing a project! 34 | 35 | This project contains three files: 36 | 37 | - `finding_donors.ipynb`: This is the main file where you will be performing your work on the project. 38 | - `census.csv`: The project dataset. You'll load this data in the notebook. 39 | - `visuals.py`: A Python file containing visualization code that is run behind-the-scenes. Do not modify 40 | 41 | In the Terminal or Command Prompt, navigate to the folder containing the project files, and then use the command `jupyter notebook finding_donors.ipynb` to open up a browser window or tab to work with your notebook. Alternatively, you can use the command `jupyter notebook` or `ipython notebook` and navigate to the notebook file in the browser window that opens. Follow the instructions in the notebook and answer each question presented to successfully complete the project. A **README** file has also been provided with the project files which may contain additional necessary information or instruction for the project. 42 | 43 | ## Submitting the Project 44 | 45 | ### Evaluation 46 | Your project will be reviewed by a Udacity reviewer against the **Finding Donors for CharityML project rubric**. Be sure to review this rubric thoroughly and self-evaluate your project before submission. All criteria found in the rubric must be *meeting specifications* for you to pass. 47 | 48 | ### Submission Files 49 | When you are ready to submit your project, collect the following files and compress them into a single archive for upload. Alternatively, you may supply the following files on your GitHub Repo in a folder named `student_intervention` for ease of access: 50 | - The `finding_donors.ipynb` notebook file with all questions answered and all code cells executed and displaying output. 51 | - An **HTML** export of the project notebook with the name **report.html**. This file *must* be present for your project to be evaluated. 52 | 53 | Once you have collected these files and reviewed the project rubric, proceed to the project submission page. 54 | 55 | ### I'm Ready! 56 | When you're ready to submit your project, click on the **Submit Project** button at the bottom of the page. 57 | 58 | If you are having any problems submitting your project or wish to check on the status of your submission, please email us at **machine-support@udacity.com** or visit us in the discussion forums. 59 | 60 | ### What's Next? 61 | You will get an email as soon as your reviewer has feedback for you. In the meantime, review your next project and feel free to get started on it or the courses supporting it! 62 | -------------------------------------------------------------------------------- /projects/boston-housing-prices/visuals.py: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Suppress matplotlib user warnings 3 | # Necessary for newer version of matplotlib 4 | import warnings 5 | warnings.filterwarnings("ignore", category = UserWarning, module = "matplotlib") 6 | # 7 | # Display inline matplotlib plots with IPython 8 | from IPython import get_ipython 9 | get_ipython().run_line_magic('matplotlib', 'inline') 10 | ########################################### 11 | 12 | import matplotlib.pyplot as pl 13 | import numpy as np 14 | import sklearn.learning_curve as curves 15 | from sklearn.tree import DecisionTreeRegressor 16 | from sklearn.cross_validation import ShuffleSplit, train_test_split 17 | 18 | def ModelLearning(X, y): 19 | """ Calculates the performance of several models with varying sizes of training data. 20 | The learning and testing scores for each model are then plotted. """ 21 | 22 | # Create 10 cross-validation sets for training and testing 23 | cv = ShuffleSplit(X.shape[0], n_iter = 10, test_size = 0.2, random_state = 0) 24 | 25 | # Generate the training set sizes increasing by 50 26 | train_sizes = np.rint(np.linspace(1, X.shape[0]*0.8 - 1, 9)).astype(int) 27 | 28 | # Create the figure window 29 | fig = pl.figure(figsize=(10,7)) 30 | 31 | # Create three different models based on max_depth 32 | for k, depth in enumerate([1,3,6,10]): 33 | 34 | # Create a Decision tree regressor at max_depth = depth 35 | regressor = DecisionTreeRegressor(max_depth = depth) 36 | 37 | # Calculate the training and testing scores 38 | sizes, train_scores, test_scores = curves.learning_curve(regressor, X, y, \ 39 | cv = cv, train_sizes = train_sizes, scoring = 'r2') 40 | 41 | # Find the mean and standard deviation for smoothing 42 | train_std = np.std(train_scores, axis = 1) 43 | train_mean = np.mean(train_scores, axis = 1) 44 | test_std = np.std(test_scores, axis = 1) 45 | test_mean = np.mean(test_scores, axis = 1) 46 | 47 | # Subplot the learning curve 48 | ax = fig.add_subplot(2, 2, k+1) 49 | ax.plot(sizes, train_mean, 'o-', color = 'r', label = 'Training Score') 50 | ax.plot(sizes, test_mean, 'o-', color = 'g', label = 'Testing Score') 51 | ax.fill_between(sizes, train_mean - train_std, \ 52 | train_mean + train_std, alpha = 0.15, color = 'r') 53 | ax.fill_between(sizes, test_mean - test_std, \ 54 | test_mean + test_std, alpha = 0.15, color = 'g') 55 | 56 | # Labels 57 | ax.set_title('max_depth = %s'%(depth)) 58 | ax.set_xlabel('Number of Training Points') 59 | ax.set_ylabel('Score') 60 | ax.set_xlim([0, X.shape[0]*0.8]) 61 | ax.set_ylim([-0.05, 1.05]) 62 | 63 | # Visual aesthetics 64 | ax.legend(bbox_to_anchor=(1.05, 2.05), loc='lower left', borderaxespad = 0.) 65 | fig.suptitle('Decision Tree Regressor Learning Performances', fontsize = 16, y = 1.03) 66 | fig.tight_layout() 67 | fig.show() 68 | 69 | 70 | def ModelComplexity(X, y): 71 | """ Calculates the performance of the model as model complexity increases. 72 | The learning and testing errors rates are then plotted. """ 73 | 74 | # Create 10 cross-validation sets for training and testing 75 | cv = ShuffleSplit(X.shape[0], n_iter = 10, test_size = 0.2, random_state = 0) 76 | 77 | # Vary the max_depth parameter from 1 to 10 78 | max_depth = np.arange(1,11) 79 | 80 | # Calculate the training and testing scores 81 | train_scores, test_scores = curves.validation_curve(DecisionTreeRegressor(), X, y, \ 82 | param_name = "max_depth", param_range = max_depth, cv = cv, scoring = 'r2') 83 | 84 | # Find the mean and standard deviation for smoothing 85 | train_mean = np.mean(train_scores, axis=1) 86 | train_std = np.std(train_scores, axis=1) 87 | test_mean = np.mean(test_scores, axis=1) 88 | test_std = np.std(test_scores, axis=1) 89 | 90 | # Plot the validation curve 91 | pl.figure(figsize=(7, 5)) 92 | pl.title('Decision Tree Regressor Complexity Performance') 93 | pl.plot(max_depth, train_mean, 'o-', color = 'r', label = 'Training Score') 94 | pl.plot(max_depth, test_mean, 'o-', color = 'g', label = 'Validation Score') 95 | pl.fill_between(max_depth, train_mean - train_std, \ 96 | train_mean + train_std, alpha = 0.15, color = 'r') 97 | pl.fill_between(max_depth, test_mean - test_std, \ 98 | test_mean + test_std, alpha = 0.15, color = 'g') 99 | 100 | # Visual aesthetics 101 | pl.legend(loc = 'lower right') 102 | pl.xlabel('Maximum Depth') 103 | pl.ylabel('Score') 104 | pl.ylim([-0.05,1.05]) 105 | pl.show() 106 | 107 | 108 | def PredictTrials(X, y, fitter, data): 109 | """ Performs trials of fitting and predicting data. """ 110 | 111 | # Store the predicted prices 112 | prices = [] 113 | 114 | for k in range(10): 115 | # Split the data 116 | X_train, X_test, y_train, y_test = train_test_split(X, y, \ 117 | test_size = 0.2, random_state = k) 118 | 119 | # Fit the data 120 | reg = fitter(X_train, y_train) 121 | 122 | # Make a prediction 123 | pred = reg.predict([data[0]])[0] 124 | prices.append(pred) 125 | 126 | # Result 127 | print "Trial {}: ${:,.2f}".format(k+1, pred) 128 | 129 | # Display price range 130 | print "\nRange in prices: ${:,.2f}".format(max(prices) - min(prices)) -------------------------------------------------------------------------------- /projects/titanic-survival-exploration/project_description.md: -------------------------------------------------------------------------------- 1 | ## Content: Introduction and Foundations 2 | ## Project: Titanic Survival Exploration 3 | 4 | ## Project Overview 5 | Welcome to the Machine Learning Engineer Nanodegree! 6 | 7 | In this ***optional*** project, you will create decision functions that attempt to predict survival outcomes from the 1912 Titanic disaster based on each passenger's features, such as sex and age. You will start with a simple algorithm and increase its complexity until you are able to accurately predict the outcomes for at least 80% of the passengers in the provided data. This project will introduce you to some of the concepts of machine learning as you start the Nanodegree program. 8 | 9 | In addition, you'll make sure Python is installed with the necessary packages to complete this project. There are two Python libraries, `numpy` and `pandas`, that we'll use a bit here in this project. Don't worry about how these libraries work for now -- we'll get to them in more detail in later projects. This project will also familiarize you with the submission process for the projects that you will be completing as part of the Nanodegree program. 10 | 11 | ## Software Requirements 12 | This project uses the following software and Python libraries: 13 | 14 | - [Python 2.7](https://www.python.org/download/releases/2.7/) 15 | - [NumPy](http://www.numpy.org/) 16 | - [pandas](http://pandas.pydata.org/) 17 | - [matplotlib](http://matplotlib.org/) 18 | 19 | You will also need to have software installed to run and execute a [Jupyter Notebook](http://ipython.org/notebook.html). 20 | 21 | If you do not have Python installed yet, it is highly recommended that you install the [Anaconda](http://continuum.io/downloads) distribution of Python, which already has the above packages and more included. Make sure that you select the Python 2.7 installer and not the Python 3.x installer. 22 | 23 | If you already have Python 2.7 installed on your computer, then you can install `numpy`, `pandas`, `matplotlib` and Jupyter Notebook (formerly known as "iPython") by using [pip](https://pip.pypa.io/en/stable/) on the command line. [This page](http://www.lfd.uci.edu/~gohlke/pythonlibs/) may also be of use for some packages for Windows users, if pip has trouble performing the installation. After installing pip, you can install all the packages with the following command: 24 | 25 | `sudo pip install numpy pandas matplotlib jupyter` 26 | 27 | ## Starting the Project 28 | 29 | For this assignment, you can find the `titanic_survival_exploration` folder containing the necessary project files on the [Machine Learning projects GitHub](https://github.com/udacity/machine-learning), under the `projects` folder. You may download all of the files for projects we'll use in this Nanodegree program directly from this repo. Please make sure that you use the most recent version of project files when completing a project! 30 | 31 | This project contains three files: 32 | 33 | - `titanic_survival_exploration.ipynb`: This is the main file where you will be performing your work on the project. 34 | - `titanic_data.csv`: The project dataset. You?ll load this data in the notebook. 35 | - `visuals.py`: This Python script provides supplementary visualizations for the project. Do not modify. 36 | 37 | In the Terminal or Command Prompt, navigate to the folder containing the project files, and then use the command `jupyter notebook titanic_survival_exploration.ipynb` to open up a browser window or tab to work with your notebook. Alternatively, you can use the command `jupyter notebook` or `ipython notebook` and navigate to the notebook file in the browser window that opens. Follow the instructions in the notebook and answer each question presented to successfully complete the project. A **README** file has also been provided with the project files which may contain additional necessary information or instruction for the project. 38 | ## Submitting the Project 39 | 40 | ### Evaluation 41 | Your project will be reviewed by a Udacity reviewer against the ** Titanic Survival Exploration project rubric**. Be sure to review this rubric thoroughly and self-evaluate your project before submission. All criteria found in the rubric must be *meeting specifications* for you to pass. 42 | 43 | ### Submission Files 44 | When you are ready to submit your project, collect the following files and compress them into a single archive for upload. Alternatively, you may supply the following files on your GitHub Repo in a folder named `titanic_survival_exploration` for ease of access: 45 | - The `titanic_survival_exploration.ipynb` notebook file with all questions answered and all code cells executed and displaying output. 46 | - An **HTML** export of the project notebook with the name **report.html**. Instructions for exporting to HTML are at the bottom of the notebook; you may need to install the [mistune](https://pypi.python.org/pypi/mistune) package first, e.g. via `pip install mistune` in the terminal. 47 | 48 | Once you have collected these files and reviewed the project rubric, proceed to the project submission page. 49 | 50 | ### I'm Ready! 51 | When you're ready to submit your project, click on the **Submit Project** button at the bottom of the page. 52 | 53 | If you are having any problems submitting your project or wish to check on the status of your submission, please email us at **machine-support@udacity.com** or visit us in the discussion forums. 54 | 55 | ### What's Next? 56 | You will get an email as soon as your reviewer has feedback for you. In the meantime, review your next project and feel free to get started on it or the courses supporting it! 57 | -------------------------------------------------------------------------------- /classes/supervised-learning/supervised-learning.md: -------------------------------------------------------------------------------- 1 | # Supervised Learning 2 | 3 | ## Supervised Learning, Classification and Regression 4 | 5 | Supervised learning is a technique of fitting a model to some labeled input, and then given a new input, the model predicts the output. 6 | 7 | There are two types of tasks whiles doing supervised learning: `Classification` and `Regression`. 8 | 9 | ### Classification 10 | 11 | Classification is the task of predicting a discrete output given an input. Example of classification problems are: 12 | 13 | - Given a portrait, define if the person is a male or female 14 | - Given some features of a student, define if he is a graduate student, undergraduate or highschool. 15 | 16 | ### Regression 17 | 18 | Regression is the task of predicting a continuous output for a given input. For example: 19 | 20 | - Given some info about a person, predict his income. 21 | - Given a portrait, predict the person's age* 22 | 23 | * Although age is usually considered continuous output, depending on the problem, it might be discrete output. 24 | 25 | ## Types of Regression 26 | 27 | ### Parametric vs Non-parametric Regression 28 | 29 | A **parametric regression** captures all information about the provided data into their own parameters, and then uses these parameters to predict the outputs for a given input. 30 | 31 | A **non-parametric regression** uses the data directly to predict the output for a given input. 32 | 33 | Parametric regressions take longer to train but less time to give predictions, while non-parametric regressions can be trained faster but require more time to provide the predictions. Also, it is easier to add new data points to a non-parametric regression, since it doesn't need to be trained all over again. 34 | 35 | An example of a parametric regression is a **polynomial regression**. 36 | 37 | An example of a non-parametric regression is a **kernel regression**. 38 | 39 | ### Linear Regression 40 | 41 | Linear regression is a parametric regression that fits the data to a line. The parameters of the line are found by the following steps: 42 | 43 | 1. The line is represented by `y = mx + b`. We have to find `m` and `b`, given two sets X and Y. 44 | 2. First we compute the mean of X and Y. 45 | 3. Then we normalize X and Y (subtract each point by the mean). 46 | 4. Then we find `m`. `X` and `Y` below are normalized from step 3. 47 | ``` 48 | m = sum(Xi*Yi) / sum(Yi*Yi) 49 | ``` 50 | 5. Finally we find `b`, by the equation: 51 | ``` 52 | y - mean_y = m * (x - mean_x) 53 | y = m * x - m * mean_x + mean_y 54 | 55 | Comparing to y = mx + b, then: 56 | 57 | b = -m * mean_x + y 58 | ``` 59 | 60 | We can use sklearn to compute the linear regression for us: 61 | 62 | ```python 63 | from sklearn.linear_model import LinearRegression 64 | 65 | reg = LinearRegression() 66 | reg.fit(X, Y) 67 | 68 | print "m = ", reg.coef_ 69 | print "b = ", reg.intercept_ 70 | print "r_squared = ", reg.score(X_test, Y_test) 71 | ``` 72 | 73 | #### Final notes 74 | 75 | - `m` is also known as `Slope` 76 | - `b` is also known as `Intercept` 77 | 78 | ### SSE vs R Squared 79 | 80 | Squared Sum Errors (SSE) is the sum of the squared errors. In other words, given a line, we compute the distance between the data points and the line, square it and sum. 81 | 82 | R Squared is a value between 0 and 1 that answers the question: "How much of the change in my output (Y) is explained by the change in my input (x)?" In other words, it describes how many cases the given model can explain variations around the mean in %. 83 | 84 | It is important to notice that SSE incrases as we add more training data (because for each point added, there will be some error), this doesn't happen with R Squared. 85 | 86 | R Squared is defined as: 87 | 88 | ![R Squared](https://wikimedia.org/api/rest_v1/media/math/render/svg/fed29779d54adeccdec58f0894870c680f3d6b5b) 89 | 90 | Where SSres is the residual Sum of Squares and SStot is the total Sum of Squares. 91 | 92 | ```python 93 | SSres = sum((Yi - reg.predict(Xi))ˆ2) 94 | SStot = sum((Yi - mean_y)^2) 95 | 96 | r_squared = 1 - (SSres / SStot) 97 | ``` 98 | 99 | ### Polynomial Regression 100 | 101 | Polynomial regression is a parametric regression which given a data set and a `n` degree, it will calculate the values for the `a` parameters that best fit the data set: 102 | 103 | ![polynomial regression](https://wikimedia.org/api/rest_v1/media/math/render/svg/5dc55ae387a97beec17a821a014dd101d329004d) 104 | 105 | ```python 106 | # using numpy 107 | 108 | import numpy as np 109 | 110 | X = [5,6,7,8,10,12,16] 111 | Y = [65,51,75,75,86,80,0] 112 | degrees = 2 113 | 114 | coeffs = np.polyfit(X, Y, degrees) 115 | # in this case, we have a parabola 116 | 117 | 118 | # using sklearn 119 | from sklearn.preprocessing import PolynomialFeatures 120 | 121 | poly = PolynomialFeatures(degrees) 122 | poly.fit(X, Y) 123 | poly.powers_ 124 | ``` 125 | 126 | ### K-nearest neighbor (KNN) 127 | 128 | KNN is a non-parametric regression, which given an input, it finds the K nearest data points that neighbors that input hyperplane and average their Y, in order to compute the output. 129 | 130 | ![KNN](images/KNN.png) 131 | 132 | 133 | ### Kernel Regression 134 | 135 | Kernel regression is similar to KNN, but instead uses a weighted average based on the distance to the hyperplane to calculate the output. This differs from KNN, because the latter equally weighs all data points selected. 136 | 137 | ### Visualizing Regression 138 | 139 | ```python 140 | import matplotlib as plt 141 | 142 | # Scatter the data points of the training/test set 143 | plt.scatter(X, Y) 144 | # Plot the linear regression line 145 | plt.plot(X, reg.predict(X), color='blue', linewidth=3) # color and line are optionals 146 | plt.xlabel("Some label for X") 147 | plt.ylabel("Some label for Y") 148 | # Finally we show the graph 149 | plt.show() 150 | 151 | ``` 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /projects/finding-donors/visuals.py: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Suppress matplotlib user warnings 3 | # Necessary for newer version of matplotlib 4 | import warnings 5 | warnings.filterwarnings("ignore", category = UserWarning, module = "matplotlib") 6 | # 7 | # Display inline matplotlib plots with IPython 8 | from IPython import get_ipython 9 | get_ipython().run_line_magic('matplotlib', 'inline') 10 | ########################################### 11 | 12 | import matplotlib.pyplot as pl 13 | import matplotlib.patches as mpatches 14 | import numpy as np 15 | import pandas as pd 16 | from time import time 17 | from sklearn.metrics import f1_score, accuracy_score 18 | 19 | 20 | def distribution(data, transformed = False): 21 | """ 22 | Visualization code for displaying skewed distributions of features 23 | """ 24 | 25 | # Create figure 26 | fig = pl.figure(figsize = (11,5)); 27 | 28 | # Skewed feature plotting 29 | for i, feature in enumerate(['capital-gain','capital-loss']): 30 | ax = fig.add_subplot(1, 2, i+1) 31 | ax.hist(data[feature], bins = 25, color = '#00A0A0') 32 | ax.set_title("'%s' Feature Distribution"%(feature), fontsize = 14) 33 | ax.set_xlabel("Value") 34 | ax.set_ylabel("Number of Records") 35 | ax.set_ylim((0, 2000)) 36 | ax.set_yticks([0, 500, 1000, 1500, 2000]) 37 | ax.set_yticklabels([0, 500, 1000, 1500, ">2000"]) 38 | 39 | # Plot aesthetics 40 | if transformed: 41 | fig.suptitle("Log-transformed Distributions of Continuous Census Data Features", \ 42 | fontsize = 16, y = 1.03) 43 | else: 44 | fig.suptitle("Skewed Distributions of Continuous Census Data Features", \ 45 | fontsize = 16, y = 1.03) 46 | 47 | fig.tight_layout() 48 | fig.show() 49 | 50 | 51 | def evaluate(results, accuracy, f1): 52 | """ 53 | Visualization code to display results of various learners. 54 | 55 | inputs: 56 | - learners: a list of supervised learners 57 | - stats: a list of dictionaries of the statistic results from 'train_predict()' 58 | - accuracy: The score for the naive predictor 59 | - f1: The score for the naive predictor 60 | """ 61 | 62 | # Create figure 63 | fig, ax = pl.subplots(2, 3, figsize = (11,7)) 64 | 65 | # Constants 66 | bar_width = 0.3 67 | colors = ['#A00000','#00A0A0','#00A000'] 68 | 69 | # Super loop to plot four panels of data 70 | for k, learner in enumerate(results.keys()): 71 | for j, metric in enumerate(['train_time', 'acc_train', 'f_train', 'pred_time', 'acc_test', 'f_test']): 72 | for i in np.arange(3): 73 | 74 | # Creative plot code 75 | ax[j/3, j%3].bar(i+k*bar_width, results[learner][i][metric], width = bar_width, color = colors[k]) 76 | ax[j/3, j%3].set_xticks([0.45, 1.45, 2.45]) 77 | ax[j/3, j%3].set_xticklabels(["1%", "10%", "100%"]) 78 | ax[j/3, j%3].set_xlabel("Training Set Size") 79 | ax[j/3, j%3].set_xlim((-0.1, 3.0)) 80 | 81 | # Add unique y-labels 82 | ax[0, 0].set_ylabel("Time (in seconds)") 83 | ax[0, 1].set_ylabel("Accuracy Score") 84 | ax[0, 2].set_ylabel("F-score") 85 | ax[1, 0].set_ylabel("Time (in seconds)") 86 | ax[1, 1].set_ylabel("Accuracy Score") 87 | ax[1, 2].set_ylabel("F-score") 88 | 89 | # Add titles 90 | ax[0, 0].set_title("Model Training") 91 | ax[0, 1].set_title("Accuracy Score on Training Subset") 92 | ax[0, 2].set_title("F-score on Training Subset") 93 | ax[1, 0].set_title("Model Predicting") 94 | ax[1, 1].set_title("Accuracy Score on Testing Set") 95 | ax[1, 2].set_title("F-score on Testing Set") 96 | 97 | # Add horizontal lines for naive predictors 98 | ax[0, 1].axhline(y = accuracy, xmin = -0.1, xmax = 3.0, linewidth = 1, color = 'k', linestyle = 'dashed') 99 | ax[1, 1].axhline(y = accuracy, xmin = -0.1, xmax = 3.0, linewidth = 1, color = 'k', linestyle = 'dashed') 100 | ax[0, 2].axhline(y = f1, xmin = -0.1, xmax = 3.0, linewidth = 1, color = 'k', linestyle = 'dashed') 101 | ax[1, 2].axhline(y = f1, xmin = -0.1, xmax = 3.0, linewidth = 1, color = 'k', linestyle = 'dashed') 102 | 103 | # Set y-limits for score panels 104 | ax[0, 1].set_ylim((0, 1)) 105 | ax[0, 2].set_ylim((0, 1)) 106 | ax[1, 1].set_ylim((0, 1)) 107 | ax[1, 2].set_ylim((0, 1)) 108 | 109 | # Create patches for the legend 110 | patches = [] 111 | for i, learner in enumerate(results.keys()): 112 | patches.append(mpatches.Patch(color = colors[i], label = learner)) 113 | pl.legend(handles = patches, bbox_to_anchor = (-.80, 2.53), \ 114 | loc = 'upper center', borderaxespad = 0., ncol = 3, fontsize = 'x-large') 115 | 116 | # Aesthetics 117 | pl.suptitle("Performance Metrics for Three Supervised Learning Models", fontsize = 16, y = 1.10) 118 | pl.tight_layout() 119 | pl.show() 120 | 121 | 122 | def feature_plot(importances, X_train, y_train): 123 | 124 | # Display the five most important features 125 | indices = np.argsort(importances)[::-1] 126 | columns = X_train.columns.values[indices[:5]] 127 | values = importances[indices][:5] 128 | 129 | # Creat the plot 130 | fig = pl.figure(figsize = (9,5)) 131 | pl.title("Normalized Weights for First Five Most Predictive Features", fontsize = 16) 132 | pl.bar(np.arange(5), values, width = 0.6, align="center", color = '#00A000', \ 133 | label = "Feature Weight") 134 | pl.bar(np.arange(5) - 0.3, np.cumsum(values), width = 0.2, align = "center", color = '#00A0A0', \ 135 | label = "Cumulative Feature Weight") 136 | pl.xticks(np.arange(5), columns) 137 | pl.xlim((-0.5, 4.5)) 138 | pl.ylabel("Weight", fontsize = 12) 139 | pl.xlabel("Feature", fontsize = 12) 140 | 141 | pl.legend(loc = 'upper center') 142 | pl.tight_layout() 143 | pl.show() 144 | -------------------------------------------------------------------------------- /projects/boston-housing-prices/project_description.md: -------------------------------------------------------------------------------- 1 | # Content: Model Evaluation and Validation 2 | ## Project: Predicting Boston Housing Prices 3 | 4 | ## Project Overview 5 | In this project, you will apply basic machine learning concepts on data collected for housing prices in the Boston, Massachusetts area to predict the selling price of a new home. You will first explore the data to obtain important features and descriptive statistics about the dataset. Next, you will properly split the data into testing and training subsets, and determine a suitable performance metric for this problem. You will then analyze performance graphs for a learning algorithm with varying parameters and training set sizes. This will enable you to pick the optimal model that best generalizes for unseen data. Finally, you will test this optimal model on a new sample and compare the predicted selling price to your statistics. 6 | 7 | ## Project Highlights 8 | This project is designed to get you acquainted to working with datasets in Python and applying basic machine learning techniques using NumPy and Scikit-Learn. Before being expected to use many of the available algorithms in the sklearn library, it will be helpful to first practice analyzing and interpreting the performance of your model. 9 | 10 | Things you will learn by completing this project: 11 | 12 | - How to use NumPy to investigate the latent features of a dataset. 13 | - How to analyze various learning performance plots for variance and bias. 14 | - How to determine the best-guess model for predictions from unseen data. 15 | - How to evaluate a model's performance on unseen data using previous data. 16 | 17 | ## Description 18 | The Boston housing market is highly competitive, and you want to be the best real estate agent in the area. To compete with your peers, you decide to leverage a few basic machine learning concepts to assist you and a client with finding the best selling price for their home. Luckily, you\'ve come across the Boston Housing dataset which contains aggregated data on various features for houses in Greater Boston communities, including the median value of homes for each of those areas. Your task is to build an optimal model based on a statistical analysis with the tools available. This model will then be used to estimate the best selling price for your clients\' homes. 19 | 20 | ## Software and Libraries 21 | This project uses the following software and Python libraries: 22 | 23 | - [Python 2.7](https://www.python.org/download/releases/2.7/) 24 | - [NumPy](http://www.numpy.org/) 25 | - [pandas](http://pandas.pydata.org/) 26 | - [scikit-learn](http://scikit-learn.org/stable/) 27 | - [matplotlib](http://matplotlib.org/) 28 | 29 | You will also need to have software installed to run and execute a [Jupyter Notebook](http://ipython.org/notebook.html). 30 | 31 | If you do not have Python installed yet, it is highly recommended that you install the [Anaconda](http://continuum.io/downloads) distribution of Python, which already has the above packages and more included. Make sure that you select the Python 2.7 installer and not the Python 3.x installer. 32 | 33 | ## Starting the Project 34 | 35 | For this assignment, you can find the `boston_housing` folder containing the necessary project files on the [Machine Learning projects GitHub](https://github.com/udacity/machine-learning), under the `projects` folder. You may download all of the files for projects we'll use in this Nanodegree program directly from this repo. Please make sure that you use the most recent version of project files when completing a project! 36 | 37 | This project contains three files: 38 | 39 | - `boston_housing.ipynb`: This is the main file where you will be performing your work on the project. 40 | - `housing.csv`: The project dataset. You'll load this data in the notebook. 41 | - `visuals.py`: This Python script provides supplementary visualizations for the project. Do not modify. 42 | 43 | In the Terminal or Command Prompt, navigate to the folder containing the project files, and then use the command `jupyter notebook boston_housing.ipynb` to open up a browser window or tab to work with your notebook. Alternatively, you can use the command `jupyter notebook` or `ipython notebook` and navigate to the notebook file in the browser window that opens. Follow the instructions in the notebook and answer each question presented to successfully complete the project. A **README** file has also been provided with the project files which may contain additional necessary information or instruction for the project. 44 | 45 | ## Submitting the Project 46 | 47 | ### Evaluation 48 | Your project will be reviewed by a Udacity reviewer against the **Predicting Boston Housing Prices project rubric**. Be sure to review this rubric thoroughly and self-evaluate your project before submission. All criteria found in the rubric must be *meeting specifications* for you to pass. 49 | 50 | ### Submission Files 51 | When you are ready to submit your project, collect the following files and compress them into a single archive for upload. Alternatively, you may supply the following files on your GitHub Repo in a folder named `boston_housing` for ease of access: 52 | - The `boston_housing.ipynb` notebook file with all questions answered and all code cells executed and displaying output. 53 | - An **HTML** export of the project notebook with the name **report.html**. This file *must* be present for your project to be evaluated. 54 | 55 | Once you have collected these files and reviewed the project rubric, proceed to the project submission page. 56 | 57 | ### I'm Ready! 58 | When you're ready to submit your project, click on the **Submit Project** button at the bottom of the page. 59 | 60 | If you are having any problems submitting your project or wish to check on the status of your submission, please email us at **machine-support@udacity.com** or visit us in the discussion forums. 61 | 62 | ### What's Next? 63 | You will get an email as soon as your reviewer has feedback for you. In the meantime, review your next project and feel free to get started on it or the courses supporting it! 64 | -------------------------------------------------------------------------------- /classes/unsupervised-learning/feature-engineering.md: -------------------------------------------------------------------------------- 1 | # Feature Engineering 2 | 3 | ## Feature Scaling 4 | 5 | ![Feature Scaling Formula](images/feature-scaling.png) 6 | 7 | ### Min Max Rescaler Coding Quiz 8 | 9 | ```python 10 | """ quiz materials for feature scaling clustering """ 11 | 12 | ### FYI, the most straightforward implementation might 13 | ### throw a divide-by-zero error, if the min and max 14 | ### values are the same 15 | ### but think about this for a second--that means that every 16 | ### data point has the same value for that feature! 17 | ### why would you rescale it? Or even use it at all? 18 | def featureScaling(arr): 19 | min_x = min(arr) 20 | value_range = max(arr) - min_x 21 | 22 | if value_range == 0: 23 | return [1 for x in arr] 24 | 25 | return [float(x - min_x) / value_range for x in arr] 26 | 27 | # tests of your feature scaler--line below is input data 28 | data = [115, 140, 175] 29 | print featureScaling(data) 30 | 31 | ``` 32 | 33 | ### Min Max Rescaler in sklearn 34 | 35 | ![Min Max Rescaler in sklearn](images/min-max-rescaler-sklearn.png) 36 | 37 | ### Quiz: Algorithms affected by feature rescaling 38 | 39 | - Decision Trees 40 | - SVM with RBF Kernel 41 | - Linear Regression 42 | - K-means clustering 43 | 44 | **Answer:** SVM and K-means are affected by feature rescaling. For instance, take the feature rescaling example where `weight` and `height` were rescaled, so that their contributions to the outcome would be the same (i.e: between 0 and 1). Because SVM and K-means compute distances, scaling the features would affect the calculated distances and therefore would affect the result. 45 | 46 | In contrast, Decision Trees and Linear Regression don't measure distances. Decision Trees define for each feature available some constant value in order to split the data. So if we scale that feature, we will be scaling the constant split value by the same amount and the result won't be changed. In a similar way, Linear Regression defines coefficients for each feature available, so they are independent from each other and rescaling the features won't change the results 47 | 48 | ## Feature Selection 49 | 50 | ### Why Feature Selection? 51 | 52 | - Knowledge Discovery: usually we don't need all the features to solve a problem. Also, selecting the important features allow us to understand, interpret, visualize and get more insights about the problem. 53 | - Interpretability 54 | - Insight 55 | - Curse of dimensionality: to correctly fit a model, we need 2n training data, where `n` is the number of features of our model. 56 | 57 | ### How hard is feature selection? 58 | 59 | Feature selection is defined as: 60 | 61 | F(N) -> M, where M ≤ N 62 | 63 | To select all *M* relevant features from *N*, without knowing *M*, we need to try all subsets of *N*. This give us ![n choose m](http://latex.codecogs.com/gif.latex?%7Bn%20%5Cchoose%20m%7D) combinations, which, if we don't know *m* equals *2n* possibilities. 64 | 65 | ### Filtering and Wrapping Overview 66 | 67 | ![Filtering and Wrapping Overview](images/filtering-wrapping.png) 68 | 69 | ### Filtering and Wrapping Comparison 70 | 71 | ![Filtering and Wrapping Comparison](images/filtering-wrapping-comparison.png) 72 | 73 | - `Filtering` is a straightforward process where the search algorithm and the learner don't interact. 74 | - In contrast, in `wrapping` the learner gives feedback to the search algorithm about which features are impacting the learning process. Because of this, it is slower than filtering. 75 | - As an example, one could use a Decision Tree as a search algorithm for filtering. This DT would be trained until overfitting, thus maximizing information gain (the filtering criterion). Then we would extract the selected features from the flattened DT and input them into another learner, for example: KNN. In this setup, KNN's major setback, which is needing too much train data to fit the model to all features available, would be dealt with by the filtering done by the DT. 76 | 77 | ![Filtering and Wrapping Comparison 2](images/filtering-wrapping-comparison-2.png) 78 | 79 | - In the lesson, the teacher shows us how filtering uses the labeled data to get to the best results, while wrapping uses the bias of the learning algorithm to select the best features. 80 | - Examples of wrapping setups are: 81 | - hill climbing 82 | - randomized optimization 83 | - forward sequential selection 84 | - backward elimination 85 | 86 | ### Minimum Features Quiz 87 | 88 | ![Minimum Features Quiz](images/minimum-features-quiz.png) 89 | 90 | - The quiz asks the student to select the minimum features needed to minimize erros to (1) a Decision Tree, (2) an origin limited perceptron. 91 | - The solution involves testing the features using some filtering or wrapping algorithm, in trial-and-error fashion. 92 | - My solution was based on the insight that the predicted function is `a AND b`. Because of that is easy to note what features are necessary to minimize the error for both learners. 93 | 94 | ### Feature Relevance 95 | 96 | ![Feature Relevance](images/relevance.png) 97 | 98 | 1. A feature xi is *strongly relevant* if removing it degrades the Bayes Optimal Classifier (BOC) 99 | 2. A feature xi is *weakly relevant* if: 100 | - it is not *strongly relevant* 101 | - exists a subset of features S that by adding xi to S, improves BOC 102 | 3. otherwise the feature xi is irrelevant 103 | 104 | - In the `AND quiz-example`, the teacher shows that the features `a` and `b`are *strongly relevant*, since the function is `a AND b` and we need both to correctly predict the result. 105 | - By adding another feature `e` equal to `not a`, we make both `a` and `e` *weakly relevant*, because without one of them, we can still use the other to predict the result of `a AND b` (or `NOT e AND b`). 106 | - The other features `c` and `d` are *irrelevant*, but not *useless* as we'll see next. 107 | 108 | ### Feature Relevance vs Usefulness 109 | 110 | ![Feature Relevance](images/relevance-vs-usefulness.png) 111 | 112 | - A feature is relevant if it affects the result of the BOC. 113 | - A feature is useful for a model/predictor, if it affects the result of that model/predictor 114 | -------------------------------------------------------------------------------- /projects/image-classification/helper.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | from sklearn.preprocessing import LabelBinarizer 5 | 6 | 7 | def _load_label_names(): 8 | """ 9 | Load the label names from file 10 | """ 11 | return ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'] 12 | 13 | 14 | def load_cfar10_batch(cifar10_dataset_folder_path, batch_id): 15 | """ 16 | Load a batch of the dataset 17 | """ 18 | with open(cifar10_dataset_folder_path + '/data_batch_' + str(batch_id), mode='rb') as file: 19 | batch = pickle.load(file, encoding='latin1') 20 | 21 | features = batch['data'].reshape((len(batch['data']), 3, 32, 32)).transpose(0, 2, 3, 1) 22 | labels = batch['labels'] 23 | 24 | return features, labels 25 | 26 | 27 | def display_stats(cifar10_dataset_folder_path, batch_id, sample_id): 28 | """ 29 | Display Stats of the the dataset 30 | """ 31 | batch_ids = list(range(1, 6)) 32 | 33 | if batch_id not in batch_ids: 34 | print('Batch Id out of Range. Possible Batch Ids: {}'.format(batch_ids)) 35 | return None 36 | 37 | features, labels = load_cfar10_batch(cifar10_dataset_folder_path, batch_id) 38 | 39 | if not (0 <= sample_id < len(features)): 40 | print('{} samples in batch {}. {} is out of range.'.format(len(features), batch_id, sample_id)) 41 | return None 42 | 43 | print('\nStats of batch {}:'.format(batch_id)) 44 | print('Samples: {}'.format(len(features))) 45 | print('Label Counts: {}'.format(dict(zip(*np.unique(labels, return_counts=True))))) 46 | print('First 20 Labels: {}'.format(labels[:20])) 47 | 48 | sample_image = features[sample_id] 49 | sample_label = labels[sample_id] 50 | label_names = _load_label_names() 51 | 52 | print('\nExample of Image {}:'.format(sample_id)) 53 | print('Image - Min Value: {} Max Value: {}'.format(sample_image.min(), sample_image.max())) 54 | print('Image - Shape: {}'.format(sample_image.shape)) 55 | print('Label - Label Id: {} Name: {}'.format(sample_label, label_names[sample_label])) 56 | plt.axis('off') 57 | plt.imshow(sample_image) 58 | 59 | 60 | def _preprocess_and_save(normalize, one_hot_encode, features, labels, filename): 61 | """ 62 | Preprocess data and save it to file 63 | """ 64 | features = normalize(features) 65 | labels = one_hot_encode(labels) 66 | 67 | pickle.dump((features, labels), open(filename, 'wb')) 68 | 69 | 70 | def preprocess_and_save_data(cifar10_dataset_folder_path, normalize, one_hot_encode): 71 | """ 72 | Preprocess Training and Validation Data 73 | """ 74 | n_batches = 5 75 | valid_features = [] 76 | valid_labels = [] 77 | 78 | for batch_i in range(1, n_batches + 1): 79 | features, labels = load_cfar10_batch(cifar10_dataset_folder_path, batch_i) 80 | validation_count = int(len(features) * 0.1) 81 | 82 | # Prprocess and save a batch of training data 83 | _preprocess_and_save( 84 | normalize, 85 | one_hot_encode, 86 | features[:-validation_count], 87 | labels[:-validation_count], 88 | 'preprocess_batch_' + str(batch_i) + '.p') 89 | 90 | # Use a portion of training batch for validation 91 | valid_features.extend(features[-validation_count:]) 92 | valid_labels.extend(labels[-validation_count:]) 93 | 94 | # Preprocess and Save all validation data 95 | _preprocess_and_save( 96 | normalize, 97 | one_hot_encode, 98 | np.array(valid_features), 99 | np.array(valid_labels), 100 | 'preprocess_validation.p') 101 | 102 | with open(cifar10_dataset_folder_path + '/test_batch', mode='rb') as file: 103 | batch = pickle.load(file, encoding='latin1') 104 | 105 | # load the training data 106 | test_features = batch['data'].reshape((len(batch['data']), 3, 32, 32)).transpose(0, 2, 3, 1) 107 | test_labels = batch['labels'] 108 | 109 | # Preprocess and Save all training data 110 | _preprocess_and_save( 111 | normalize, 112 | one_hot_encode, 113 | np.array(test_features), 114 | np.array(test_labels), 115 | 'preprocess_training.p') 116 | 117 | 118 | def batch_features_labels(features, labels, batch_size): 119 | """ 120 | Split features and labels into batches 121 | """ 122 | for start in range(0, len(features), batch_size): 123 | end = min(start + batch_size, len(features)) 124 | yield features[start:end], labels[start:end] 125 | 126 | 127 | def load_preprocess_training_batch(batch_id, batch_size): 128 | """ 129 | Load the Preprocessed Training data and return them in batches of or less 130 | """ 131 | filename = 'preprocess_batch_' + str(batch_id) + '.p' 132 | features, labels = pickle.load(open(filename, mode='rb')) 133 | 134 | # Return the training data in batches of size or less 135 | return batch_features_labels(features, labels, batch_size) 136 | 137 | 138 | def display_image_predictions(features, labels, predictions): 139 | n_classes = 10 140 | label_names = _load_label_names() 141 | label_binarizer = LabelBinarizer() 142 | label_binarizer.fit(range(n_classes)) 143 | label_ids = label_binarizer.inverse_transform(np.array(labels)) 144 | 145 | fig, axies = plt.subplots(nrows=4, ncols=2) 146 | fig.tight_layout() 147 | fig.suptitle('Softmax Predictions', fontsize=20, y=1.1) 148 | 149 | n_predictions = 3 150 | margin = 0.05 151 | ind = np.arange(n_predictions) 152 | width = (1. - 2. * margin) / n_predictions 153 | 154 | for image_i, (feature, label_id, pred_indicies, pred_values) in enumerate(zip(features, label_ids, predictions.indices, predictions.values)): 155 | pred_names = [label_names[pred_i] for pred_i in pred_indicies] 156 | correct_name = label_names[label_id] 157 | 158 | axies[image_i][0].imshow(feature) 159 | axies[image_i][0].set_title(correct_name) 160 | axies[image_i][0].set_axis_off() 161 | 162 | axies[image_i][1].barh(ind + margin, pred_values[::-1], width) 163 | axies[image_i][1].set_yticks(ind + margin) 164 | axies[image_i][1].set_yticklabels(pred_names[::-1]) 165 | axies[image_i][1].set_xticks([0, 0.5, 1.0]) 166 | --------------------------------------------------------------------------------