Skip to content

Instantly share code, notes, and snippets.

@morales-roman
Created October 1, 2025 22:50
Show Gist options
  • Select an option

  • Save morales-roman/e6c3c73f71a1ab9327f5cb00cac7c804 to your computer and use it in GitHub Desktop.

Select an option

Save morales-roman/e6c3c73f71a1ab9327f5cb00cac7c804 to your computer and use it in GitHub Desktop.
HW 1 MLZoomcamp
import pandas as pd
import numpy as np
# Question 1
print(pd.__version__)
df = pd.read_csv('car_fuel_efficiency.csv')
# Question 2
print(df['engine_displacement'].count())
# Question 3
print(df['fuel_type'].unique())
# Question 4
print(df.isnull().sum())
# Question 5
asia = df[df['origin'] == 'Asia']
print(asia['fuel_efficiency_mpg'].max())
# Question 6
print("Question 6")
median_hp = df['horsepower'].median()
print(median_hp)
most_frequent_hp = df['horsepower'].mode()[0]
print(most_frequent_hp)
filled = df['horsepower'].fillna(most_frequent_hp)
print(filled)
median_hp_filled = df['horsepower'].median()
print(median_hp_filled)
# Question 7
print("Question 7")
asia = df[df['origin'] == 'Asia'][['vehicle_weight', 'model_year']].head(7)
print(asia)
X = asia.values
print(X)
XTX = X.T @ X
print(XTX)
XTX_inv = np.linalg.inv(XTX)
print(XTX_inv)
y = [1100, 1300, 800, 900, 1000, 1100, 1200]
w = XTX_inv @ X.T @ y
print("w:", w)
print(sum(w))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment