Sunday, 23 December 2018

Octave

Commands
  • % means comment
  • ; suppresses print output
  • 2^6(2 power 6)
  • 1==2
  • 1~=2 (is not equals)
  • Logical operations
    •  1&&0
    • 1||0
  •  Vectors & Matrix
    • A=[1 2; 2 3; 4 5]
    • V=1:0.2:2  % Bunch of elements starts from 1, increments with 0.2, until you get up to 2
    • V=1:6  %means 1 to 6
    • ones(2,3)   % 2 by 3 matrix with all elements as 1
    • use try zeros, rand
    • w=-6+sqrt(10)*(randn(1,10000))
      hist(w)     % generates histogram
      hist(w,50) % histogram with 50 bins
    • I= eye(4)     % 4*4 identity matrix
    • A(2,:) % to fetch every element of 2nd row 
    • A(:,2)  % 2nd column
    • A([1,3],:) % every element in 1st and 3rd rows
    • A=[A,[100;102;102]]  % append another column vector
    • A(:)  % put all elements of A into single vector
    • C=[A B] % concatenate 2 matrices
    • C=[A; B] % concatenate 2 matrices by adding B to bottom of A
    • A .* B  %element wise multiplication
    • A .^ 2  %element wise square
    • 1 ./A %element wise reciprocal
    • A'   % transpose
  • Octave variables in memory
    • who/whos
    • load
      • load featuresx.dat  %featuresx will be variable after loading
      • clear featuresx % to clear the variable
      • save hello.mat v % to save varaible v to hello.mat
      • clear   % clears all variables
  • Function
    • file extension .m
      • function y= squareThisNumber(x)
        y=x^2;
    • Octave searches for the file in the current directory
    • Alternatively add path using command addpath();
    • Octave function can return more than one value

Thursday, 6 December 2018

Machine Learning & AI

  • AI - Enables machine to think
    • ML - Provides statistical tools to explore the data. The has 3 techniques Supervised, unSupervised, reinforcement or semi-supervised learnings
      •  Deep Learning -Multi neural architecture(simulate human brain)- ANN for number data, CNN for images, RNN for timeseries data
  • Data science -  uses all tools from AI,ML & deep learning & creates AI system


Types of Data
    • Categorical - 
      • Categories or groups like car brands 
      • Questions to Yes/No answers
    • Numerical
      • Discreet(finite number)
      • Continuous (infinite)
 Measurement Levels
  • Qualitative
    • Nominal (cannot be ordered)
      • Car brands, seasons in year, 
    • Ordinal
      • tastes disgusting, unappetizing, neutral, tasty, delicious
  • Quantitative
    • Interval
      •  doesnt have true 0
      • Temperatures,
    • Ratio
      • Have 0
 Representation of Categorical variables.
  • Frequency distribution tables
  • Bar charts
  • Pie charts(relative percentage/frequency)
  • Pareto diagrams
    • This is special type of Bar chart, where categories are shown in descending order of frequency. And a curve on the same graph showing cumulative frequency. 
    • This combines strong sides of the bar and pie charts
Pareto Principle
80% of the effect comes from 20% of the causes.(80-20 rule).
Numerical Variables
  • Frequency distribution table with intervals
  • interval width = (largest number-smallest number)/#desired intervals
  • relative frequency which is equal to frequency/total frequency
Representation of Numerical variables.
  • Histogram
Represent Relationship between two variables
  • Cross tables -> Variation of Bar chart or side by side bar chart
  • Scatter plots-> two numerical variables

 
https://www.coursera.org/learn/machine-learning/home/welcome

Simple Linear Regression
Multiple Linear Regression
Polynomial Regression
Support Vector Regression (SVR)
Decision Tree Regression
Random Forest Regression
Evaluating Regression Models Performance

What is Machine Learning?

Two definitions of Machine Learning are offered. Arthur Samuel described it as: "the field of study that gives computers the ability to learn without being explicitly programmed." This is an older, informal definition.

Tom Mitchell provides a more modern definition: "A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."
Example: playing checkers.
E = the experience of playing many games of checkers
T = the task of playing checkers.
P = the probability that the program will win the next game.
In general, any machine learning problem can be assigned to one of two broad classifications:
Supervised learning and Unsupervised learning.

Usages
  • Database mining  eg: web click data, medical records, biology, engineering
  • Applications that can't be programmed. eg: Autonomous helicopter, handwriting recognition, Natural language processing, 
  • Self-customizing programs - Amazon, Netflix product recommendations. 
Machine Learning Algorithms
  • Supervised Learning
  • Unsupervised Learning

Supervised Learning

In supervised learning, we are given a data set and already know what our correct output should look like, having the idea that there is a relationship between the input and the output.

Supervised learning problems are categorized into "regression" and "classification" problems. In a regression problem, we are trying to predict results within a continuous output, meaning that we are trying to map input variables to some continuous function. In a classification problem, we are instead trying to predict results in a discrete output. In other words, we are trying to map input variables into discrete categories.
Example 1:
Given data about the size of houses on the real estate market, try to predict their price. Price as a function of size is a continuous output, so this is a regression problem.
We could turn this example into a classification problem by instead making our output about whether the house "sells for more or less than the asking price." Here we are classifying the houses based on price into two discrete categories.
Example 2:
(a) Regression - Given a picture of a person, we have to predict their age on the basis of the given picture
(b) Classification - Given a patient with a tumor, we have to predict whether the tumor is malignant or benign.

Unsupervised Learning

Unsupervised learning allows us to approach problems with little or no idea what our results should look like. We can derive structure from data where we don't necessarily know the effect of the variables.
We can derive this structure by clustering the data based on relationships among the variables in the data.
With unsupervised learning there is no feedback based on the prediction results.
Example:
Clustering: Take a collection of 1,000,000 different genes, and find a way to automatically group these genes into groups that are somehow similar or related by different variables, such as lifespan, location, roles, and so on.
Non-clustering: The "Cocktail Party Algorithm", allows you to find structure in a chaotic environment. (i.e. identifying individual voices and music from a mesh of sounds at a cocktail party).





Matlab, Octave, Clojure, Julia, Python, R: Octave and Matlab are optimized for rapid vectorized calculations, which is very useful in Machine Learning. R is a nice tool, but:
1. It is a bit too high level. This course shows how to actually implement the algorithms of machine learning, while R already has them implemented. Since the focus of this course is to show you what happens in ML algorithms under the hood, you need to use Octave 2. This course offers some starter code in Octave/Matlab, which will really save you tons of time solving the tasks.


Linear Regression with One Variable

 

  Cost Function - J (@1)

We can measure the accuracy of our hypothesis function by using a cost function. This takes an average difference (actually a fancier version of an average) of all the results of the hypothesis with inputs from x's and the actual output y's.
 J(θ0,θ1)=12mi=1m(y^iyi)2=12mi=1m(hθ(xi)yi)2J(\theta_0, \theta_1) = \dfrac {1}{2m} \displaystyle \sum _{i=1}^m \left ( \hat{y}_{i}- y_{i} \right)^2 = \dfrac {1}{2m} \displaystyle \sum _{i=1}^m \left (h_\theta (x_{i}) - y_{i} \right)^2

To break it apart, it is 12\frac{1}{2}
xˉ\bar{x} where xˉ\bar{x} is the mean of the squares of hθ(xi)yih_\theta (x_{i}) - y_{i} , or the difference between the predicted value and the actual value.
This function is otherwise called the "Squared error function", or "Mean squared error". The mean is halved (12)\left(\frac{1}{2}\right)
as a convenience for the computation of the gradient descent, as the derivative term of the square function will cancel out the 12\frac{1}{2} term.