Zain Khan

Information Science & Computer Science Student at CU Boulder.

Resume

About me

zain.jpg
Zain Khan standing next to a red car in front of pine trees and mountains

I am an Information Science and Computer Science student at CU Boulder. I am extremely passionate about working with data and creating ways to understand it. Outside of school and work I’m a photographer. It’s a big reason I love exploring new places and meeting new people, and it’s the main way I do both. Currently open to data and analytics roles.

Projects

SQL

Camera Database Schema

Database: SQLite  |  Tools: SQL

Designed a relational database for camera bodies, lenses and lens mounts, with six tables and a join table that tracks which lenses fit which bodies.

Excel

Auto MPG: Tables and Pivot Tables

Dataset: Auto MPG  |  Tools: Excel Tables, PivotTables

Cleaned 398 cars from the 1970s and 80s and summarized them with an Excel Table and two PivotTables.

Neural Network

Predicting Diamond Prices

Dataset: Diamonds  |  Tools: Python, scikit-learn

Trained a neural network on about 54,000 diamonds to predict price from size and quality. It explained about 97.5% of the variation in price on diamonds it had never seen.

AI Product

BridgeforgeAI

Product: Forge

Forge is AI automation for tasks, built for small trade businesses like HVAC, plumbing and electrical companies. It answers calls and website chats around the clock in English and Spanish, books jobs on the owner’s calendar and sends confirmation texts.

Visit site
Coming soon

More to come

More projects will be added here soon.

Skills

Programming

Python, Java, C++

Data & Analysis

SQL, pandas, scikit-learn, regression modeling, relational schema design, Excel, Tableau

Systems & IT

Windows, macOS, Linux, hardware troubleshooting, virtualized environments

Security

System hardening, ethical hacking basics, Linux terminal

Contact

resume.pdfDownload
Zain Khan resume
SQL

Camera Database Schema

Database: SQLite
Tools: SQL

The idea

For this project I designed my own database schema by sketching one out. I picked cameras because it's something I'm interested in, and because camera bodies and lenses have a real relationship: a lens only fits a body that uses the same mount.

The schema

mountsmount_idPKintegernametextcamera_bodiesbody_idPKintegermodeltextbrandtextcountrytextmount_idFKintegersensor_sizetextmegapixelsrealrelease_yearintegeroperating_systemtextprice_usdreallenseslens_idPKintegermodeltextbrandtextcountrytextmount_idFKintegerfocal_min_mmintegerfocal_max_mmintegermax_aperturerealprice_usdreal

A query on the database

This query looks up my own setup, a Sony A7C II with a 24-70mm f/2.8 G Master lens, by joining the tables back together.

SELECT cb.brand,
       cb.model AS camera,
       l.model AS lens,
       m.name AS mount,
       cb.megapixels,
       l.focal_min_mm || '-' || l.focal_max_mm || 'mm' AS focal_range,
       'f/' || l.max_aperture AS max_aperture
FROM camera_bodies cb
JOIN mounts m ON cb.mount_id = m.mount_id
JOIN lenses l ON l.mount_id = cb.mount_id
WHERE cb.model = 'A7C II'
  AND l.model = 'FE 24-70mm F2.8 GM';

brandcameralensmountmegapixelsfocal_rangemax_aperture
SonyA7C IIFE 24-70mm F2.8 GMSony E33.024-70mmf/2.8

It starts at camera_bodies, joins mounts to get the mount name, then finds the lenses that use the same mount as that camera, and filters down to the two I own.

Neural Network

Predicting Diamond Prices

Dataset: Diamonds, about 54,000 stones
Tools: Python, pandas, scikit-learn, matplotlib

0.975test R², neural network
0.944test R², linear baseline
$324average error on test diamonds

The dataset

Each row is a diamond with its carat, cut, color, clarity, a few measurements and its price. The goal is to predict the price from everything else. I used a neural network (an MLP) because the relationship between size, quality and price is curved, and I wanted to see if it beats a straight line.

Feature engineering

  1. Cleaning. I removed 146 duplicate rows and 26 rows with impossible measurements, like a diamond that was 0 mm wide or 59 mm long. That left 53,768 diamonds.
  2. Skewed price. Most diamonds are cheap and a few are very expensive. I trained on the log of price, which makes the shape much more even, and converted back to dollars to score it.
  3. Encoding. Cut, color and clarity are ordered grades, so I turned them into numbers in order, worst to best, instead of one hot encoding. I tried one hot too and it scored slightly lower.
  4. Correlated columns. Length, width and depth in millimeters are about 98% correlated with carat, so I dropped them and used the log of carat.
  5. Scaling. Neural networks need features on similar scales, so I standardized them. The scaler only learns from the training data.
04,0008,00012,00016,000$0.3k$5.0k$9.6k$14.2k$18.8kprice (USD)
01,0002,0003,0004,0005.86.87.88.89.8log of price

The model

I held out 20% of the diamonds for testing and trained on the other 80%. The network has two hidden layers of 64 and 32 neurons and stops training early when the score on a validation slice quits improving. I compared it to a plain linear regression on the same features.

Results

On diamonds it had never seen, the neural network explained about 97.5% of the variation in price, against 94.4% for the linear model, and its average error was $324 compared to $458. I ran it with five different random starts and the score stayed between 0.974 and 0.976.

Linear0.944average error $458
Neural net0.975average error $324
$0k$0k$5k$5k$10k$10k$15k$15k$20k$20kactual pricepredicted price

What I learned

The feature work mattered as much as the model. The same network on the raw columns with no scaling or log scored 0.868, so the cleaning and scaling were worth about ten points. Carat is by far the biggest driver of price. Ideal cut diamonds actually average less than Fair ones, because the Ideal ones tend to be smaller, so cut only makes sense once you account for size. The predictions get looser on the most expensive diamonds, where there is less data to learn from. I removed duplicates assuming they were repeated entries, but some could be separate stones that happen to match.

Excel

Auto MPG: Tables and Pivot Tables

Dataset: Auto MPG, 398 cars from 1970–82
Tools: Excel Tables, PivotTables

398cars in the Excel Table
2PivotTables built from it
6missing horsepower values, left blank

The dataset

The same Auto MPG data from my machine learning project. This time I summarized it instead of predicting from it.

Cleaning the data

  1. Changed the origin codes 1, 2 and 3 to USA, Europe and Japan.
  2. Made the two-digit model years four digits.
  3. Six cars had a "?" for horsepower. I left those blank instead of guessing.

The Excel Table

I turned the data into an Excel Table named AutoMPG and added a calculated column, MPG Class: High is 30 MPG or more, Medium is 20 to 29.9, and Low is under 20. Those cutoffs are my own.

=IF([@MPG]>=30,"High (30+)",IF([@MPG]>=20,"Medium (20-29.9)","Low (under 20)"))
Car NameMPGCylHorsepowerWeight (lb)Model YearOriginMPG Class
Chevrolet Chevelle Malibu18.081303,5041970USALow (under 20)
Toyota Corolla 120032.04651,8361971JapanHigh (30+)
Volkswagen 1131 Deluxe Sedan26.04461,8351970EuropeMedium (20-29.9)

PivotTable 1: average MPG by origin and cylinders

Origin3 cyl4 cyl5 cyl6 cyl8 cylAll
Europe28.427.420.127.9
Japan20.631.623.930.5
USA27.819.715.020.1
Grand Total20.629.327.420.015.023.5
0510152025303528.431.627.820.123.919.715.04 cylinders6 cylinders8 cylindersnumber of cylindersaverage MPGEuropeJapanUSA

Fewer cylinders means better fuel economy, and Japanese cars average the most MPG at 4 and 6 cylinders. The chart leaves out 3 and 5 cylinder cars because there are so few.

PivotTable 2: cars per MPG class

MPG classEuropeJapanUSAAll
High (30+)22472392
Medium (20-29.9)422984155
Low (under 20)63142151
Grand Total7079249398
0408012016022472342298463142High (30+)Medium (20-29.9)Low (under 20)MPG classnumber of carsEuropeJapanUSA

142 of the 151 low-MPG cars are American.

Machine Learning

Predicting Car Fuel Economy

Dataset: Auto MPG, 398 cars from 1970–82
Tools: Python, pandas, scikit-learn, matplotlib

0.892test R², polynomial model
0.806test R², linear baseline
398cars, 80 held back for testing

The dataset and why I chose it

This dataset has information on car models from the 70's and 80's. Older vehicles are an interest of mine, so being able to visualize data about them is something I really wanted to do. It also has a variety of datatypes to work with, which gave me a lot more to work with. The goal is to predict a car's fuel economy from its other features. I thought with how simple cars were back then, that it would be easier to estimate fuel economy.

Cleaning and feature engineering

  1. Missing values. Horsepower was stored as text because six rows had a "?" in them, so those had to be changed into proper null values before I could work with them. I filled them in with the median, which is 93.5.
  2. Balance and outliers. It seems that the origin column is imbalanced, with a vast majority of the cars being American made, 249 of 398 cars. Odd numbered cylinder engines are also incredibly uncommon, and four cylinders is the most common at 204 cars. Since fuel economy is a number, there aren't any classes to balance. I kept all of the rows because there were no absurd values that didn't seem accurate for a car from this era.
  3. Encoding. There are 305 unique car names out of 398 rows, so most are unique and the model wouldn't have much to learn from if I one hot encoded them. I pulled out the brand, which is the first word of the name, instead and fixed the typos and duplicates, like "chevy" and "chevrolet". Origin was one hot encoded since the numbers are just labels and not sequential.
  4. Correlated columns. Fuel economy has the strongest correlation with weight, and it is negative, so the heavier a car is, the worse its fuel efficiency is. Weight, displacement, horsepower, and cylinders are also all correlated with each other, which makes sense since the larger a vehicle is, the more powerful it seemingly needs to be. They were too highly correlated, so I removed cylinders and displacement so they don't harm the model.
0102030405060709152127333945fuel economy (mpg)number of cars
Most cars fall between about 13 and 30 mpg, with a smaller group of really efficient ones.
mpgcyldisphpweightaccelyear
mpg1.00-0.78-0.80-0.77-0.830.420.58
cyl-0.781.000.950.840.90-0.51-0.35
disp-0.800.951.000.900.93-0.54-0.37
hp-0.770.840.901.000.86-0.69-0.41
weight-0.830.900.930.861.00-0.42-0.31
accel0.42-0.51-0.54-0.69-0.421.000.29
year0.58-0.35-0.37-0.41-0.310.291.00
Correlation between columns. Gold means they go up together and blue means one goes up as the other goes down. Weight has the strongest link to fuel economy, at -0.83.

Finding clusters without using mpg

I left out fuel economy, used only the features, and ran K-means on them. The elbow is at k=2 because that's where the most pronounced bend in the chart is. It split the cars into two groups: 301 lighter, lower horsepower cars that average about 2,592 lb and 86 hp and 97 much heavier and more powerful ones that average about 4,144 lb and 162 hp. The fuel economy between the two groups varies drastically, with the more efficient group at about 26.4 mpg and the more powerful, less efficient group at only a little over 14.5.

06001200180012345678number of clusters (k)inertiaelbow at k = 2
Elbow plot. The bend is at 2 clusters.
501001502002502,0003,0004,0005,000weight (lb)horsepower
lighter, lower horsepower   heavier, more powerful

Train/test split and the models

I held out 20% of the cars, which is 80, to test on and trained on the other 318. The model can't see the test cars while it trains, otherwise it would memorize them and make the scores look better than they actually are. Based on the shape of the fuel economy vs weight and horsepower plots there's a bit of a curve, so a polynomial regression made the most sense using degree 2 on horsepower, weight, acceleration, and model year. I trained a plain linear regression too, since knowing how it acts can show where it might be more accurate.

Results

R² is basically how much of the variation in fuel economy the model explains. On cars it hadn't seen before, the polynomial model explained about 89.2% of it and the linear model explained about 80.6%, so my initial prediction was correct. They are both somewhat accurate, but the polynomial version does have that slight edge, and on the graph it gets slightly tighter when the fuel economy is higher. The training and test scores were close for both, so neither seems badly overfit.

Linear0.806train 0.838
Polynomial0.892train 0.896
10203040501020304050actual fuel economy (mpg)predicted fuel economy (mpg)
Predicted fuel economy against actual fuel economy for the 80 test cars. The closer a dot is to the dashed line, the better the prediction.

What I learned

Fuel economy is driven by how big and powerful a vehicle is. Weight, displacement, horsepower, and cylinders were all negatively correlated with fuel economy, and letting the model curve got it about nine points of R² higher than a straight line. The data is small and outdated, so I don't expect it to be incredibly accurate for newer vehicles, considering the advancements made in technology and efficiency. There also aren't enough 3 and 5 cylinder cars for the model to learn much from.

I got a lot more comfortable with pandas and scikit-learn. pandas made the cleaning pretty easy, like turning the bad horsepower values into nulls with to_numeric and one hot encoding the brands with get_dummies. scikit-learn covered everything else, like SimpleImputer for the median, KMeans for the clusters, and a pipeline that scales the columns and adds the polynomial terms, so the exact same steps get applied to the test cars. The biggest thing I learned is to split the data before fitting anything and to score the model on cars it hasn't seen, since that is what shows whether it really works. I also refined my matplotlib skills.