This file contains hidden or 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
| axis = np.linspace(5, 105, NUM_BINS + 1)[:-1] | |
| jp_df = pd.DataFrame(jp_matrix, columns=axis, index=axis) | |
| jp_df = jp_df.applymap(lambda val: 0 if math.isnan(val) else (val / NUM_STUDENTS)) | |
| jp_df |
This file contains hidden or 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
| def create_joint_probability_matrix(data_GT, data_P, bins): | |
| # https://stackoverflow.com/questions/38931566 | |
| def background_gradient(s, m=None, M=None, cmap='Reds', low=0, high=0): | |
| if m is None: | |
| m = s.min().min() | |
| if M is None: | |
| M = s.max().max() | |
| rng = M - m | |
| norm = colors.Normalize(m - (rng * low), M + (rng * high)) |
This file contains hidden or 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
| # Regression Analysis | |
| fig, ax = plt.subplots(2, 1, figsize=(20,20)) | |
| sns.set(color_codes=True) | |
| print("mean_squared_error: ", round(mean_squared_error(grades_GT, grades_P), 2)) | |
| print("mean_absolute_error: ", round(mean_absolute_error(grades_GT, grades_P), 2)) | |
| print("explained_variance_score: ", round(explained_variance_score(grades_GT, grades_P), 2)) | |
| ax[0].tick_params(axis='both', labelsize=25) |
This file contains hidden or 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
| # Regression Analysis | |
| fig, ax = plt.subplots(2, 1, figsize=(20,20)) | |
| sns.set(color_codes=True) | |
| print("r2_score: ", round(r2_score(grades_GT, grades_P), 2)) | |
| print("mean_squared_error: ", round(mean_squared_error(grades_GT, grades_P), 2)) | |
| print("mean_absolute_error: ", round(mean_absolute_error(grades_GT, grades_P), 2)) | |
| print("explained_variance_score: ", round(explained_variance_score(grades_GT, grades_P), 2)) |
This file contains hidden or 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
| # Generate a pandas dataframe where the index represents the student number | |
| df_GT = pd.DataFrame({'bucket': bucket_GT}).reset_index() | |
| display(df_GT.head()) | |
| df_P = pd.DataFrame({'bucket': cut_P}).reset_index() | |
| display(df_P.head()) | |
| # Merged the actual predicted grades | |
| merged_df = pd.merge(df_GT, df_P, on=['index'], suffixes=('_grouth_truth', '_predicted')) | |
| display(merged_df.head()) |
This file contains hidden or 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
| NUM_BINS = 10 | |
| bins = np.linspace(0, 100, NUM_BINS + 1) | |
| # Note: we set include_lowest to true to make sure that we include zeroes | |
| bucket_GT = pd.cut(grades_GT, bins=bins, include_lowest=True, right=True) | |
| bucket_P = pd.cut(grades_P, bins=bins, include_lowest=True, right=True) | |
| # Output of the cut function | |
| pd.DataFrame({'grades': grades_GT, 'bucket': bucket_GT}).head() |
This file contains hidden or 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
| # Data Generation | |
| NUM_STUDENTS = 30 | |
| MEAN = 80 | |
| STD = 20 | |
| # https://stackoverflow.com/questions/36894191/how-to-get-a-normal-distribution-within-a-range-in-numpy | |
| # Need to cap the values of the distributions to [0,100] | |
| def get_truncated_normal(mean, sd, size, low, upp): | |
| return truncnorm((low - mean) / sd, (upp - mean) / sd, loc=mean, scale=sd).rvs(size) |
This file contains hidden or 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
| import cProfile, pstats | |
| import time | |
| from random import randint | |
| def sleep1(): | |
| time.sleep(0.1) | |
| def sleep2(): | |
| time.sleep(0.2) | |
This file contains hidden or 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
| import numpy as np | |
| import matplotlib | |
| import matplotlib.pyplot as plt | |
| from matplotlib.ticker import FormatStrFormatter | |
| WIDTH = 0.4 | |
| ind = np.arange(len(time_sliced_counters)) | |
| x_axis = tuple(time for (time, c) in time_sliced_counters) |
This file contains hidden or 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 collections import Counter | |
| import itertools | |
| TIME_SLICE = 10 # Aggregate logs every 10 seconds | |
| def time_to_bucket(time): | |
| return (time-START_TIME) // TIME_SLICE | |
| def bucket_to_time(bucket): | |
| return bucket * TIME_SLICE + START_TIME |