Session 1: Introduction to Machine Learning

with practical examples using Python and Jupyter Notebook. The session focuses on understanding machine learning, key concepts, and tools, supported by simple code snippets and visualizations.

Jupyter Notebok

Session 1: Introduction to Machine Learning

1. What is Machine Learning?

Machine Learning (ML) is the science of enabling machines to learn patterns from data and make decisions without being explicitly programmed.


2. Types of Machine Learning


3. Key ML Concepts


4. Tools and Frameworks


Practical Examples

Step 1: Data Loading and Exploration

# Import libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Example dataset: House prices
data = {
    "Size (sq ft)": [750, 800, 1200, 1500, 1800],
    "Price ($)": [150000, 160000, 240000, 300000, 360000],
}

df = pd.DataFrame(data)

# Display the data
print(df)

# Visualize the data
sns.scatterplot(data=df, x="Size (sq ft)", y="Price ($)")
plt.title("House Prices vs. Size")
plt.show()

Step 2: Linear Regression Example

from sklearn.linear_model import LinearRegression
import numpy as np

# Prepare data for the model
X = df[["Size (sq ft)"]].values  # Features
y = df["Price ($)"].values       # Target

# Train a simple linear regression model
model = LinearRegression()
model.fit(X, y)

# Predict prices for new data
new_sizes = np.array([[1000], [2000]])
predicted_prices = model.predict(new_sizes)

# Visualization
plt.scatter(df["Size (sq ft)"], df["Price ($)"], label="Original Data")
plt.plot(new_sizes, predicted_prices, color="red", label="Prediction")
plt.xlabel("Size (sq ft)")
plt.ylabel("Price ($)")
plt.title("Linear Regression: House Prices vs. Size")
plt.legend()
plt.show()

Step 3: Model Evaluation

# Model coefficients
print(f"Intercept: {model.intercept_}")
print(f"Coefficient: {model.coef_[0]}")

# Predict values for the training data
y_pred = model.predict(X)

# Plot actual vs predicted
plt.scatter(y, y_pred)
plt.xlabel("Actual Prices ($)")
plt.ylabel("Predicted Prices ($)")
plt.title("Actual vs Predicted Prices")
plt.show()

Step 4: Feature Scaling Show how scaling affects ML models using standardization.

from sklearn.preprocessing import StandardScaler

# Scaling features
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Train again with scaled features
model_scaled = LinearRegression()
model_scaled.fit(X_scaled, y)

# Visualization
plt.scatter(X_scaled, y, label="Scaled Data")
plt.plot(X_scaled, model_scaled.predict(X_scaled), color="red", label="Scaled Model")
plt.xlabel("Scaled Size (sq ft)")
plt.ylabel("Price ($)")
plt.legend()
plt.show()

Key Takeaways - Understand Data: Data exploration and visualization are crucial for ML success. - Learn from Patterns: Models like Linear Regression use patterns in the data to make predictions. - Use Tools Effectively: Python libraries like pandas, matplotlib, and scikit-learn simplify ML implementation.


The session includes simple visualizations (scatter plots, regression lines) and focuses on building intuition with relatable examples like predicting house prices.


Contact https://www.schogini.com 1 to 1 coaching and consultations