A simple machine learning web app built with Streamlit that predicts a student's exam score based on the number of hours they studied — powered by Linear Regression.
Enter the number of hours you studied (0–9), hit Submit, and the model will predict your exam score.
- Loads a CSV dataset (
Hours_and_Scores.csv) containing study hours and corresponding exam scores. - Trains a Linear Regression model on 75% of the data.
- Uses the trained model to predict a score from user input.
- Clamps the output between 0 and 100 to keep it realistic.
project/
│
├── data/
│ └── Hours_and_Scores.csv # Dataset with Hours and Scores columns
│
├── app.py # Main Streamlit application
└── README.md
Install the dependencies with:
pip install pandas numpy streamlit plotly scikit-learnOr if you have a requirements.txt:
pip install -r requirements.txtpandas
numpy
streamlit
plotly
scikit-learn
streamlit run app.pyThen open your browser at http://localhost:8501.
The dataset (Hours_and_Scores.csv) should have the following structure:
| Hours | Scores |
|---|---|
| 2.5 | 21 |
| 5.1 | 47 |
| 3.2 | 27 |
| ... | ... |
- Hours — Number of hours studied
- Scores — Exam score achieved (0–100)
The dataset contains 25 samples and is split 75/25 for training and testing.
| Property | Value |
|---|---|
| Algorithm | Linear Regression |
| Library | scikit-learn |
| Train/Test Split | 75% / 25% |
| Feature Scaling | Not applied* |
| Input Range | 0 – 9 hours |
| Output Range | 0 – 100 (clamped) |
*Feature scaling (StandardScaler) is not needed for Linear Regression and has been intentionally left out.
- Streamlit — Web UI framework
- scikit-learn — Machine learning
- pandas — Data handling
- NumPy — Numerical operations
- Plotly — Visualization (imported for future use)
- The model is retrained every time the app starts (no model persistence).
- Since
train_test_splituses a random seed by default, results may vary slightly between runs. Addrandom_state=42for reproducibility:X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
NFlux