Ad

Saturday, March 2, 2019

Udacity Machine Learning Nanodegree Mega Review Part 1

Introduction. 
  • Section 1 Machine Learning Foundations
  • 1.4 Training Models (Luis Serrano)
    • 1.4.1 Intro: 1. evaluate how well the model is doing,  2. how to improve the model based on metrics
    • 1.4.2 Outline: a) problem, b) tools aka algorithms, measurement tools aka metrics (focus of this section) 
    • 1.4.3. Statistics refresher: link to stats concepts mean, median, variance link to free descriptive and inferential statistics by Udacity
    • 1.4.4 loading data into pandas `import pandas` `data=pandas.read_csv('file_name.csv')` pandas cheatsheet
    • 1.4.5 Numpy Arrays: Pandas read_csv and stores data as a dataframe, use this code to query one column `df['name_of_col']`, query more than one column `df[['col_1','col_2']]`. A common operation is to split dataframe into feature and target, then convert each to numpy arrays for efficient calculation. `numpy.array(df)`
    • 1.4.6 Training models in sklearn: this course will cover important classification algorithms including Logistic Regression, Neural Networks, Decision Tree, Support Vector Machines. Modeling data is easy in sklearn `classifier.fit(X,y). Important exercise playing with decision boundaries. Seems like decision tree really fits "boxy" data well, because it can draw vertical and horizontal boundaries. But careful, the data may be "circular", in that case NN and SVM can fit better. 
    • 1.4.7 Tuning parameters manually classifier = SVC(kernel = None, degree = None, gamma = None, C = None)  kernel (string): 'linear', 'poly', 'rbf'. degree (integer): This is the degree of the polynomial kernel, if that's the kernel you picked (goes with poly kernel). gamma (float): The gamma parameter (goes with rbf kernel). C (float): The C parameter. RBF can fit some strange "bacteria" shaped data, while poly can fit some strange abstract art like data. 
    • 1.4.8 Tuning parameters automatically: useful when data gets big
  • 1.5 Testing Models:
    • 1.5.1 Regression model returns  a numeric number, classification model returns a state. Testing reveals how well the model is doing. It's possible to make a model with a frontier or fitted line that's so curvey, it fits data perfectly, but it doesn't generalize well. Requirement of defining a good testing evaluation function, is to figure out if the model can generalize. Split datainto train_data, test_data. Train model with train_data, test model with test_data. from sklearn.model_selection import train_test_split 
    • X_train, X_test, y_train, y_test = from sklearn.model_selection import train_test_split(X,y,test_size= 0.25) if you try the code above you will get an error ImportError: No module named model_selection. Previously the train_test_split is in ImportError: No module named model_selection 
    • 1.5.2 cool visualization of train_test_split, plotting X_train, X_test, y_train, y_test with different tickers. 
  • Regression vs Classification: quantitative continuous vs discrete classes and categories. 

Pytorch Cheatsheet for beginners

train_loader, test_loader in python code pattern

train_loader = torch.utils.data.DataLoader(train_data, batch_size=batch_size, num_workers=num_workers)
test_loader = torch.utils.data.DataLoader(test_data, batch_size=batch_size, num_workers=num_workers)

Pytorch dataloader helps load data in batches such as images.

Flavors of Pytorch Model Initialization

Functional

import torch.nn as nn
import torch.nn.functional as F

Object Oriented OOP

class Autoencoder(nn.Module):
    def __init__(self, encoding_dim):
        super(Autoencoder, self).__init__()
        ## encoder ##
        
        ## decoder ##
        

    def forward(self, x):
        # define feedforward behavior 
        # and scale the *output* layer with a sigmoid activation function
        
        return x

Best Practice:
Pytorch do sanity check load checkpoint and make sure everything worked. Imshow() the output image make sure it is the desired output. Do sanity check, visual check.

Udacity Machine Learning Nanodegree Mega Review Part 2

Lesson 2 Introduction to Regression
See more in the series visit the main course outline page



Cross validation: any train test validation split should be representative of the real world dataset. Else the model is invalid. Can compare stats, representation, distribution.  IID independently identically distributed, drawn from same distribution. Fundamental assumptions of algorithms.

Lesson 3 More Regression

Section by Georgia Tech, professor also led courses for ML for finance. He's really good. Much better than many Georgia Tech instructors who gave contents for Udacity.

.2 Parametric regression
Basic line is y=mx+b
Parameters are m,b
There are regions of the data the line cannot track because it's just a line. We can then use higher degree polynomial.
y = m_2 * x**2 + m_1 * x + b
m_2,m_1, b are the parameters.

Lesson 3 Supervised Learning
Lesson 3 More Regressions
.3 K Nearest Neighbors
Data centric approach, instance based approach. Example historic data, weather prediction based on weather data.
Identify related datapoints, then what to do? : use the mean of their y values, or prediciton values. voting

Kernel Regression: weigh each data point based its distance. KNN each data point is weighted equally.

Parametric vs Non Parametric
Yes, the cannon ball distance can be best estimated using a parametric model, as it follows a well-defined trajectory.


On the other hand, the behavior of honey bees can be hard to model mathematically. Therefore, a non-parametric approach would be more suitable.

Biased means theres a formula for it. It's biased towards the math formula. There's no formula for the other method, so it's unbiased.

Parametric don't have to store original data, space efficient, however if there's new data, we cannot update it. Training is slow, querying is fast.

Non parametric querying is slow. Need to store all data points. Easily add new data points. (Kind of like Neo4j). Training is fast. Avoid assuming type of model such as linear or quadratic. If complex, we don't need to assume.

.7 Quiz : which problems are regression useful
.8  Quiz: Are polynoials linears: is polynomial regression still linear?
yes: the space of polynomials is linear in its coeffecients.

Lesson 4 Regressions in sklearn
.1 Quiz Continuous Output Quiz : 

Udacity Machine Learning Nanodegree Mega Review Part 8

Markov Decision Process


See more in the series visit the main course outline page

Important
Lesson 2 Markov Decision Process
.5 Markov Decision Process - 1: single agent, there are STATES s - a set of tokens that represent every state one can be in - which part of the grid I am in - the entire grid minus blocked states, (x,y) coordinates, process for making decisions, MODEL T(s,a,s')~Pr(s'|s,a)

.6 Markov Decision Process - 2:

Action things you can do in a particular STATE: UP DOWN LEFT RIGHT
Action is also a function of state A(s), or a set of actions - A

Model aka the transition model describes the rule of the world. How to play the game.

The transition Model is a function of two variables state, action, next state aka state_prime.

S' can equal to S : means to stay.

The transition model outputs the probability one would end up at S' given that person is transitioning from S with action a

Deterministic case: means there is no noise. Take every action with certainty: 100%. In nondeterministic, action execute faithfully 80% of time, 0.8, 0.1, 0.1,

Model describes the rule of the game. Also captures what happens if you do something. Physics of the world.
Pr(S'|S,A)
Transition models are probablistic by nature
.7 Markov Decision Process - 3: Markovian property, Markov means you don't have to condition on everything pass the most recent state - Markov only the present matters. Only depends on current state s. Pr(s'|s,a) there's only one dependency on s not s1 s2 s3.

You can turn anything into markovian process by making sure the current state remembers anything from the past.

Second property of MDP: nothing ever changes, things are stationery, these rules don't change over time.

Reward : R(s) for being in a state, R(s,a) reward for being in a state and take an action,  R(s,a,s') being in a state take an action and end up in s'. All mathematically equivalent. Intuition:
Green or goal is great. Want to be there. Red is punishment, restricted area. Encompasses the domain knowledge. Usefulness of entering that state.

.8 Markov Decision Process - 4: MDP describes a problem, the solution is described in Pi or policy. Pi(s) --> a takes in a state, and outputs the action to take. It's a solution to the MDP.

Pi* or policy star is the optimal policy that maximizes your long term reward across time.

Autoencoder Decoder Notes Cheatsheet from Udacity Deep Learning Nanodegree


  • Auto encoder decoder are two neural networks that are trained to encode, and then decode the input based on training data and examples. The goal is to compress with little loss and decode to get as close to the original as possible while getting performance gain and efficiency. 
  • Encode is to obtain a compressed representation of the input
  • Decode is takes the representation from encoders and try to reconstruct the original input
  • A compressed representation can save space, time, and improve performance of  storage, serving and other computer, network tasks 
  • The depth dimensions should change as follows: 784 inputs > encoding_dim > 784 outputs.

Machine Learning & Deep Learning Extra Curricular Reading List


  • Best LSTM articles Article 1 Lecture on LSTM  Article 2 Article 3
  • LSTM overview
  • https://pytorch.org/tutorials/intermediate/char_rnn_classification_tutorial.html
  • https://pytorch.org/docs/stable/_modules/torch/nn/modules/rnn.html
  • https://pytorch.org/tutorials/intermediate/char_rnn_classification_tutorial.html
  • https://towardsdatascience.com/understanding-bidirectional-rnn-in-pytorch-5bd25a5dd66
  • This Is How Google Rejected Me Just To Tell Me “Yes” The Year After https://blog.pramp.com/this-is-how-google-rejected-me-just-to-tell-me-yes-the-year-after-d1c49dc53f88
  • Introduction to Recurrent Neural Network (important, high quality) https://www.cpuheater.com/deep-learning/introduction-to-recurrent-neural-networks-in-pytorch/
  • Highly recommended article on learning rate
  • Uniqtech Co Data Science Bootcamp


Neo4j Building the BBC GoodFoods Graph (Neo4j Online Meetup #51) Notes Transcript Lessons Learned









Building the BBC GoodFoods Graph (Neo4j Online Meetup #51) Food Data great for testing out all important neo4j features. Great dataset for illustrating Neo4j's capability for name entity management, master data management, knowledge graph. First look for an API for the data. Almost people scrape if not available. Beautiful Soup. Hard to ID ingredient, trained a ML to recognize that. Nice JSON object in Page Source. On the top of the page. Cool tip to scrape. File with a stream of JSON one per recipe. Decode using a library from JavaScript code and JSON to Python Dictionary. Some exception handling if no data, can skip recipe. Use apcjones.com to construct the graph. Design a graph model first: model the data also needs to find out what question do we want to ask the data. Neo4j easy to change. Don't have to get the model right the first time. Materials available in github. Also a browser guide. Tool called arrows:Create node, entities, the nouns in the data. First node Recipe. Click into the apcjones node, add title as property example title: Chocolate Cake. https://youtu.be/nEIJmH6FIjs?t=643


React UI, UI UX, Reactstrap React Bootstrap

React UI MATERIAL  Install yarn add @material-ui/icons Reactstrap FORMS. Controlled Forms. Uncontrolled Forms.  Columns, grid