A beginner-friendly project exploring core Data Science and Machine Learning concepts using real-world TeleCom employee data. This project walks through the full data pipeline β from raw CSV ingestion to trained regression models.
π Project Root
βββ π TeleCom.csv # Core dataset (salary & tax data)
βββ π CsvImport.py # EDA & data analysis
βββ π LinearRegression.py # Linear Regression model
β
βββ π PolynomialImportCsvTest/
β βββ π TeleComP.csv # Extended dataset
β βββ π PolynomialRegression.py # Polynomial Regression (script)
β
βββ π PolynomialPractice/
βββ π TeleComP.csv # Extended dataset (copy)
βββ π PolynomialRegressionExample.py # Polynomial Regression (script)
βββ π PolynomialTest.ipynb # Polynomial Regression (notebook)
Stage 1 Stage 2 Stage 3
βββββββββββββββββ ββββββββββββββββββββββ ββββββββββββββββββββββββββ
π₯ Data Import β π Linear Regression β π Polynomial Regression
& EDA (Salary β TaxDeduction) (Curved fit, degree=2)
CsvImport.py LinearRegression.py PolynomialRegression.py
| Tool | Purpose |
|---|---|
Python |
Core programming language |
pandas |
Data loading, manipulation & groupby analysis |
matplotlib |
Data visualisation (bar charts, scatter plots) |
scikit-learn |
Machine learning models & evaluation metrics |
numpy |
Numerical operations & array handling |
Jupyter Notebook |
Interactive experimentation environment |
File: CsvImport.py
Dataset: TeleCom.csv β 35 employees across departments with Salary and Tax Deduction data.
- Loads the TeleCom CSV into a pandas DataFrame
- Performs descriptive statistics and group analysis
- Visualises employee distribution by department
- Calculates the correlation between Salary and Tax Deduction
# Total salary across all employees
total_score = df["Salary"].sum()
# Max and mean tax deduction
max_tax = df["TaxDeduction"].max()
mean_tax = df["TaxDeduction"].mean()
# Gender breakdown β count, mean/max/min salary and tax
df.groupby('Gender')["Salary"].mean()
# Employee count per department
df.groupby("Department")["Gender"].count()
# Salary vs Tax Deduction correlation
corr = df["Salary"].corr(df["TaxDeduction"])A bar chart is generated showing how many employees exist per department (Sales, Finance, ICT, Marketing, Consulting, Human Resource).
Output: Bar chart β "No. of Employees in Department"
X-axis: Department names
Y-axis: Employee count
Correlation between Salary and Tax Deduction: ~0.97
A near-perfect positive correlation β as salary increases, tax deduction increases proportionally. This makes sense as the foundation for building a regression model.
File: LinearRegression.py
Goal: Predict TaxDeduction from Salary using a trained Linear Regression model.
Raw Data β Train/Test Split β Fit Model β Predict β Evaluate
(80% / 20%) LinearRegression() y_pred RΒ², MSE
X = data[['Salary']] # Independent variable
y = data['TaxDeduction'] # Dependent variable
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)| Metric | Value |
|---|---|
| RΒ² Score | ~0.94+ |
| Mean Squared Error | Low (tight fit) |
| Regression Coefficient | Positive slope |
| Intercept | Base tax at zero salary |
A scatter plot is generated showing actual vs predicted tax deductions, with a red regression line overlaid.
Output: Scatter plot β "Linear Regression: Tax Deduction vs Salary"
Blue dots β Actual test data points
Red line β Predicted regression line
Total employees : 35
Training samples : 28 (80%)
Test samples : 7 (20%)
Max Salary (train) : ~R24,444
Min Salary (train) : ~R9,225
Mean Tax (train) : ~R1,700
Files: PolynomialRegression.py / PolynomialTest.ipynb
Dataset: TeleComP.csv β Same employees with an extended NewTaxDeduction column.
Goal: Fit a curved (degree=2) polynomial model to capture any non-linear relationships.
Linear regression assumes a straight-line relationship. Polynomial regression adds squared terms so the model can capture curved patterns in data, which is useful when the relationship between features bends rather than stays perfectly linear.
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
poly = PolynomialFeatures(degree=2, include_bias=False)
x_poly = poly.fit_transform(x)
poly_reg = LinearRegression()
poly_reg.fit(x_poly, y)A scatter plot with a smooth green polynomial curve is generated, showing how the model fits the data with a slight curve rather than a straight line.
Output: Scatter plot β "Polynomial Regression: Salary vs TaxDeduction"
Blue dots β Actual data points
Green curve β Fitted polynomial regression curve (degree=2)
| Concept | Where Applied |
|---|---|
| CSV loading with pandas | CsvImport.py |
| GroupBy & aggregation | CsvImport.py |
| Correlation analysis | CsvImport.py |
| Train/test split | LinearRegression.py |
| Model fitting & prediction | LinearRegression.py |
| RΒ² and MSE evaluation | LinearRegression.py |
| Feature transformation | PolynomialRegression.py |
| Non-linear modelling | PolynomialRegression.py |
| Jupyter Notebook workflow | PolynomialTest.ipynb |
python -m pip install pandas matplotlib scikit-learn numpy# Stage 1 β EDA
python CsvImport.py
# Stage 2 β Linear Regression
python LinearRegression.py
# Stage 3 β Polynomial Regression
python PolynomialImportCsvTest/PolynomialRegression.py
# Or open the notebook
jupyter notebook PolynomialPractice/PolynomialTest.ipynb- This project uses a small dataset (35 employees) β ideal for learning core concepts without computational overhead.
- The high RΒ² on linear regression (~0.94+) reflects the near-perfect real-world correlation between salary and tax deduction.
- Polynomial regression (degree=2) was explored as a next step to understand non-linear modelling, even though linear regression already performs well on this dataset.
Built as a beginner introduction to Data Science and ML Engineering in Python.