Machine Learning Project using NumPy in Google Colab
Project Overview
Project Title: Predict Student Pass/Fail Using Rule-Based Model
This project demonstrates how to use NumPy for a basic machine learning-like task in Google Colab.
The goal is to predict whether a student passes or fails based on their average marks in subjects.
This is done without any ML libraries-only using NumPy.
Steps covered in this project:
1. Import NumPy
2. Create a dataset using NumPy arrays
3. Calculate average marks
4. Use a rule to classify Pass/Fail
5. Make predictions and calculate accuracy
Complete Python Code
# Step 1: Import Libraries
import numpy as np
# Step 2: Create a Dataset
# Simulate dataset: rows = students, columns = [Maths, Science, English]
marks = np.array([
[65, 70, 72],
[45, 50, 40],
[90, 88, 95],
[30, 25, 40],
[55, 60, 58],
[80, 85, 82]
])
Machine Learning Project using NumPy in Google Colab
# Print dataset
print("Marks of students:\n", marks)
# Step 3: Define the Passing Rule
# Define passing rule: average >= 50
average_marks = np.mean(marks, axis=1)
print("\nAverage Marks:", average_marks)
# Rule-based label generation
# If avg >= 50, Pass (1), else Fail (0)
pass_fail = np.where(average_marks >= 50, 1, 0)
print("Pass/Fail Labels:", pass_fail)
# Step 4: Analyze Accuracy (Optional Manual Prediction)
# Example model prediction using a new rule: pass if Maths >= 50
predictions = np.where(marks[:, 0] >= 50, 1, 0)
# Check accuracy
accuracy = np.mean(predictions == pass_fail) * 100
print("Prediction Accuracy: ", accuracy, "%")