Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
data = pd.read_csv('weight-height.csv')
height = np.array(data['Height'])
weight = np.matrix(data['Weight']).T
gender = np.array([0 if x == 'Male' else 1 for x in data['Gender']])
feature_0 = [1] * len(height)
data = np.matrix([feature_0, gender, height]).T
calculation = np.linalg.pinv(data.T * data) * data.T * weight
def predict(gender, height):
"""male is 0, female is 1"""
testing_set = np.array([1, gender, height])
prediction = np.array(testing_set * calculation)[0][0]
print(f'Weight is {int(prediction)}')
predict(0, 250)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.