This project demonstrates the process of building a machine learning model to predict university rankings based on various features. Additionally, it provides a FastAPI-based API for making predictions with the trained model.
API Endpoint:https://simple-ml-api-4b6b50e31b43.herokuapp.com/
Send a POST request with the following JSON object to get predictions:
{ "no_of_student":32000, "no_of_student_per_staff":23.5, "international_student":0.15, "teaching_score":97.4, "research_score":96.8, "citations_score":92.5, "industry_income_score":94.3, "international_outlook_score":97.1, "female_ratio":52.5, "male_ratio":47.5 }
The goal of this project is to predict university rankings using machine learning. The steps involved in this project include:
- Data Preprocessing: The project starts with data preprocessing. The dataset, "World University Rankings 2023.csv," is loaded and cleaned to remove missing values and format columns correctly.
- Model Training: A Linear Regression model is trained on the preprocessed dataset. The model is used to predict university rankings based on features like the number of students, teaching scores, research scores, etc.
- Scalability: The StandardScaler is used to standardize the input features for making predictions.
- API Development: The FastAPI framework is used to create a simple API for university ranking predictions. The API takes input in the form of a JSON object, processes it, and returns a prediction.
Before running this project, ensure you have the following prerequisites:
- Python 3.x
- Jupyter Notebook (optional)
- Heroku CLI (optional for deployment)
- Clone the repository:
bashCopy code
git clone https://github.com/StevenHHB/simple_ml_api.git
- Install the required Python packages:
bashCopy code
pip install -r requirements.txt
- Data Preprocessing: The data preprocessing step is essential to clean and format the dataset. It involves handling missing values, converting data types, and creating appropriate features. This is done in the
preprocess_data
function. - Model Training: The machine learning model, a Linear Regression model, is trained on the preprocessed dataset. This model is used to predict university rankings. You can find the code for training the model in a Jupyter Notebook or Python script.
- Standardization: Input features are standardized using the
StandardScaler
to ensure consistency when making predictions. - Model Persistence: Both the trained model and the scaler are saved to pickle files (
university_ranking_model.pkl
anduniversity_ranking_scaler.pkl
, respectively) for later use.
Once the model and scaler are trained and saved, you can start the FastAPI-based API to make university ranking predictions.
- Run the FastAPI application:
bashCopy code
uvicorn api:app --host 0.0.0.0 --port 8000 --reload
- Access the API at
http://localhost:8000
using an API client or a tool likecurl
. - Send a POST request with the following JSON object to get predictions:
jsonCopy code
{ "no_of_student": 32000, "no_of_student_per_staff": 23.5, "international_student": 0.15, "teaching_score": 97.4, "research_score": 96.8, "citations_score": 92.5, "industry_income_score": 94.3, "international_outlook_score": 97.1, "female_ratio": 52.5, "male_ratio": 47.5 }
- You will receive a JSON response with the prediction:
jsonCopy code
{ "predictions": 15.23 }
Contributions are welcome! If you'd like to improve this project or fix any issues, please submit a pull request. For major changes, please open an issue first to discuss the proposed changes.
This project is licensed under the MIT License - see the LICENSE file for details.