Skip to content

Instantly share code, notes, and snippets.

@jameskyle
Created March 15, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameskyle/fec9709e253b52c4d8ad to your computer and use it in GitHub Desktop.
Save jameskyle/fec9709e253b52c4d8ad to your computer and use it in GitHub Desktop.
from __future__ import division
import pandas as pd
import numpy as np
import scipy.optimize as sopt
def gradebook():
grades = np.array([
[100, 2.5],
[100, 2.5],
[100, 2.5],
[100, 5],
[100, 5],
[100, 15],
[100, 2.5],
[np.NaN, 10],
[np.NaN, 20],
[np.NaN, 10],
[np.NaN, 10],
[np.NaN, 15],
], dtype=float)
index = [
'mc1hw1',
'mc1hw2',
'mc1hw3',
'mc1p1',
'mc1p2',
'mc2p1',
'mc2hw1',
'mc2p2',
'midterm',
'mc3p1',
'mc3p2',
'mc3p3'
]
df = pd.DataFrame(grades, columns=('Grade', 'Percent'), index=index)
df['Grade'] = df['Grade'] / 100
df['Percent'] = df['Percent'] / 100
return df
def calc(grades):
df = gradebook()
df.loc[df['Grade'].isnull(), 'Grade'] = grades
return np.abs(check_grade(df) - .80)
def check_grade(df):
return (df['Grade'] * df['Percent']).sum()
def optimize():
df = gradebook()
nulls = df[df['Grade'].isnull()].shape[0]
guess = [.5] * nulls
bounds = ((0.0, 1.0),) * nulls
res = sopt.minimize(
calc,
guess,
method="SLSQP",
bounds=bounds,
)
return res
def main():
pass
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment