Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLM.jl and DataFrames.jl #27

Closed
odow opened this issue Jun 9, 2024 · 0 comments · Fixed by #32
Closed

GLM.jl and DataFrames.jl #27

odow opened this issue Jun 9, 2024 · 0 comments · Fixed by #32

Comments

@odow
Copy link
Collaborator

odow commented Jun 9, 2024

Our vector-in/vector-out syntax keeps things simple. But it doesn't really help real-world use-cases.

It'd be nice to have a good solution for the interaction of GLM.jl and DataFrames.

This example is cribbed from https://gurobi-machinelearning.readthedocs.io/en/stable/auto_examples/example2_student_admission.html

using JuMP
import CSV
import DataFrames
import Downloads
import GLM
import Ipopt
import MathOptAI
function read_df(filename)
    url = "https://raw.githubusercontent.com/INFORMSJoC/2020.1023/master/data/"
    data = Downloads.download(url * filename)
    return CSV.read(data, DataFrames.DataFrame)
end
historical_df = read_df("college_student_enroll-s1-1.csv")
model_glm = GLM.glm(
    GLM.@formula(enroll ~ 0 + merit + SAT + GPA),
    historical_df,
    GLM.Bernoulli(),
)
application_df = read_df("college_applications6000.csv")
n_students = size(application_df, 1)
model = Model(Ipopt.Optimizer)
application_df.merit = @variable(model, 0 <= x_merit[1:n_students] <= 2.5)
y_enroll = MathOptAI.add_predictor(model, model_glm, application_df)
@objective(model, Max, sum(y_enroll))
@constraint(model, sum(x_merit) <= 0.2 * n_students)
optimize!(model)
@assert is_solved_and_feasible(model)
value.(x_merit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant