Created
March 15, 2016 15:33
-
-
Save jameskyle/fec9709e253b52c4d8ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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