Python Machine Learning Examples — ARIMA/SARIMAX Time-Series Forecasting and Linear Regression
A collection of beginner-friendly machine learning projects built with Python: a COVID-19 time-series forecast using auto-ARIMA and SARIMAX (pmdarima, statsmodels), and a salary prediction model using scikit-learn linear regression with a separate training and inference workflow.
Projects
1. COVID Forecast
Location: COVID Forecast/Console_Code/CovidForecast.py
A time series forecasting script that predicts the number of daily COVID-19 cases for a country using SARIMAX and auto-ARIMA models.
How It Works
- Downloads daily COVID-19 case data via the
covid_dailypackage (if not already cached locally as a CSV) - Performs stationarity testing using the Augmented Dickey-Fuller (ADF) test
- Detrends and differences the time series for stationarity
- Automatically fits the best ARIMA/SARIMA model using
pmdarima.auto_arima - Fits the chosen model using
statsmodels.SARIMAX - Generates a static forecast (in-sample) and a future forecast for the next N days
- Displays all charts using
matplotlib
Configuration
Edit these variables at the top of the script:
| Variable | Default | Description |
|---|---|---|
country |
'india' |
Country to forecast ('india', 'brazil', etc.) |
stepCount |
50 |
Number of future days to forecast |
Requirements
numpy
pandas
pmdarima
covid_daily
statsmodels
matplotlib
pip install numpy pandas pmdarima covid_daily statsmodels matplotlib
Usage
cd "COVID Forecast/Console_Code"
python CovidForecast.py
The downloaded data is cached as <country>_corvid19.csv in the working directory, so later runs reuse it instead of downloading again.
2. Salary Prediction
Location: Salary/
A linear regression pipeline that predicts salary based on years of experience.
Sub-projects
| File | Purpose |
|---|---|
Model Builder/builder.py |
Trains the model and saves it to disk |
Prediction/prediction.py |
Loads the saved model and predicts salary from user input |
Model Builder Pipeline (builder.py)
- Load data from
Source/Salary.csv - Remove duplicate rows
- Drop columns with more than 50% missing values; fill remaining nulls with column mean
- Scale
years_experienceusingStandardScaler - Split into train (80%) and test (20%) sets
- Train a
LinearRegressionmodel - Evaluate using R² score and Mean Squared Error
- Save the model and scaler to
Source/salary.pklandSource/scaler.pklif R² > 0.95
Prediction Inference (prediction.py)
- Load the saved model and scaler from disk
- Prompt the user for years of experience
- Scale the input using the saved scaler
- Predict and display the salary
Requirements
pandas
scikit-learn
joblib
numpy
pip install pandas scikit-learn joblib numpy
Usage
Both scripts use paths relative to the working directory (./Source/...), so run them from the Salary folder. A trained salary.pkl and scaler.pkl are already included in Salary/Source/, so you can run inference without training first.
Train the model:
cd Salary
python "Model Builder/builder.py"
Run inference:
cd Salary
python "Prediction/prediction.py"
Inference session format:
Enter Years of Experience: 5
Predicted Salary for 5.0 years of experience: $<predicted amount>
Folder Structure
ML/
├── COVID Forecast/
│ └── Console_Code/
│ └── CovidForecast.py # Time series forecasting script
└── Salary/
├── Model Builder/
│ └── builder.py # Model training pipeline
├── Prediction/
│ └── prediction.py # Inference script
└── Source/
├── Salary.csv # Training data
├── salary.pkl # Saved LinearRegression model
└── scaler.pkl # Saved StandardScaler
Related
- Machine-learning datasets — more datasets for regression, classification, and forecasting practice
- Back to all Python projects
Documentation links
Read all Python Projects and Code Examples guides online · Project overview · All developer projects