The Adaptive Courses API is a Flask-based backend designed to provide personalized course recommendations and dropout risk analysis for students in an online learning platform. Built with Python, it leverages machine learning (Random Forest classifier) and collaborative filtering to tailor recommendations based on student profiles, learning styles, and peer performance. The API supports five main endpoints: /api/students/<id>, /api/recommendations/<id>, /api/courses, /api/health, and /api/analysis, with Swagger documentation via Flask-RESTX.
- Features
- Project Structure
- Dataset
- Algorithms and AI Classifier
- Setup and Installation
- Usage
- How to Use the API
- Dependencies
- Research Perspectives
- Future Improvements
- Contributing
- License
- Dropout Risk Prediction: Uses a Random Forest classifier to predict dropout likelihood based on student features.
- Personalized Recommendations: Combines content-based filtering (learning style match) and collaborative filtering (similar student success) with a dropout risk adjustment.
- Analytics Dashboard Support: Provides aggregated statistics for visualizing dropout risk, engagement, and course performance.
- Scalable Design: Modular structure with separate services for data management, preprocessing, and recommendations.
- Swagger Documentation: Interactive API explorer via Flask-RESTX at
/swagger-ui.
Adaptative-courses/
├── personalized_learning_dataset.csv # Dataset with student data
├── recommender/ # Core application code
│ ├── __init__.py
│ ├── api/ # Flask API layer
│ │ └── app.py
│ ├── algorithms/ # Recommendation and similarity algorithms
│ │ ├── recommender.py
│ │ └── similarity.py
│ ├── ai/ # AI components (classifier and preprocessor)
│ │ ├── classifier.py
│ │ └── preprocessor.py
│ ├── core/ # Core models and services
│ │ ├── models.py
│ │ └── services.py
│ └── data/ # Data management
│ └── manager.py
├── README.md # This file
└── requirements.txt # Python dependencies
The API uses personalized_learning_dataset.csv, a synthetic dataset with 10,000 student records. Each row represents a student’s interaction with a course.
- Student_ID: Unique identifier (e.g.,
S00001). - Age: Integer (18-40 range).
- Gender:
Male,Female, orOther. - Education_Level:
High School,Bachelor's,Master's, orPhD. - Learning_Style:
Visual,Auditory,Reading/Writing, orKinesthetic. - Course_Name: One of
Python Basics,Web Development,Data Science,Machine Learning, orCybersecurity. - Time_Spent_on_Videos: Float (hours spent on video content).
- Quiz_Scores: Float (average quiz score, 0-100).
- Quiz_Attempts: Integer (number of quiz attempts).
- Forum_Participation: Float (participation score, 0-100).
- Assignment_Completion_Rate: Float (percentage, 0-100).
- Final_Exam_Score: Float (final score, 0-100).
- Feedback_Score: Integer (student feedback, 1-5).
- Engagement_Level:
Low,Medium, orHigh. - Dropout_Likelihood:
YesorNo(target variable for classifier).
- Size: 10,000 rows.
- Dropout Rate: ~5.7% (based on sample, ~570
Yes). - Courses: 5 unique courses, roughly balanced (~1,953-2,043 students each).
The API uses a Random Forest classifier to predict dropout risk, implemented in recommender/ai/classifier.py.
- Input Features (preprocessed in
recommender/ai/preprocessor.py):- Age (normalized).
- Gender (one-hot encoded: Male, Female, Other).
- Education Level (one-hot encoded: High School, Bachelor's, Master's, PhD).
- Learning Style (one-hot encoded: Visual, Auditory, Reading/Writing, Kinesthetic).
- Engagement Metrics (per course): Time Spent on Videos, Quiz Scores, Forum Participation, Assignment Completion Rate (normalized).
- Engagement Level (one-hot encoded: Low, Medium, High).
- Target:
Dropout_Likelihood(Yes→ 1,No→ 0).
- Algorithm: Random Forest (
sklearn.ensemble.RandomForestClassifier). - Parameters:
n_estimators=100: 100 decision trees.class_weight="balanced": Adjusts for class imbalance (~5.7% dropouts).random_state=42: Ensures reproducibility.
- Training:
- 80/20 train-test split.
- Evaluated with a custom threshold of 0.3 for binary prediction (though stored scores are probabilities).
- Output:
predicted_dropout_score(0-1 probability) stored in eachStudentProfile.
- Accuracy: 78.45%.
- Classification Report:
precision recall f1-score support No Dropout 0.81 0.96 0.88 1623 Dropout 0.20 0.05 0.08 377 - Notes: Low recall (0.05) for dropouts due to conservative threshold and imbalance. Scores like 0.7 (e.g.,
S00027) correctly identify high-risk students.
The recommendation system, implemented in recommender/algorithms/recommender.py, combines content-based and collaborative filtering with a dropout risk adjustment.
-
Content-Based Filtering:
- Matches student’s
learning_styleto coursecontent_type_weights(defined inservices.py). - Example Weights:
- Python Basics: Visual (0.3), Auditory (0.1), Reading/Writing (0.5), Kinesthetic (0.1).
- Web Development: Visual (0.4), Auditory (0.1), Reading/Writing (0.2), Kinesthetic (0.3).
- Score:
content_match = course.content_type_weights[student.learning_style].
- Matches student’s
-
Collaborative Filtering:
- Uses cosine similarity (
recommender/algorithms/similarity.py) to find 5 most similar students based on profile features (age, gender, education, etc.). - Calculates average success (
final_exam_scores / 100) among similar students who took the course. - Score:
collab_score = avg(similar_students_success)(0 if no similar students took the course).
- Uses cosine similarity (
-
Dropout Risk Adjustment:
- If
predicted_dropout_score > 0.5, adds a fixed+0.25to the relevance score. - Encourages courses for high-risk students to improve retention.
- If
relevance_score = 0.5 * content_match + 0.5 * collab_score + (0.25 if predicted_dropout_score > 0.5 else 0)
- Combines: "Matches learning style (Visual: X.XX)", "Popular among N similar students (avg success: X.XX)", and "Adjusted for high dropout risk (+0.25)" (if applicable).
- Profile: Visual learner,
predicted_dropout_score=0.7. - Web Development:
- Content Match: 0.40.
- Collab Score: 0.84 (3 similar students).
- Adjustment: +0.25.
- Score:
0.5 * 0.40 + 0.5 * 0.84 + 0.25 = 0.87.
-
Clone the Repository (if applicable):
git clone <repository-url> cd Adaptative-courses
Or copy the project folder to your machine.
-
Create Virtual Environment:
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Verify Dataset:
- Ensure
personalized_learning_dataset.csvis in the root directory (/Users/mac/Desktop/Adaptative-courses/).
- Ensure
-
Explore Swagger UI:
- After running the API, visit
http://127.0.0.1:5000/swagger-uito interact with the endpoints via an interactive interface.
- After running the API, visit
cd /Users/mac/Desktop/Adaptative-courses/
python -m recommender.api.app- Runs on
http://127.0.0.1:5000(and all network interfaces). - Debug mode is enabled by default.
- Swagger UI is available at
http://127.0.0.1:5000/swagger-ui.
-
GET
/api/students/<student_id>:- Description: Returns a student’s profile.
- Example:
curl http://localhost:5000/api/students/S00027 - Response:
{ "student_id": "S00027", "age": 30, "gender": "Male", "education_level": "High School", "learning_style": "Visual", "course_history": ["Python Basics"], "engagement_level": "Medium", "dropout_likelihood": true, "predicted_dropout_score": 0.7 }
-
GET
/api/recommendations/<student_id>:- Description: Returns top N course recommendations (default N=3).
- Query Param:
num(optional, integer, default=3). - Example:
curl http://localhost:5000/api/recommendations/S00027?num=3 - Response:
{ "student_id": "S00027", "recommendations": [ { "course_name": "Web Development", "reasoning": "Matches learning style (Visual: 0.40). Popular among 3 similar students (avg success: 0.84). Adjusted for high dropout risk (+0.25).", "relevance_score": 0.87 }, {...} ] }
-
GET
/api/courses:- Description: Returns a list of all available courses with statistics.
- Example:
curl http://localhost:5000/api/courses - Response:
{ "courses": [ { "course_name": "Python Basics", "average_completion_rate": 85.5, "average_quiz_score": 75.2, "average_time_spent": 10.3 }, {...} ] }
-
GET
/api/health:- Description: Checks API health status.
- Example:
curl http://localhost:5000/api/health - Response:
{ "status": "healthy", "message": "API is running" }
-
GET
/api/analysis:- Description: Returns aggregated statistics for dropout risk, engagement, and course performance.
- Example:
curl http://localhost:5000/api/analysis - Response:
{ "avg_dropout_risk": 0.1976, "course_statistics": {...}, "dropout_risk_distribution": {"0-0.25": 9995, "0.25-0.5": 5, ...}, "engagement_distribution": {"High": 2980, "Medium": 4927, "Low": 2093}, "total_students": 10000 }
This section provides practical examples of integrating the API into applications or workflows.
-
Student Profile Widget:
- Fetch
/api/students/<id>to display a student’s details (e.g., age, dropout risk). - Example (Python):
import requests response = requests.get('http://localhost:5000/api/students/S00027') print(response.json())
- Fetch
-
Recommendation Engine:
- Use
/api/recommendations/<id>to suggest courses in a student portal. - Example (JavaScript):
fetch('http://localhost:5000/api/recommendations/S00027?num=2') .then(response => response.json()) .then(data => console.log(data.recommendations));
- Use
-
Analytics Dashboard:
- Call
/api/analysisto populate charts (e.g., dropout risk distribution). - Example (Python):
import requests import matplotlib.pyplot as plt response = requests.get('http://localhost:5000/api/analysis') data = response.json() plt.bar(data['engagement_distribution'].keys(), data['engagement_distribution'].values()) plt.show()
- Call
- Check Health:
curl http://localhost:5000/api/health - Get Courses:
curl http://localhost:5000/api/courses | jq . - Explore via Swagger: Open
http://127.0.0.1:5000/swagger-uiin a browser to test endpoints interactively.
- Batch Recommendations:
- Script to fetch recommendations for multiple students:
for id in S00027 S00001; do curl "http://localhost:5000/api/recommendations/$id" >> recs.json; done
- Script to fetch recommendations for multiple students:
Listed in requirements.txt:
flask==2.3.3
flask-restx==1.3.0 # For Swagger documentation and API structuring
scikit-learn==1.5.0
numpy==1.26.4
Install with:
pip install -r requirements.txtThe API offers several avenues for academic or experimental research in educational technology and machine learning:
-
Dropout Prediction Enhancement:
- Feature Engineering: Investigate additional features (e.g., time between quiz attempts, sentiment from forum posts) to improve recall for dropout prediction.
- Alternative Models: Compare Random Forest with gradient boosting (e.g., XGBoost) or deep learning (e.g., LSTM for sequential engagement data).
- Threshold Optimization: Use ROC curves to dynamically select a threshold balancing precision and recall, rather than the fixed 0.3.
-
Personalized Learning:
- Learning Style Impact: Test whether aligning course content with learning styles (e.g., Visual vs. Kinesthetic) significantly affects completion rates using A/B testing.
- Dynamic Weighting: Research adaptive
content_type_weightsbased on real-time student performance or feedback, potentially using reinforcement learning.
-
Collaborative Filtering:
- Similarity Metrics: Experiment with alternatives to cosine similarity (e.g., Pearson correlation, Jaccard index) for identifying similar students.
- Cold Start Problem: Study recommendation accuracy for new students with sparse
course_historyusing hybrid approaches (e.g., demographics + content).
-
Dropout Intervention:
- Adjustment Impact: Evaluate whether the
+0.25adjustment for high-risk students reduces dropout rates in a controlled study. - Behavioral Analysis: Correlate predicted dropout scores with engagement metrics to identify early warning signs.
- Adjustment Impact: Evaluate whether the
-
Scalability and Real-World Data:
- Big Data: Test the system with larger, real-world datasets (e.g., MOOC platforms) to assess scalability and generalizability.
- Online Learning: Adapt the classifier for streaming data to update predictions in real-time as students progress.
- Classifier Tuning: Increase dropout recall by lowering the threshold (e.g., 0.2) or adding features (e.g., quiz attempts).
- Dynamic Weights: Adjust
content_type_weightsbased on student feedback or course outcomes. - Scalability: Add database support (e.g., PostgreSQL) instead of in-memory storage.
- API Security: Implement authentication (e.g., JWT) and rate limiting for production use.
- Real-Time Updates: Support live data ingestion for continuous learning.
- Fork the repository, make changes, and submit a pull request.
- Report issues or suggest features via GitHub Issues (if hosted).
- Flask-RESTX Integration: Updated
Setup and InstallationandDependenciesto include Flask-RESTX and Swagger UI instructions. - How to Use the API: Added practical examples for dashboard integration, CLI testing, and automation.
- Research Perspectives: Included five research areas with specific ideas to inspire academic exploration.
- Endpoints: Updated to reflect the
/api/namespace from Flask-RESTX.
- Save the File: Replace
/Users/mac/Desktop/Adaptative-courses/README.mdwith this content. - Update
requirements.txt: Ensure it includesflask-restx==1.3.0. - Test: Run the API and verify Swagger UI at
http://127.0.0.1:5000/swagger-ui.