Ad

Tuesday, March 5, 2019

Technical Interview Tools and Resources - Data Structure & Algorithms


Monday, March 4, 2019

Baye's Theorem

P(A,B) = P(A|B)P(B) = P(B,A) = P(B|A)P(A)
P(A|B)P(B) = P(B|A)P(A)

P(A|B) = P(B|A)P(A) / P(B)  # divide by P(B) on both sides
P(e|T) = P(T|event)P(event) / P(T)

P(A|B) is called the posterior
P(B|A) is called the likelihood
P(A) is called the prior
P(B) is called the marginal likelihood
https://towardsdatascience.com/what-is-bayes-rule-bb6598d8a2fd

Sunday, March 3, 2019

Udacity machine learning nanodegree mega review part 5

Lesson 5 Decision Trees
See more in the series visit the main course outline page


Decision tree can be seen as a classification problem
Example 1 Dating : what attribute to split one.
Intuition 20 questions, ask broader questions at first to narrow down the domain space for example animal vs personal

Decision tree learning
1.First find the best attribute to split
For example splitting in half (binary search)
2. Ask questions depending on the answer
3. Follow the answer path
4. Go back to no.1 until an answer is found
The above describes an ALGORITHM

Best attribute to split
Depends on entropy
Does the split improve information gain

Decision nodes can be used to write boolean operation or gates logic.

AND(A,B)

A
/f \t
-     B
       /f\t
       -  +

IF an operation is communicative, that means if we switch the operands will still get the same result. AND(A,B) is the same as AND(B,A)

Extra: random forest is a collection of randomized decision trees that was selected if it generated good result. Machine continuous decision tree branch can be a fraction of 1. Machine discrete decision branch true false. Information gain formula will automatically rule out some redundancy. Pruning the tree collapse the tree and see the error get a smaller tree avoid over fitting 

Machine Learning Concepts Overview


  • Without being explicitly program each step of instruction
  • Collect data make observations
  • Make use of statistics
  • Supervised unsupervised 
  • Labeled vs unlabeled data
  • Features vs labels
  • Model: train vs inference
  • Regression vs classification 
  • Bias simplified to 2D is like intercept b in y=wx+b
  • We care about minimizing loss across entire dataset.
  • SSE will always increase with number of datapoints.
  • That's why we like SSE/N averaged out = MSE
  • MSE = SSE/n number of data points.
  • The MSE isnt always obvious during visual inspection.
  • Reducing Loss
    • mini-batch gradient descent
    • stochastic gradient descent
    • Tuning learning rate

Find a direction to go in parameter space to reduce loss.
Compute gradient
Compute derivative of loss function --> how to decrease loss.
Take small steps in direction of gradient that min loss
Called gradient steps
Strategy: gradient descent
todo derive derivative of MSE
Initialization matters for NN, notoriously non-convex, like an egg carton. Initialization matters more.
Empirically people found there's no need to compute gradient over entire dataset.
Can compute gradient on small data samples
stochastic gradient descent: one example at a time
mini-batch gradient descent: batch of 10-1000
loss & gradient are averaged over the batch
in practice we don't compute the gradient for the entire dataset nor do we compute gradient gradient for one example, instead we do something in the middle: mini batch


We also plan to turn this article into a great ML pattern article on Medium, stay tuned.






















Machine learning crash course google 

Best of Uniqtech's Medium Articles on Data Science, Machine Learning and Deep Learning


Famous Machine Learning Datasets You Need to Know https://link.medium.com/6omM6q0vBU #data #machinelearning #deeplearning #datascience #learntocode


Host an HTML website on Github in 5 minutes HD https://youtu.be/a16Oz2MX-7Q via @YouTube #HTML #CSS #github #webhosting #tutorial #webdevelopment



Getting Started with Natural Language Processing NLP for Beginners https://link.medium.com/d4nnsFiinU #NLP #DeepLearning #Data



Saturday, March 2, 2019

Basic Machine Learning Patterns - Machine Learning 101

Traditional Supervised Machine Learning

k-Nearest Neighbors, Linear Regression, Logistic Regression, Support Vector Machines (SVM), Decision Trees and Random Forest. Finally Neural Networks (NN). NN has gotten so popular it is often a category of its. Many innovations have happened in the past 5 years that it is no longer considered a traditional method. 

Traditional Unsupervised Learning

Clustering: k-means, Hierarchical Cluster Analysis (HCA), Expectation Maximization, Visualization and dimensionality reduction: Principal Component Analysis (PCA), Kernel PCA, Locally-Linear Embedding (LLE), t-distributed Stochastic Neighbor Embedding (t-SNE), Assocation rule learning: Apriori, Eclat.

We can use unsupervised learning for feature extraction to simplify data and reduce computation cost. Also used for anomaly detection, outlier detection.

Import Data

## Read csv into Pandas DataFrame
import numpy as np
import pandas as pd
# TODO import data from source 
%matplotlib inline
file = 'my_file.csv'
data = pd.read_csv(file)
Data.head()
type(data) #->DataFrame

Data Preprocessing - Target Column

## store target column as a separate vector
## remove target column from training data
target = data['Target_Column']
data = data.drop('Target_Column', axis = 1)
data.head()

Normalization

Data always needs to be normalized to make input features comparable with each other. Generally we want to normalize the values so that they are between 0 and 1. Then we use sigmoid activation function get outputs between 0 and 1.

Example:
  • Normalize RGB value divide by 255
  • Normalize a Yelp review divide by 5 for five stars scale

Activation Functions

We can use activation functions to squash output numbers into certain ranges for example 0 and 1.

Vector Spaces

The decision boundary can span a line, but also a plane, even a hyper plane because data can be 2D aka planes, 3D hyperplanes.

Metric - Calculate Accuracy Scores

def accuracy_score(y, pred):
    if len(y) == len(pred):
        return "Accuracy score is {:.2f}.".format((y == pred).mean()*100)
    else:
        return "Exception: Lengths of inputs don't match."

Machine Learning in the Real World

Are you willing to let classifiers make business decisions for you?

Broadcasting

"The term broadcasting describes how numpy treats arrays with different shapes during arithmetic operations. Subject to certain constraints, the smaller array is “broadcast” across the larger array so that they have compatible shapes." (source scipy doc).

ROC Curve
Receiver operating characteristic (ROC) plots the true positive rate (TPR) against the false positive rate (FPR) at various threshold setting (source: wikipedia). It's a measure of how good the decision frontier is at each split.
Read more about ROC Curve Here

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. 

React UI, UI UX, Reactstrap React Bootstrap

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