<jupyter_start><jupyter_text>Mentor Match:Using a data-driven approach to match mentors to students with similiar interests will improve the mentorship program!  Introduction:Mentoring is a crucial component of the P-TECH 9-14 model. Through mentoring, industry professionals are invited into the schoolcommunity. They offer students with meaningful academic, workplace learning and social/emotional support. Likewise, mentoring givesstudents with an adult role model and a guide who works in the field they are studying. Mentors can also provide emotional support,encouragement, and meaningful feedback on coursework. Problem:While mentors have an important role in the p-tech model, the way mentors are chosen for students has quite a few problems. Mentors are matched almost completely randomly and are matched manually by the program manager. This is not only very time consuming for the program manager, but it isn't a scalable solution for the inevitable expansion of P-TECH. Through my experience, and my conversations with both Students and Mentors, I have found that the mentors assigned to students often have little in common with the students. Through my research, I have found that this causes unfulfilling mentor-student relationships and reduce overall engagement from both parties. Problem(Summarized):The method of matching mentors at P-TECH is unscalable and can be improved. Poorly matched mentors are  having a negative effect in the mentor-mentee relationships.Solution:Using a data-driven approach to match mentors to students with similiar interests will improve the quality of the mentorship program! Giving students mentors who have similiar interests is much more intuitive for a relationship that has major focus on guidance. Also an algorithmic approach to this save program manager valueable time!The steps to a better mentor matching framework are outlined below:1.   Survey2.   Matching algorithm3.   Happy mentor and students :)<jupyter_code>%pip install names
import pandas as pd
import numpy as np
import names<jupyter_output>Collecting names
[?25l  Downloading https://files.pythonhosted.org/packages/44/4e/f9cb7ef2df0250f4ba3334fbdabaa94f9c88097089763d8e85ada8092f84/names-0.3.0.tar.gz (789kB)
[K    100% |████████████████████████████████| 798kB 22.9MB/s 
[?25hBuilding wheels for collected packages: names
  Building wheel for names (setup.py) ... [?25ldone
[?25h  Stored in directory: /root/.cache/pip/wheels/f9/a5/e1/be3e0aaa6fa285575078fa2aafd9959b45bdbc8de8a6803aeb
Successfully built names
Installing collected packages: names
Successfully installed names-0.3.0<jupyter_text>Step 1: Survey*This is probably the most important step*We need to ask every person(Students and Mentors) the right questions regarding what we want to get out of the mentor-mentee relationship. If it is career advice career focused questions might be the best andif it is school advice subject-focused questions might be best!  Create student and mentor datasets in the form of:{Name : [rating1, rating2, rating3, rating4, rating5, ... ratingN]} for N categories  Example survey questions: Enter name: <NAME> How interested are you in the following topics in a scale from 1-5; 1 being least interested, 5 being the most:1. Computer Science: 52. Buisness: 53. History: 14. Design: 35. Biology: 36. Physics: 57. Chemistry: 4--- output: {Abdullah Saleh: [5,5,1,3,3,5,4]} --- Mock Data:random names - random scoresIn this example we will create mock data for 300 mentors and 300 students!<jupyter_code># Create an array of size 300 for mentors and 600 for students with a random int value between 1 and 5
mentor = np.random.randint(1,6,size=[300,5])
student = np.random.randint(1,6,size=[600,5])

def create_dataset(data):
    dataset = {}
    for i in data:
        dataset[names.get_full_name()] = i
    return dataset
mentor_dataset = create_dataset(mentor)
student_dataset = create_dataset(student)
mentor_dataset<jupyter_output><empty_output><jupyter_text>Step 2: Math, baby!Now that we have the survey data, how can we get meaningful insight from it? If we think about the array of interest scores as a set of points that represent the persons overall interests as a **coordinate** then we can look for the closest coordinate and assume that that is representitive of the person with the closest interests!So how do we find the closest person? we establishes that we should represent each person as a coordinate of their interests and from therewe can look at the distance between all the other coordinates on the and pick the one with that is closestThere are many metrics to measure distance but we will use the straight line distance from each point as ours. This is called Euclidean Distance and can be written out as:$\sqrt{\sum_{i=1}^n (x_i-y_i)^2}$*Feel free to try other distance or similiarity metrics*Now that we have a way to measure the distance between each persons interest coordinate, we can find the closest person to each person by making a list of the distances of a person to every other person in the list. In this case we can record the distance from a mentor to every other student and then sort them in acending order. Since we have a sorted list of the closest students, lets call the neighbors, the closest student would be the first person in the list, the second closest would be the 2nd person on the list, and so on. In general we can find any number of the nearest neighbors this way!In this case we only look for the closest student on the list but you can play around with the ammount of nearest neighbors you look for.Google these for more info:Euclidean DistanceK-Nearest-Neighbors<jupyter_code>def distance(pers1, pers2):
  squared_difference = 0
  for i in range(len(pers1)):
    squared_difference += (pers1[i] - pers2[i]) ** 2
  final_distance = squared_difference ** 0.5
  return final_distance

def knn(unknown, dataset, k=1):
  distances = []
  #Looping through all points in the dataset
  for name in dataset:
    scores = dataset[name]
    distance_to_point = distance(scores, unknown)
    #Adding the distance and point associated with that distance
    distances.append([distance_to_point, name])
  distances.sort()
  #Taking only the k closest points
  neighbors = distances[0:k]
  return neighbors[0]
  
knn([5,5,5,5,5], mentor_dataset)<jupyter_output><empty_output><jupyter_text>Matching process The matching process is quite simple. We go through the dataset of mentors and match every mentor to the student closest to them. We check if any student doesnt have a mentor and then we match the mentors again until all the students have been matched!Steps:make an empty dictionary recording mentors and their mentee(s);While there are students that are not matched to a mentor:  For each mentor:    match them to the student that is the most similiar<jupyter_code>matched_list = {}
for i in mentor_dataset:
    matched_list[i] = []
while(len(student_dataset) != 0):
    for i in mentor_dataset:
        if len(student_dataset) != 0:
            matched_student = knn(mentor_dataset[i], student_dataset)[1]
            matched_list[i].append(matched_student)
            del student_dataset[matched_student]
        else:
            matched_list[i].append('')

print(matched_list)



        
    
df = pd.DataFrame(matched_list)
# writer = pd.ExcelWriter('output.xlsx',engine='xlsxwriter')
# df.to_html()
# writer.save()
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06343434343434344, 'fraction_numerical': 0.02410774410774411, 'mean_word_length': 4.8015625, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '400259', 'license': 'MIT', 'n_tokens_mistral': 2120, 'n_tokens_neox': 1958, 'n_words': 958, 'path': 'MentorMatch.ipynb', 'repo_name': 'SneakyAsH311/Mentor-Match', 'size': '7433'}