# Ml & Dl

* The term **artificial intelligence** describes computer systems that can apply reasoning to subjects that previously required human intelligence.
    
* **Machine learning** can enable systems to **predict** and **classify** given data in response to ever-changing data, somewhat like the way you learn from experience.
    
* **Deep learning** is a group of extremely powerful types of machine learning, many of which are inspired by the operation of **neural networks** in the human brain.
    
    ### **Supervised Learning**
    
* These AI systems do not have common sense or world knowledge, nor do they have a sense of self (at least, not yet). But they do acquire knowledge and understanding through experience—a process called **cognition**—accomplishing results that resemble human thinking. They do this primarily by using complex rules called **algorithms** that help them analyze data.
    
* The machine will never give this result with absolute confidence. Instead, the system will give a **confidence value** to indicate, for example, that it might predict with 85% certainty that its answer is correct. The more data the system ingests, the higher its accuracy will be.
    
* Supervised learning requires that an AI system ingest structured data.
    
    ### Unsupervised learning
    
* In contrast to supervised learning, **unsupervised learning** trains a machine with **unlabeled** data, such as the text of a book. Training an AI system with unlabeled data is more difficult because the system can’t make predictions until it has structured the data itself. In the book example, structuring the data would involve breaking down the text and finding relationships between words and sentences. So, algorithms explore the data and try to find structure.
    
    ### Reinforcement learning
    
* With **reinforcement learning**, a machine is not given specific information to ingest. Instead, it learns through trial and error. The machine’s algorithms are rewarded when it performs a correct action and penalized when it doesn’t.
    
* Unsupervised learning and reinforcement learning require a system to develop its own structure either by analyzing large amounts of data (unsupervised learning) or by trial-and-error (reinforcement learning).
    
    # Classical machine learning
    
    \*There are two different technologies by which machine learning takes place: **classical machine learning** and members of a group of technologies called the **deep learning ecosystem**.
    
* **Classical machine learning** began in the 1950s. AI systems **learned** by ingesting data and getting better at recognizing patterns. The AI systems could predict things like the distance between points or the intensity of values.
    
* Classical machine learning uses a small number of algorithms in a relatively simple arrangement. Sometimes machine learning algorithms are **binary**, which means that they output one of only two values. Typical binary results might be a 1 or a 0, a YES or a NO, and a TRUE or a FALSE.
    
* Here are three typical algorithms that are used in classical computing:
    
    * Decision tree
        
    * Linear regression
        
    * Logistic regression
        
        # Decision tree
        
    * A **decision tree** is a supervised learning algorithm. It operates like a flowchart. You can think of a flowchart as an upside-down decision tree. The flowchart has a **root node** (where the flowchart begins), branches that connect to **internal nodes**, and more branches that connect to **leaf nodes**.
        
        # Linear regression
        
    * **Linear regression** is another type of algorithm. It relates to data that might be graphed as a straight line. For example, a business might believe that more advertising spending leads to better sales. This could be graphed as a series of dots that form a rising straight line, as depicted here.
        
    * The situation is more complicated if a company’s actual sales show different data for different products, at different locations, on different dates, and so on. With a large number of variables and instances, the graph becomes a mass of dots that don’t arrange into a straight line at all. Without adjustment, resulting graph is too general to help a business make a good decision. That’s where linear regression can help. Linear regression can learn all the variables, then calculate a reasonably accurate prediction of how advertising will impact sales at some time and location in the future. In effect, linear regression resolves the mass of dots into a “most likely” line that can be used for simple prediction.
        
        # Logistic regression
        
    * In some situations, a relationship does not fall in a straight line. Sometimes a system uses values that require a specific, limited kind of outcome, such as something between 0 and 1 (or NO and YES). In this situation, a graph can form what’s called a **sigmoid function,** or an S-shaped curve.
        
    * For any set of variables, the outcome (which is a point on the S-curve) falls between 0 and 1.
        
    * An exam passed or failed is binary (YES or NO) so relating it to hours studied would use logistic regression. More AP classes passed leading to more college acceptances would use linear regression. Deciding a major would use a decision tree based on professors' names and personal interest.
        
        # Classical machine learning is not obsolete
        
    * Classical machine learning can be outperformed, at some tasks, by newer methods that are part of the deep learning ecosystem. But there are still reasons to use classical machine learning. These include:
        
        * **Work with structured data**
            
            Classical machine learning is used mostly with structured data from databases, such as hours studied compared to grades earned.
            
        * **Lower expense to operate**
            
            Classical machine learning requires less computing power than deep learning ecosystems. They can run on less expensive computers with less powerful processors, which lowers the price for smaller businesses, communities, or healthcare systems that share time on them in pay-as-you-go arrangements.
            
        * **Easier to interpret**
            
            Deep networks are so complex that even AI researchers don’t entirely understand what’s going on inside. As a result, AI researchers are not always able to determine when deep network systems are producing invalid outputs. Compared to these mysteries, classical results can be easier to debug, and to test for accuracy and lack of bias.
            
            # **The deep learning ecosystem**
            
        * Today, machine learning has evolved into a collection of powerful applications called the **deep learning ecosystem**. The foundation for many applications is called a **neural network**. A neural network uses electronic circuitry inspired by the way neurons communicate in the human brain.
            
        * In the brain, cells called neurons have a cell body at one end where the nucleus resides, and a long axon leading to a set of branching terminals at the other end. Neurons communicate to each other by receiving signals into the axon, altering those signals, then transmitting them out through the terminals to other neurons. Researchers estimate that a human brain has about 100 billion neurons, each one connected to up to 10,000 other neurons.
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941050803/6776ea19-c8d4-422d-bcbe-0fcfb88b94de.png align="center")
            
        * In a neural network, a building block, called a **perceptron**, acts as the equivalent of a single neuron. A perceptron has an **input** layer, one or more **hidden layers**, and an **output** layer. A signal enters the input layer and the hidden layers run algorithms on the signal. Then, the result is passed to the output layer.
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941064420/4100c1b1-ca28-40fd-b919-9ee6e338707b.png align="center")
            
            ## Comparison of a neuron and a perceptron
            
        * ### **Biological Input**
            
        * ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941165558/7aa4033d-31b6-4dc8-99dc-876715f41dba.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941184922/5683e226-1433-4abf-bbed-7437e094a966.png align="center")
            
            ### **Biological Input and response**
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941235883/e3056b5e-3436-42cc-96c5-a373882f4fbe.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941290440/a919a4c9-c0bd-4b49-96d3-2afbe907da4c.png align="center")
            
            ### **Neural network input and response**
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941336414/4a4d493d-04d1-4bf8-bac2-0b85da0cbc05.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699941357984/0aa56c6f-de8f-4536-aafc-fde4be32a37f.png align="center")
            
        * The hidden layers in a neural network resemble, as a group, the long cell body that connects dendrites to axons within a human brain cell. Those hidden layers contain **nodes**. Each node runs an algorithm and bits of additional code to test and adjust its result. When the value reaches a certain threshold, the node “fires”.
            
        * **Note**: A node often uses a sigmoid function to determine whether or not to “fire”. As explained previously, a sigmoid function can generate a binary answer, such as, YES or NO. The binary answer tells the node whether or not to fire. You can think of the threshold as a hurdle a solution must jump over to give a result of YES.
            
        * If there are other nodes connected to the node, they are activated when the signal reaches them. If the other nodes reach their own thresholds, then they fire. The signal cascades down through the hidden layers in a way that’s somewhat similar to how a signal passes down the body of a human brain cell.
            
        * Keep in mind that these resemblances are only similarities. Neural networks are inspired by the human brain, but the activities inside neural networks are quite different.
            
            # Machine learning is often trial and error
            
        * by continuously adjusting itself, in a process that humans refer to as **trial and error**.
            
        * Once a neural network has ingested or already learned a certain amount of data, it stores the data in its “body of information”, called its **corpus**.
            
        * In many modern applications of AI, the unstructured data involved is complex enough to overwhelm even a simple perceptron, such as to decide whether to order pizza in a previous lesson. So, a perceptron requires more **brainpower** in the form of **deep learning**. Deep learning relies on multiple layers of nodes (even multiple groups of perceptrons with multiple layers of nodes!) to finish the work in reasonable time.
            
            # From perceptrons to deep learning
            
        * Advanced AI systems use many hidden layers whose algorithms pass the results of sophisticated calculations. This is a **deep neural network (DNN)**. DNN layers can be arranged in groups or elaborate blocks of groups for greater power. DNNs can even be doubled in competing teams that judge and learn from each other’s mistakes, without human intervention. This creates powerful reinforcement learning.
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699942441748/0559b01f-6139-4c47-bc12-8a2995e55cb7.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699942559858/8d071329-0d88-4c5d-84d4-2572b31ed0eb.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699942573535/d1367446-b5c5-4db3-9501-689ea4c52463.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1699942588758/9e6e48a3-a3aa-418e-8362-db7d28677e92.png align="center")
            
        
        ### **Generative AI**
        
    * **Generative AI** is a type of artificial intelligence that creates new, original content that people have never seen before.
        
    * Generative artificial intelligence (AI) is a powerful and exciting type of AI that generates new, original content, such as images, music, videos, data, code, responses to questions, and a whole lot more.
        
    * Generative AI’s output has gained global attention due to the uniqueness, high quality, and speed of content generation.
        
    * Generative AI is a revolutionary change that’s as radical to global humanity as the invention of electricity and automobiles.
        
    * It’s a technology that is revolutionizing the way people live, work, and enjoy their leisure time.
        
        * Most AI systems are discriminative AI models, which predict and classify data.
            
        * In contrast, generative AI models are a type of deep learning AI system that uses algorithms to generate content based on a submitted prompt, thus the name of generative AI.
            
    
    # Generative AI process
    
* First, a person feeds the AI a large amount of data. This could be anything from images and sounds to text and numbers.
    
* Then, the AI analyzes this data, looking for patterns and relationships between the different pieces of information. The neural network is trained on a dataset of examples of the type of output it is intended to generate, such as images or text. During the training process, the neural network learns to identify patterns and relationships in the input data and use them to generate new outputs that are similar to, but not identical to, the examples it was trained on.
    
* Next, the AI uses what it has learned to create something new. The neural network generates new outputs by inputting a random seed value. The seed value serves as the starting point for the generation process. The neural network processes the seed value and generates a new output that is based on the patterns and relationships it learned during training. For example, if someone gave the AI a set of images of dogs, it might use its knowledge of different dog breeds to create an image of a new dog that doesn't exist in real life.
    
    ### **Types of generative AI models**
    
    Let’s explore the three primary types of generative AI models:
    
    * **Variational autoencoder (VAE)**
        
        Think of **variational autoencoder (VAE)** models as a skilled artist who can look at a painting, quickly sketch a simplified version of it, and then recreate a new painting using only that simplified sketch as a reference. The artist is capturing the essential elements of the painting and then using them to create a new work of art.
        
        VAEs use a similar process. The "**encoder**" network compresses the input data into a lower-dimensional representation and the "**decoder**" network reconstructs the original data from this compressed representation. This allows VAEs to capture the underlying structure and patterns in the data, which can then generate new, similar data.
        
    * **Generative adversarial network (GAN)**
        
        Think of a **generative adversarial network (GAN)** model as a competition between a skilled forger (the generator) and a talented art critic (the discriminator). The forger creates fake paintings, while the critic tries to determine whether each painting is genuine or a forgery. As the forger improves their technique, the critic becomes more discerning, and this cycle continues until the forger can create near-perfect forgeries.
        
        In GANs, the generator creates new data, while the discriminator evaluates the quality of the generated data. The generator tries to create data that is realistic enough to fool the discriminator, while the discriminator learns to better distinguish between real and generated data. This competition leads to the generator creating increasingly realistic content.
        
    * **Autoregressive**
        
        Imagine an **autoregressive** model as a skilled storyteller who listens to the beginning of a story and then continues it by predicting what comes next based on the words and events that have occurred so far. The storyteller uses their knowledge of language, grammar, and storytelling conventions to create a coherent and engaging continuation of the story.
        
        Autoregressive models generate new content by predicting the next element in a sequence based on the previous elements. They are particularly well-suited for generating text because they can model the conditional probabilities of words and characters in a sentence.
        
        # Examples of generative AI applications
        
* **CHATGPT**
    
    OpenAI launched ChatGPT, an AI chatbot, in November 2022. Able to interact by using conversational natural language, this AI tool goes beyond the traditional search engine responses of simply listing related results. Instead, ChatGPT follows instructions given in the prompt and provides a detailed response. For example, with ChatGPT, a person can enter a text prompt of “Write a poem about cats” and the result will be a poem about cats, rather than a listing of websites about cats.
    
* **IBM Watson Discovery**
    
    IBM Watson Discovery uses foundational technologies, such as large language models (LLMs), to obtain insights from what it is that we don’t know that we don’t know. It’s used widely in genomic research discovering what amino acids might lurk inside the protein not known before and unearth the relationship of various actors or entities for government security related questions.
    
* **DALL-E and DALL-E2**
    
    Developed by OpenAI, these are generative AI models that use natural language text input to generate digital images. The first version of DALL-E could only render AI-created images in a cartoonish fashion, but the latest version can produce much more realistic images due to improved image processing algorithms.
    
* **BARD**
    
    Bard is a generative AI tool that Google launched in an initial, limited capacity in March 2023. Bard is founded on Google’s Bidirectional Encoder Representations from Transformers (BERT) model. It isn’t generative AI; rather, Google developed it for natural language processing (NLP), especially for its capacity to interpret the nuances of a user’s search words. Bard builds on BERT’s capability of natural language interactions with Bard’s generative AI capability to generate new content. For example, musicians can use Bard to compose music and lyrics.
    
    # Limitations of generative AI
    
* **Lack of originality:** Generative AI models rely on large datasets to learn and generate content. As a result, they might not create entirely original content but rather mimic patterns from their training data, which can lead to a lack of creativity and innovation.
    
* **Incompleteness:** While generative AI models are becoming increasingly sophisticated, they still struggle to understand the nuanced contexts and might generate incomplete or nonsensical content.
    
* **Bias:** Generative AI models can perpetuate existing biases present in their training data, leading to the generation of biased content that might reinforce stereotypes and discriminatory behavior.
    
* **Computational resources:** Training and deploying generative AI models require significant computational power, which can be expensive and contribute to environmental concerns such as energy consumption and carbon emissions.
    
    # **Ethical concerns of generative AI**
    
* **Misinformation and fake content:** Generative AI can create convincing fake content, like **deepfakes** or falsified news articles, which can lead to the spread of misinformation and have severe consequences for individuals and societies.
    
* **Intellectual property and copyright:** Generative AI can produce content that resembles copyrighted material. This raises questions about intellectual property rights and potential infringements.
    
* **Privacy:** Generative AI can create realistic images and text about individuals, potentially violating their privacy and causing harm to their reputation.
    
* **Loss of human touch:** As generative AI becomes more prevalent, there is a risk that the human touch will be lost in various creative domains, potentially leading to a decline in the appreciation of human-created art and culture.
    
* **Unemployment and job displacement:** The rise of generative AI might lead to job displacement in creative industries, as machines take over tasks previously performed by humans.
    
    # **AI trends in future**
    

### Deeper Insights

* New technologies will be able to sense and analyze things at a level of understanding that was never before possible. This includes future-forward technologies with unfamiliar names, like quantum computing. Quantum computing is a dramatically different way to calculate, based on the behavior of subatomic particles.
    
    **Technologies:**
    
    * Quantum computing
        
    * Distributed deep learning
        
    * Neuromorphic systems
        
    * Homomorphic encryption
        
    * Machine foresight
        
    * Cognitive discovery
        
        ### **Engagement Reimagined**
        
    * New forms of human-machine communication, based on blockchain, conversational bots, and more ideas, will transform how you interact not only with your friends, family members, and coworkers, but also with machines that listen and engage in complex conversations.
        
        **Interactions:**
        
        * Human-machine collaboration
            
        * New AI modalities
            
        * Augmented reality
            
        * Global trade logistics
            
        * Blockchain for payments
            
            ### **Personalization on at Scale**
            
        * Machines will interact with you in ways tailored to your particular desires, habits, and level of comfort. Today, websites already offer merchandise based on orders you’ve made in the past. Soon, you’ll use sites that recognize you and know and understand the things you love. This includes the fashions you follow. Future sites will discuss your fashion preferences with you and offer them perfectly fitted to your size and needs.
            
            **Ways to personalize:**
            
            * Personalized healthcare
                
            * Micro-segmentation
                
            * Personalized finance
                
            * Targeted marketing
                
            * Personalized learning
                
            * Individualized solutions
                
            
            ### **Instrumented Planet**
            
        * Billions of sensors generating exabytes of data every day will improve the safety, sustainability, and security of our planet. You won’t get caught in a surprise storm. You will enjoy food from crops grown in new ways that provide maximum taste and nutrition, with minimum damage to the environment.
            
            **Connections:**
            
            * Environmental solutions
                
            * Digital agriculture
                
            * Connected cars
                
            * Geospatial temporal data and analytics
                
            * Smart sensors
                
                # Key points to remember
                
            * Using advanced mathematics, machines can learn either in classical ways or with neural networks.
                
            * Machines can learn from structured or unstructured data and teach themselves through trial-and-error.
                
            * Machine learning tools include logic methods, such as decision trees, linear regression, and logistic regression.
                
            * Neural networks, inspired by the human brain, build perceptrons with layers of algorithm nodes to perform complex calculations.
                
            * Multiple groups of multilayer perceptrons, arranged in different ways, extend machine learning in the deep learning ecosystem.
                
            * Today, people carry on simple conversations with machine learning AI systems using what is known as Broad AI.
                
            * Generative AI has gained attention worldwide as a revolutionary change for creating new and unique content.
                
            * In the future, General AI systems will perform unprecedented levels of analysis to help humans improve life on a global scale.
                
                ##   
                Q & A
                
                1. Henry-**reinforcement Learning**
                    
                2. What is the minimum number of hidden layers in a deep learning system?-**1**
                    
                3. Which of the following is an advantage of classical machine learning compared to deep learning?-**Classical machine learning works well with unstructured data.**
                    
                4. AI systems use complex rules called \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ to help them analyze data.-**algorithms**
                    
                5. A research team has reviewed hundreds of photos, tagging them as either **pet** or **not pet**.
                    
                
                What kind of machine learning are they preparing for?-**Supervised learning**
                
                1. Where does a perceptron’s input layer send its signal?-**To one or more nodes in a hidden layer**
                    
                2. \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ which "fire", or activates a signal, when a tested value reaches the threshold.-**nodes**
                    
                3. Every hour, your oven temperature increases by twice the number of degrees of the previous hour.
                    
                
                What kind of regression are you seeing?-**Linear regression**
                
                1. Machine learning is a subset of what technology?-**Artificial intelligence**
                    
                2. You’re writing a science ﬁction story in which the main character is travelling from Earth to the Andromeda galaxy. The main character uses the ship’s AI system to think just like a human to keep the ship safe throughout the voyage.  
                    What future machine learning trend does this system represent?-**Narrow AI**
                    
                3. You work for a government that wants to set up an AI system. It should make predictions that can help the government allocate water to farmers during droughts. Such predictions depend on constantly changing factors such as rainfall, humidity, mountain runoff, and crop maturity.
                    
                
                What form of machine learning could you recommend?-
                
                **Deep neural network learning**
                
                1. Street map-Decision tree
                    
                2. A \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ is a perception region that's loosely equivalent to the "decision-making" body of a nerve cell.-**hidden layer**
                    
                3. Which of the following is a distinguishing feature of generative AI?-**It creates new, unique content.**
                    
                4. Which of the following models does generative AI use to produce content?
                    
                
                Select all that apply.
                
                * **Generative adversarial networks (GANs)**
                    
                * **Autoregressive models**
                    
                * **Variational autoencoders (VAEs)**
