Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/F-FIDELO-19-008-FLEURY/course-recommender
03 February 2026, 00:33:30 UTC
  • Code
  • Branches (2)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • refs/heads/newMut
    No releases to show
  • b093802
  • /
  • data_analysis.py
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:b5c4da68f39e367599be46fdfaf5be259f7c581b
origin badgedirectory badge
swh:1:dir:b09380205ed372b3c80d9423d9c6f5d70cdd352a
origin badgerevision badge
swh:1:rev:b4af72cf48d8a032675a2e80ed9b480e78e7cdff
origin badgesnapshot badge
swh:1:snp:bf7fd2bc2d3f35378e04541f69e2c95ba967e971

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: b4af72cf48d8a032675a2e80ed9b480e78e7cdff authored by Alexis Lebis on 09 November 2023, 08:54:25 UTC
modified mut function to prevent rn to draw from an existing value and looping until ok.
Tip revision: b4af72c
data_analysis.py
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 25 15:47:42 2023

@author: luis.pinos-ullauri
"""

# -*- coding: utf-8 -*-
"""
Created on Fri Aug 25 14:36:37 2023

@author: luis.pinos-ullauri
"""

import read_functions as rdf
import math
import pandas as pd
import numpy as np
from scipy.special import expit

######################## User Defined Functions ###############################

### Function that returns the overall fitness of the solution across all soft skill dimensions
### It checks whether the fitness amongst the different dimensions is compensated or not
### as well as which scoring function to use
def fitness_func(ga_instance, solution, solution_idx):
    if comp:
        fitness=0
    else:
        fitness=1
    for i in range(10):#soft skill id from 0 to 9
        estimated_outcome=soft_skill_estimation_mean(thresholds, courses_effects, theta[i], solution,i)
        if score_func==1:
            score=linear(estimated_outcome,desired_outcome[i])
        elif score_func==2:
            score=logistic(estimated_outcome,desired_outcome[i])
            
        if comp:
            fitness=fitness+score*(1/10)
        else:
            fitness=fitness*score
    return fitness

### Linear scoring function
def linear(estimated_skill,goal_skill):
    #function min value
    f_min=min_skill-goal_skill
    #function max value
    f_max=max_skill-goal_skill    
    return (estimated_skill-goal_skill-f_min)/(f_max-f_min)
  
### Logistic scoring function    
def logistic(estimated_skill,goal_skill):
    #crossing value with linear function at estimated_goal=goal_skill
    fcrossing=(goal_skill-min_skill)/(max_skill-min_skill)
    return (1)/(1+((1-fcrossing)/fcrossing)*pow(math.e,3*(goal_skill-estimated_skill)))

### Function that estimates the soft skill mean based on the ordinal logistic regression model
### It calculates the probability of each level and estimates the mean SUM x*P(X=x)
def soft_skill_estimation_mean(thresholds,courses_effects,theta,solution,soft_skill_id):
    linear_combination=0
    for i in range(len(solution)):
        if solution[i]!=0 and solution[i]!=104 and solution[i]!=105 and solution[i]!=106:
            linear_combination=linear_combination+courses_effects.iloc[soft_skill_id,0]+courses_effects.iloc[soft_skill_id,solution[i]]
        elif solution[i]==104 or solution[i]==105:
            linear_combination=linear_combination+courses_effects.iloc[soft_skill_id,0]+courses_effects.iloc[soft_skill_id,solution[i]-1]
        elif solution[i]==103 or solution[i]==106:
            linear_combination=linear_combination+courses_effects.iloc[soft_skill_id,0]
    linear_combination=linear_combination+theta
    eta12=thresholds.iloc[soft_skill_id,0]-linear_combination
    eta23=thresholds.iloc[soft_skill_id,1]-linear_combination
    eta34=thresholds.iloc[soft_skill_id,2]-linear_combination
    p_1=expit(eta12)
    p_2=expit(eta23)-p_1
    p_3=expit(eta34)-p_1-p_2
    p_4=1-p_3-p_2-p_1
    expected_outcome=1*p_1+2*p_2+3*p_3+4*p_4
    return expected_outcome



################## End of  User Defined Functions #############################

################## Data Analysis ######################


#Read real data set
real_data=rdf.read_real_data()
#Considering only stage 2
real_data_stage2=real_data.loc[real_data["stage"]==2]
real_data_stage2=real_data_stage2.loc[real_data_stage2["N_courses_followed"]>5]
real_data_stage2=real_data_stage2.loc[real_data_stage2["N_courses_followed"]<12]
#real_data_stage2=real_data_stage2.loc[real_data_stage2["domain_id"]==1]
min_skill=1#Minimum Soft skill proficiency
max_skill=4#Maximum Soft skill proficiency
#Compensatory boolean variable
comp=False
#Score function flag variable
score_func=2#Linear
#Read recommendations
recommendations=rdf.read_recommendations(score_func,comp)
real_data_stage2=real_data_stage2.reset_index(drop=True)
#Thresholds
thresholds=rdf.get_thresholds()
#Course Effects
courses_effects=rdf.get_courses_effects()
comparison=pd.DataFrame(np.zeros(shape=(len(real_data_stage2),5)))
for i in range(len(real_data_stage2)):
    student_id=real_data_stage2.iloc[i,0]
    domain_id=real_data_stage2.iloc[i,26]
    N_courses_followed=real_data_stage2.iloc[i,25]
    #Student Effect
    theta=rdf.get_student_random_effect(student_id)
    #Desired outcome
    desired_outcome=rdf.get_desired_standard(domain_id)
    #get possible courses
    possible_courses=rdf.get_courses_domain(domain_id)
    actual_courses=real_data_stage2.iloc[i,13:24].values.flatten().tolist()
    actual_courses=actual_courses[0:N_courses_followed]
    for j in range(len(actual_courses)):
        actual_courses[j]=int(actual_courses[j]) 
    #send that list as 2nd parameter
    real_fitness=fitness_func(None,actual_courses,0)
    recommendation_fitness=recommendations.iloc[i,11]
    comparison.iloc[i,0]=student_id
    comparison.iloc[i,1]=domain_id
    comparison.iloc[i,2]=recommendation_fitness
    comparison.iloc[i,3]=real_fitness
    comparison.iloc[i,4]=(recommendation_fitness-real_fitness)/abs(real_fitness)
    
comparison.columns=['student_id','domain_id','recommendation_fitness','real_fitness','increase']

if score_func==1 and comp:
    comparison.to_csv("./real_data/comparison_lin_comp.csv")
if score_func==1 and not comp:
    comparison.to_csv("./real_data/comparison_lin_parcomp.csv")
if score_func==2 and comp:
    comparison.to_csv("./real_data/comparison_quad_comp.csv")
if score_func==2 and not comp:
    comparison.to_csv("./real_data/comparison_quad_parcomp.csv")
if score_func==3 and comp:
    comparison.to_csv("./real_data/comparison_exp_comp.csv")
if score_func==3 and not comp:
    comparison.to_csv("./real_data/comparison_exp_parcomp.csv")







################# End of Brute Force Estimation Computing Time ################

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API