40 Basic AI Tutorials

40 Basic AI Tutorials

1. What is AI?

Artificial Intelligence (AI) enables machines to mimic human intelligence.

Example: AI in daily life.

print("AI powers virtual assistants like Siri.")

AI powers virtual assistants like Siri.

Note: AI includes tasks like learning, reasoning, and problem-solving.

2. Types of AI

AI is categorized into narrow, general, and super AI.

Example: Narrow AI example.

print("Narrow AI: Image recognition in apps.")

Narrow AI: Image recognition in apps.

Note: Narrow AI is task-specific, like voice assistants.

3. Machine Learning Basics

Machine Learning (ML) is a subset of AI where systems learn from data.

Example: Simple ML prediction.

from sklearn.linear_model import LinearRegression
model = LinearRegression()
print("ML predicts outcomes from data.")

ML predicts outcomes from data.

Note: ML uses algorithms to find patterns in data.

4. Supervised Learning

Supervised learning uses labeled data to train models.

Example: Predicting house prices.

from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit([[1000], [2000]], [100000, 200000])
print(model.predict([[1500]]))

[150000]

Note: Supervised learning requires input-output pairs.

5. Unsupervised Learning

Unsupervised learning finds patterns in unlabeled data.

Example: Clustering customers.

from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=2)
print("Clusters data without labels.")

Clusters data without labels.

Note: Common for clustering and dimensionality reduction.

6. Neural Networks Intro

Neural networks mimic the human brain to process data.

Example: Simple neural network structure.

from tensorflow.keras.models import Sequential
model = Sequential()
print("Neural network with layers.")

Neural network with layers.

Note: Neural networks are used for complex tasks like image recognition.

7. AI in Everyday Life

AI powers tools like recommendation systems and chatbots.

Example: AI recommendation.

print("Netflix suggests movies using AI.")

Netflix suggests movies using AI.

Note: AI enhances user experience in apps.

8. Python for AI

Python is a popular language for AI development.

Example: Basic Python script.

print("Hello, AI with Python!")

Hello, AI with Python!

Note: Python is easy to learn and widely used in AI.

9. Data Preprocessing

Data preprocessing prepares raw data for AI models.

Example: Normalizing data.

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
data = scaler.fit_transform([[1], [2], [3]])
print(data)

[[-1.22474487], [0.], [1.22474487]]

Note: Clean data improves model accuracy.

10. AI Datasets

AI datasets provide data for training models.

Example: Loading a dataset.

from sklearn.datasets import load_iris
iris = load_iris()
print(iris.data)

(Iris dataset for AI training.)

Note: Use datasets like Iris or MNIST for practice.

11. Linear Regression

Linear regression predicts numerical outcomes using a linear model.

Example: Simple linear regression.

from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit([[1], [2]], [10, 20])
print(model.predict([[3]]))

[30]

Note: Linear regression is great for simple predictions.

12. Logistic Regression

Logistic regression predicts categorical outcomes.

Example: Binary classification.

from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit([[1], [2]], [0, 1])
print(model.predict([[1.5]]))

[0]

Note: Used for binary or multi-class problems.

13. Decision Trees

Decision trees split data to make decisions.

Example: Simple decision tree.

from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier()
model.fit([[1, 2], [3, 4]], [0, 1])
print(model.predict([[2, 3]]))

[0]

Note: Decision trees are interpretable and versatile.

14. Clustering Basics

Clustering groups similar data points without labels.

Example: K-means clustering.

from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=2)
kmeans.fit([[1, 2], [3, 4], [5, 6]])
print(kmeans.labels_)

[0 1 1]

Note: K-means is a common clustering algorithm.

15. AI Libraries

AI libraries simplify machine learning development.

Example: Importing scikit-learn.

from sklearn import datasets
print("Scikit-learn provides AI tools.")

Scikit-learn provides AI tools.

Note: Popular libraries include TensorFlow and PyTorch.

16. NumPy for AI

NumPy handles numerical operations for AI.

Example: Array operations.

import numpy as np
array = np.array([1, 2, 3])
print(array * 2)

[2 4 6]

Note: NumPy is essential for matrix operations.

17. Pandas Basics

Pandas manages dataframes for AI data analysis.

Example: Creating a dataframe.

import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
print(df)

A
01
12
23

Note: Pandas is great for data manipulation.

18. Data Visualization

Data visualization displays AI data insights.

Example: Simple plot.

import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()

(Line plot of data points.)

Note: Use Matplotlib or Seaborn for visualization.

19. Overfitting Explained

Overfitting occurs when a model learns noise in training data.

Example: Overfit model.

from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier(max_depth=10)
print("Deep tree may overfit.")

Deep tree may overfit.

Note: Use validation data to detect overfitting.

20. Model Evaluation

Model evaluation measures AI model performance.

Example: Accuracy score.

from sklearn.metrics import accuracy_score
print(accuracy_score([1, 0], [1, 1]))

0.5

Note: Use metrics like accuracy or F1-score.

21. AI Ethics

AI ethics ensures responsible AI development.

Example: Ethical AI principle.

print("AI should be fair and transparent.")

AI should be fair and transparent.

Note: Consider bias and privacy in AI projects.

22. AI Bias

AI bias occurs when models produce unfair outcomes.

Example: Bias in data.

print("Biased data leads to unfair AI.")

Biased data leads to unfair AI.

Note: Use diverse datasets to reduce bias.

23. Feature Engineering

Feature engineering creates meaningful input variables for AI models.

Example: Creating a feature.

import pandas as pd
df = pd.DataFrame({'age': [25, 30]})
df['age_squared'] = df['age'] ** 2
print(df)

ageage_squared
025625
130900

Note: Good features improve model performance.

24. AI Workflows

AI workflows outline steps from data collection to model deployment.

Example: Simple workflow.

print("Collect data -> Train model -> Deploy")

Collect data -> Train model -> Deploy

Note: Plan workflows to streamline AI projects.

25. Training vs Testing

Training data trains models; testing data evaluates them.

Example: Train-test split.

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split([[1], [2]], [0, 1], test_size=0.2)
print(X_train)

[[1]]

Note: Use 80/20 split for training and testing.

26. AI Terminology

AI terminology includes key terms like algorithm and dataset.

Example: Common terms.

print("Algorithm: A set of rules for AI.")

Algorithm: A set of rules for AI.

Note: Learn terms to understand AI concepts.

27. Simple Neural Network

A simple neural network processes inputs through layers.

Example: Neural network setup.

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential([Dense(1, input_dim=1)])
print("Simple neural network created.")

Simple neural network created.

Note: Start with small networks for learning.

28. Activation Functions

Activation functions determine neuron outputs in neural networks.

Example: ReLU function.

from tensorflow.keras.layers import Dense
model = Dense(1, activation='relu')
print("ReLU activation used.")

ReLU activation used.

Note: ReLU is common for hidden layers.

29. Gradient Descent

Gradient descent optimizes model parameters by minimizing loss.

Example: Simple gradient descent.

from tensorflow.keras.optimizers import SGD
optimizer = SGD(learning_rate=0.01)
print("Gradient descent optimizer.")

Gradient descent optimizer.

Note: Adjust learning rate for better results.

30. Loss Functions

Loss functions measure model prediction errors.

Example: Mean squared error.

from tensorflow.keras.losses import MeanSquaredError
loss = MeanSquaredError()
print("Loss function for regression.")

Loss function for regression.

Note: Choose loss based on task type.

31. AI Tools Setup

Setting up AI tools prepares your environment for development.

Example: Installing TensorFlow.

!pip install tensorflow
print("TensorFlow installed.")

TensorFlow installed.

Note: Use pip or conda for library installation.

32. Basic Chatbots

Basic chatbots use AI to interact with users.

Example: Simple chatbot response.

def chatbot_response(user_input):
return "Hello, how can I help you?"
print(chatbot_response("Hi"))

Hello, how can I help you?

Note: Start with rule-based chatbots.

33. Natural Language Processing

NLP enables machines to understand human language.

Example: Tokenizing text.

from nltk.tokenize import word_tokenize
print(word_tokenize("AI is amazing"))

['AI', 'is', 'amazing']

Note: Use NLTK or spaCy for NLP tasks.

34. Image Recognition Basics

Image recognition identifies objects in images using AI.

Example: Simple image classification.

from tensorflow.keras.models import Sequential
model = Sequential()
print("Model for image recognition.")

Model for image recognition.

Note: Use CNNs for image tasks.

35. AI Model Deployment

Model deployment makes AI models accessible for use.

Example: Saving a model.

from tensorflow.keras.models import Sequential
model = Sequential()
model.save('model.h5')
print("Model saved.")

Model saved.

Note: Use Flask or FastAPI for deployment.

36. TensorFlow Basics

TensorFlow is a library for building AI models.

Example: TensorFlow model.

from tensorflow.keras.models import Sequential
model = Sequential()
print("TensorFlow model created.")

TensorFlow model created.

Note: TensorFlow is widely used for deep learning.

37. PyTorch Basics

PyTorch is a flexible library for AI development.

Example: PyTorch tensor.

import torch
tensor = torch.tensor([1, 2, 3])
print(tensor)

tensor([1, 2, 3])

Note: PyTorch is great for research and prototyping.

38. AI in Business

AI improves business processes like customer service.

Example: AI in business.

print("AI chatbots improve customer support.")

AI chatbots improve customer support.

Note: AI drives efficiency in industries.

39. AI Project Workflow

AI project workflows guide development from start to finish.

Example: Project steps.

print("Plan -> Code -> Test -> Deploy")

Plan -> Code -> Test -> Deploy

Note: Follow workflows for organized projects.

40. Getting Started with AI

Getting started with AI involves learning basics and tools.

Example: First AI script.

print("Welcome to AI learning!")

Welcome to AI learning!

Note: Start with Python and simple datasets.

Macro Nepal Helper