Curriculum
Course: Artificial intelligence (AI) and machine...
Login
Text lesson

Week 3: Self-Study Notes

Study-Friendly Structure

Each section contains:

  • Key Concepts (Simplified theory).
  • Practical Examples (Hands-on coding examples).
  • Exercises (Practice tasks to reinforce learning).

English Version

Unsupervised Learning and Neural Networks


1. Unsupervised Learning

Unsupervised learning identifies patterns in data without labeled outputs.

Key Algorithms:

  • Clustering: Groups similar data points.
    • Example: Customer segmentation.
  • Dimensionality Reduction: Reduces the number of features while retaining essential data.
    • Example: PCA (Principal Component Analysis).

Practical Steps:

  1. K-Means Clustering:

    python
    from sklearn.cluster import KMeans
    import numpy as np
    data = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
    kmeans = KMeans(n_clusters=2, random_state=0).fit(data)
    print("Cluster Centers:", kmeans.cluster_centers_)
    print("Labels:", kmeans.labels_)
  2. PCA for Dimensionality Reduction:

    python
    from sklearn.decomposition import PCA
    import numpy as np
    data = np.array([[2.5, 2.4], [0.5, 0.7], [2.2, 2.9], [1.9, 2.2]])
    pca = PCA(n_components=1)
    reduced_data = pca.fit_transform(data)
    print("Reduced Data:", reduced_data)

Quick Exercise:

  • Perform clustering on a small dataset and visualize the clusters using matplotlib.

2. Neural Networks: Basics

Neural networks are algorithms inspired by the human brain, consisting of layers of interconnected nodes.

Key Concepts:

  • Input Layer: Accepts features of data.
  • Hidden Layers: Performs computations.
  • Output Layer: Generates predictions.

Practical Steps:

  1. Building a Simple Neural Network:
    python
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import Dense
    model = Sequential([
    Dense(10, activation='relu', input_shape=(2,)),
    Dense(1, activation='sigmoid')
    ])
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
    print(model.summary())

Quick Exercise:

  • Create a neural network to classify data into two categories.

3. Feature Engineering

Feature engineering improves data quality to enhance model performance.

Key Techniques:

  • Feature Creation: Deriving new features (e.g., age groups from raw ages).
  • Feature Selection: Choosing the most relevant features for the model.

Practical Steps:

  1. Creating Features:
    python
    import pandas as pd
    data = {'Age': [23, 45, 25], 'Income': [50000, 100000, 75000]}
    df = pd.DataFrame(data)
    df['Age_Group'] = pd.cut(df['Age'], bins=[0, 30, 50], labels=['Young', 'Middle'])
    print(df)

Quick Exercise:

  • Implement feature scaling and create new features for a small dataset.

සිංහල අනුවාදය

අනවෙරෝධී ඉගෙනුම් සහ නියුරල් ජාල


1. අනවෙරෝධී ඉගෙනුම

අනවෙරෝධී ඉගෙනුම යනු ලේබල් නැති දත්තවල රටාව හඳුනාගැනීමයි.

ප්‍රධාන අලගෝරිදම්:

  • Clustering: සමාන දත්ත කුළුණු වලට වෙන් කිරීම.
    • උදාහරණය: පාරිභෝගික වර්ගීකරණය.
  • Dimensionality Reduction: විශේෂාංග සංඛ්‍යාව අඩු කිරීම.
    • උදාහරණය: PCA.

ප්‍රායෝගික පියවර:

  1. K-Means Clustering:
    python
    from sklearn.cluster import KMeans
    import numpy as np
    data = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
    kmeans = KMeans(n_clusters=2, random_state=0).fit(data)
    print("Cluster Centers:", kmeans.cluster_centers_)
    print("Labels:", kmeans.labels_)

දඩුකාරකම:

  • කුඩා දත්ත කුළුණු වලට වෙන් කිරීමේ ක්‍රියාවලිය සිදුකරන්න.

2. නියුරල් ජාල: මූලික අදහස්

නියුරල් ජාලය මනස් ආභාසයෙන් අභ්‍යන්තර කළ මෘදුකාංග වේ.

ප්‍රධාන අදහස්:

  • ආදාන ස්ථරය: දත්ත ආදානය.
  • සැගවුණු ස්ථරය: ගණනයකිරීම්.
  • ප්‍රතිදාන ස්ථරය: ප්‍රතිඵල අනාවැකිය.

ප්‍රායෝගික පියවර:

  1. සරල නියුරල් ජාලයක් සාදන්න:
    python
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import Dense
    model = Sequential([
    Dense(10, activation='relu', input_shape=(2,)),
    Dense(1, activation='sigmoid')
    ])
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
    print(model.summary())

දඩුකාරකම:

  • ද්විත්ව කාණ්ඩ සඳහා නියුරල් ජාලයක් පුහුණු කරන්න.

3. විශේෂාංග ඉංජිනේරුකරණය

විශේෂාංග ඉංජිනේරුකරණය ආදර්ශ කාර්ය සාධනය වැඩිදියුණු කිරීමට උපකාරී වේ.

ප්‍රධාන කාර්යමණ්ඩල:

  • විශේෂාංග නිර්මාණය: නව විශේෂාංග සාදීම.
  • විශේෂාංග තේරීම: විශේෂාංග මැනවින් තේරීම.

ප්‍රායෝගික පියවර:

  1. විශේෂාංග සාදන්න:
    python
    import pandas as pd
    data = {'Age': [23, 45, 25], 'Income': [50000, 100000, 75000]}
    df = pd.DataFrame(data)
    df['Age_Group'] = pd.cut(df['Age'], bins=[0, 30, 50], labels=['Young', 'Middle'])
    print(df)

දඩුකාරකම:

  • දත්ත සක්‍රීය කිරීමේ කුඩා උදාහරණයක් සාදන්න.