I have a sample of 1000 customers who have a fixed score(R) All the customers must answer 137 questions. For each question answered we have to give it a score(T) and the score should be between 0 and 24 inclusive. and so we have to optimize 137 scores so that we get maximum F1 Measure. i will have to load my data to get F1 measure for 1000 customers.
sumS = sum(T)*4
if T>100 than H=1 else 0
SR = fixed value( either 0 or 1 for each customer)
Recall and precision will be calculated for all the 1000 customers
Recall = number of customers having R>0 and SR>0/no. of customers having R>0
Precision = number of customers having R>0 and SR>0/no. of customers having SR>0
Objective = (2*Recall*Precision/Recall+Precision)
I would highly appreciate your input. i tried to do apply my logic in the following code but its not solvable.
from gekko import GEKKO
import numpy as np
m = GEKKO(remote=False)
nq = 137 # number of questions
# select 24 questions out of 137
S = m.Array(m.Var,(nq) ,integer=True)
for i in range(nq):
S[i].value = 2
S[i].lower = 0
S[i].upper = 24
sumS = m.sum(S)*4.17
HR= m.if3(sumS-101 , 0 ,1)
SR = m.FV(value=0, lb=0,ub=1,integer=True)
#countifs = m.sum([m.if3(H[i]*S[i]-0.1,0,1) for i in range(nq)])
countifs = m.if3(HR*SR-0.1, 0,1)
#countSR = m.sum(SR for i in range (nq))
#countHR = m.sum(HR for i in range (nq))
Recall = m.Intermediate(countifs/SR)
Precision = m.Intermediate(countifs/HR)
m.Maximize(2*Recall*Precision/(Recall+Precision))
# solve
m.solve(disp=False)
print('T: ', T.value)
print('HR: ', HR.value)
print('SR:' , SR.value)
print('Precision', Precision.value)
print('Recall', Recall.value)
print('S: ', [S[i].value[0] for i in range(nq)])
Here is a sample program that may help you get started.
Here is a sample solution with
nq=7
so that the solution isn't too long.