Machine Learning Basics (Courtesy: Edureka - https://www.youtube.com/watch?v=b2q5OFtxm6A)
- Machine learning is applying AI that provides the systems/computers ability to automatically learn and improve from experience without being programmed.
- Making computers learn themselves (smarter) and teaching them to make decisions using data (where writing software/application for it becomes a bottleneck or tedious work) , let data do the thing instead.
- Features of ML:
- Uses data to detect patterns in dataset and adjust program actions accordingly
- It focuses on devt of computer programs that can teach themselves to grow and change when exposed to new data.
- It enables computers to find hidden insights using iterative algorithms without being explicitly programmed.
- So ML is a method of data analysis that automates analytical model building
- Examples of applications we daily use (which are incorporating or using ML internally):
- Google maps navigation: Everyone uses google maps for navigation purpose, and exposes their current location, enters source and destination regularly. So google has a collection of this massive data including above details with the time taken by each user to reach from src to dest. Based on the data analysis it does, it comes to know about the regular traffic areas where user's time is consumed maximum times. And accordingly it suggests u heavy traffic, low/light traffic based on the combination of old and recent data that has come from users who have used google navigation.
- Facebook friend suggestion and friend tagging with image recognition:
- Automatic friend tagging suggestion in FB. How it comes to know about ur friends ? So FB uses face detection and image recognition technique to find the face/image of the person which matches its database and hence it suggests us to tag that person based on the deep face.
- Deep face is FB's ML project/application which is responsible for refining recognition of faces and define which person is in picture with u, and also provides option for alternative tag (alt) to the images already uploaded on FB; which it ideally uses to gather data and store it for ML purpose.
- Cab booking (Uber):
- U provide your location, enter src and dest. It saves all your historic data (for all users). and provides auto suggestion to you based on your past bookings done.
- It uses your and other similar route bookings made by other users (ex: Home to Office stored on ur local app which is actually for ex: Pimple Saudagar to Hinjewadi Phase 1). Many users should have saved the same route in their app; which the app keeps measuring/learning daily on how much time it takes daily for each users to reach and come back. Based on it, it provides suggestions on ETA (Estimated Time) for arriving to destination.
- Virtual Person Assistant - Alexa, Siri, Google, Cortana
- As name suggests, it helps us to find useful info when asked via voice msg or text.
- Few application of ML here are speech recognition to text conversion, text to speech conversion and natural language processing.
- Suppose u search for a product on Amazon, but do not buy it, but next day u have a suggestion or advertise not only in amazon app but also when u watch videos on youtube or checking ur FB. This happens because google tracks your search history and suggests ads based on ur past search history made. This is the best use of ML. Amazon's 35% revenue is generated by product recommendation.
- Self-driving cars by google and Tesla are also using ML and IoT.
- Another example is the price surge you find in Uber. It tracks the hits it gets in weekends, holidays and based on the rising/increasing demand in that time, it gives surge in price. This is also ML.
- Another ex of online streaming - Netflix, Amazon Prime, Hulu
- They track your searched movies, tv shows, also tracks the pause, rewind, replays made by each user for particular videos and provides suggestions accordingly. This is ML.
- Now, ML is possible because from 2012 to 2016, the support for new hardware increased, new latest CPUs, high storage devices, heavy RAM support have increased not only in laptops but also in mobile apps.
- So ML has become more effective in use due to the support of hardware it got from last 4-5 years as people have started using the apps Thand providing their personal data very frequently.
- ML is mostly done in Python; as Python has got more no. of libraries

- Types of ML:
- Supervised ML
- Reinforced ML
- Unsupervised ML
- Supervised ML : You input the raw data in the form of labelled faces. It can also be images of nature with rivers, mountains, fort, garden, etc. OR a combination of faces with some non-face background also. So here we train the model with input of face or non-face image.
- We provide data to the algorithm > Algo provides data to the model > it uses training data set to understand what is there in the picture (face, non-face)
- After model is filled with training and processing, in order to test it, we provide input of a face or non-face.
- In SL, we exactly know the output


- Supervised Learning Algorithms:
- Linear Regression - used to estimate real values like cost of house, number of calls, total sales based on the continuous variables.
- Logistic Regression - used to estimate street values. Example - which are binary values like 0 or 1 , yes or no, true or false - based on the set of independent variables.Example - Chances of a team winning today, chances of will it rain today or not. So, when the output of a particular algo is yes/no, or binary, then only we use logistic regression.
- Decision Tree - used for classification problems, works with both categorical and continuous dependent variables.
- Random Forest - Similar to decision tree, but gives better prediction accuracy than decision tree.
- Naive Bayes Classifier - covered later
- Unsupervised Learning
- This learning is with the input data which is neither classified nor labelled.
- Example : input imgs of banana, apple, etc which dont have labels here.
- So the algorithm here visually gets the features of particular set of data input and makes clusters (i.e clusters of red looking apples, clusters of yellow bananas) and also based on shape it determines which object it is.

- Reinforced Learning
- RL is the learning by interacting with space or the environment.
- It selects the actions on the basis of it's past experience, exploration and also by new choices.

- Algorithms:
- Linear regression:
- LR is a technique used to predict the unknown value of variable (dependent variable) from the
- known value of another variables (independent variable)
- Dependent variable (DV) is the variable to be predicted or explained in the regression model
- Independent var (IDV) is the variable related to the dependent variable in a regression equation
- Demo:
- We take example of a real estate company use case.
- We have John who has a price baseline for vilas, bungalows, tenaments, flats.
- We have dataset which shows various factors, specifications for the house to be selected:

- Now, John has the data of 500 houses in a csv file (based on the boston housing dataset in above table)
- NOTE: Tool to be used for coding - Jupiter notebook OR spider notebook - based on developer's preference.
- John needs to plan the pricing of the houses based on the data of all above variables, so that its profitable for him to sell and also easier for customers also to buy the house.


- Example of Logistic Regression:
- Take an example of a political election being hosted in a country. And we are interested in which candidate will win
- So the outcome variable will result in a binary (either win or loose)
- So Logistic regression is a statistical method for analyzing a dataset in which there are one or more independent variables that determine an outcome. Outcome is a binary class type.
- Decision Tree:
- This is the most used algo in SL.




- So final decision tree look like as follows:

- Random Forest
- Similar to decision tree but much more accurate than it.
- Unsupervised Learning
- As learnt earlier, the training data here is a colllection of information without any label. i.e unlabelled data.
- As seen earlier with fruits example, it distributes the data into different clusters. And if u add new data, it predicts that to which cluster or dataset the data belongs to and accordingly classifies the data.
- So, clustering is the process of dividing the datasets into groups, consisting of similar data points. It means grouping of objects based on the information found in the data, describing the objects or their relationship.
- The purpose of clustering algorithm here is to determine the exact value from the last set of structured and unstructured data.
- Example of clustering - It is used in marketing where long set of data calls are made to customers, retail store where data is classified, insurance companies using to analyze data on high avergage crash claims, banking , etc. Also used by Netflix and Amazon for recommending movies and recommending products into which category ur searched product lies in.
- Types of Clustering:
- Exclusive Clustering (K-Means Clustering) - It is an algorithm whose main goal is to group similar elements of data points into a cluster

- Steps in this algo:

- First we need to decide (assume) the no. of clusters to be made
- Then we provide the centroids of each cluster (central point)
- Then Algorithm calculates Euclidian distance of the points from each centroid and assigns the point to the closest cluster
- Next, the centroids are calculated again, when we have new cluster
- Distance of the points from the centre of clusters are calculated again and points are assigned to the closest cluster
- Then again, the new centroid for the cluster is calculated
- Steps are repeated until we have a repetition in centroids or new centroids are very close to the previous ones.
- Pros & Cons of K-Means clustering
- Pros:
- Simple & understandable
- Items automatically assigned to clusters
- Cons:
- Must define the number of clusters
- All items forced into clusters
- Unable to handle noisy data and outliers
- Overlapping Clustering (Fuzzy C-Means Clustering/Soft Clustering)
- An extension of K-Means clustering
- Here, each data point can belong to more than one cluster (get overlapped).

- Pros:
- Allows a data point to be in multiple clusters
- A more natural representation of the behaviour of genes
- Genes are usually involved in multiple functions
- Cons:
- Need to define C - the number of clusters
- Need to determine the membership cut off value
- Clusters are sensitive to initial assignment of centroids
- Fuzzy-c means algo is not a deterministic algo.
- Hierarchical Clustering
- It's an alternative approach which builds a hierarchy from bottom-up, and doesn't require us to specify the no. of clusters beforehand.

- Pros:
- No assumptions of a particular no of clusters
- May corresponds to meaningful taxonomies
- Cons:
- Once a decision is made to combine 2 clusters, it cannot be undone
- Two slow for large datasets
- Market basket analysis
- Market basket analysis explains the combination of products that frequently co-occur in transactions
- MB analysis has 2 algo:
- Association Rule Mining
- Apiriori
- This technique is used by large retailers to identify the relationships between the items that people buy.Example: People who buy bread, also tend to buy butter. The marketing team at the retail store should target the customers who buy bread to also buy butter, provide them offer so that they buy a 3rd item also like an egg. That is, if customer buys both bread n butter and gets a discount on it, he will be encouraged to buy 3rd item also i.e an egg. This is MB analysis is all about - identifying the association between items and make predictions about what customers will buy. So for that, there are two algo mentioned above:
- Association Rule Mining:- technique which shows how items r associated with each other. Example: Customers who buy bread are 60% likely to buy jam, same for laptop n laptop bag
- Apriori Algo:- Uses frequent item sets to generate association rules
- Reinforcement Learning:
- An agent learns to behave in an envt by performing actions and seeing the results.
- In RL, there is no expected output. The reinforcement agent decides what actions to take in order to perform a given task
- In RL, there is an agent (an RL algo) that learns from trial and error. Second, we have envt i.e the world through which the agent moves (or the obstacles that agent has to conquer) is the envt. Third, we have 'action' - all steps that agent can take. And 4th is the State (S) which is the current condition returned by the envt.
- Also, there are other entities like:
- Reward (R) - An instant return from the envt to appraise the last action
- Policy-approach that the agent uses to determine the next action based on the current state
- Value (V) -expected long term return with discount, as opposed to the short term reward (R)
- Action-Value (Q) - Similar to value (V), except, it takes an extra parameter, the current action (A).
- Algorithms in RL:
- Epsilon Greedy Algo.
- Markov decision process (MDP) - Mathematical approach for mapping a solution in RL is called MDP.
- Q-Learning
