|
|
@ -110,6 +110,12 @@ def reset(): |
|
|
|
|
|
|
|
|
|
|
|
global target_namesLoc |
|
|
|
global target_namesLoc |
|
|
|
target_namesLoc = [] |
|
|
|
target_namesLoc = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global featureCompareData |
|
|
|
|
|
|
|
featureCompareData = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global columnsKeep |
|
|
|
|
|
|
|
columnsKeep = [] |
|
|
|
return 'The reset was done!' |
|
|
|
return 'The reset was done!' |
|
|
|
|
|
|
|
|
|
|
|
# retrieve data from client and select the correct data set |
|
|
|
# retrieve data from client and select the correct data set |
|
|
@ -199,9 +205,14 @@ def retrieveFileName(): |
|
|
|
keyFirstTime = True |
|
|
|
keyFirstTime = True |
|
|
|
|
|
|
|
|
|
|
|
global target_namesLoc |
|
|
|
global target_namesLoc |
|
|
|
|
|
|
|
|
|
|
|
target_namesLoc = [] |
|
|
|
target_namesLoc = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global featureCompareData |
|
|
|
|
|
|
|
featureCompareData = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global columnsKeep |
|
|
|
|
|
|
|
columnsKeep = [] |
|
|
|
|
|
|
|
|
|
|
|
DataRawLength = -1 |
|
|
|
DataRawLength = -1 |
|
|
|
DataRawLengthTest = -1 |
|
|
|
DataRawLengthTest = -1 |
|
|
|
data = json.loads(fileName) |
|
|
|
data = json.loads(fileName) |
|
|
@ -379,13 +390,15 @@ def dataSetSelection(): |
|
|
|
global XData, yData, RANDOM_SEED |
|
|
|
global XData, yData, RANDOM_SEED |
|
|
|
XData, yData = ArrayDataResults, AllTargetsFloatValues |
|
|
|
XData, yData = ArrayDataResults, AllTargetsFloatValues |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XData.columns = [str(col) + ' (F'+str(idx+1)+')' for idx, col in enumerate(XData.columns)] |
|
|
|
|
|
|
|
|
|
|
|
global XDataStored, yDataStored |
|
|
|
global XDataStored, yDataStored |
|
|
|
XDataStored = XData.copy() |
|
|
|
XDataStored = XData.copy() |
|
|
|
yDataStored = yData.copy() |
|
|
|
yDataStored = yData.copy() |
|
|
|
|
|
|
|
|
|
|
|
warnings.simplefilter('ignore') |
|
|
|
warnings.simplefilter('ignore') |
|
|
|
|
|
|
|
|
|
|
|
executeModel([]) |
|
|
|
executeModel([], 0) |
|
|
|
|
|
|
|
|
|
|
|
return 'Everything is okay' |
|
|
|
return 'Everything is okay' |
|
|
|
|
|
|
|
|
|
|
@ -400,7 +413,7 @@ def create_global_function(): |
|
|
|
return np.mean(result['test_score']) |
|
|
|
return np.mean(result['test_score']) |
|
|
|
|
|
|
|
|
|
|
|
# check this issue later because we are not getting the same results |
|
|
|
# check this issue later because we are not getting the same results |
|
|
|
def executeModel(exeCall): |
|
|
|
def executeModel(exeCall, flagEx): |
|
|
|
|
|
|
|
|
|
|
|
global keyFirstTime |
|
|
|
global keyFirstTime |
|
|
|
global estimator |
|
|
|
global estimator |
|
|
@ -412,6 +425,8 @@ def executeModel(exeCall): |
|
|
|
global previousState |
|
|
|
global previousState |
|
|
|
scores = [] |
|
|
|
scores = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XData = XDataStored.copy() |
|
|
|
|
|
|
|
|
|
|
|
if (keyFirstTime): |
|
|
|
if (keyFirstTime): |
|
|
|
create_global_function() |
|
|
|
create_global_function() |
|
|
|
params = {"C": (0.0001, 10000), "gamma": (0.0001, 10000)} |
|
|
|
params = {"C": (0.0001, 10000), "gamma": (0.0001, 10000)} |
|
|
@ -419,12 +434,20 @@ def executeModel(exeCall): |
|
|
|
svc_bayesopt.maximize(init_points=130, n_iter=20, acq='ucb') |
|
|
|
svc_bayesopt.maximize(init_points=130, n_iter=20, acq='ucb') |
|
|
|
bestParams = svc_bayesopt.max['params'] |
|
|
|
bestParams = svc_bayesopt.max['params'] |
|
|
|
estimator = SVC(C=bestParams.get('C'), gamma=bestParams.get('gamma'), probability=True, random_state=RANDOM_SEED) |
|
|
|
estimator = SVC(C=bestParams.get('C'), gamma=bestParams.get('gamma'), probability=True, random_state=RANDOM_SEED) |
|
|
|
featureImportanceData = estimatorFeatureSelection(estimator) |
|
|
|
featureImportanceData = estimatorFeatureSelection(XData, estimator) |
|
|
|
|
|
|
|
|
|
|
|
XData = XDataStored.copy() |
|
|
|
|
|
|
|
if (len(exeCall) != 0): |
|
|
|
if (len(exeCall) != 0): |
|
|
|
|
|
|
|
if (flagEx == 1): |
|
|
|
XData = XData.drop(XData.columns[exeCall], axis=1) |
|
|
|
XData = XData.drop(XData.columns[exeCall], axis=1) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
columnsKeepNew = [] |
|
|
|
|
|
|
|
columns = XDataGen.columns.values.tolist() |
|
|
|
|
|
|
|
for indx, col in enumerate(columns): |
|
|
|
|
|
|
|
if indx in exeCall: |
|
|
|
|
|
|
|
columnsKeepNew.append(col) |
|
|
|
|
|
|
|
XDataTemp = XDataGen[columnsKeepNew] |
|
|
|
|
|
|
|
XData[columnsKeepNew] = XDataTemp.values |
|
|
|
|
|
|
|
print(XData) |
|
|
|
estimator.fit(XData, yData) |
|
|
|
estimator.fit(XData, yData) |
|
|
|
yPredict = estimator.predict(XData) |
|
|
|
yPredict = estimator.predict(XData) |
|
|
|
yPredictProb = cross_val_predict(estimator, XData, yData, cv=crossValidation, method='predict_proba') |
|
|
|
yPredictProb = cross_val_predict(estimator, XData, yData, cv=crossValidation, method='predict_proba') |
|
|
@ -465,24 +488,24 @@ def executeModel(exeCall): |
|
|
|
|
|
|
|
|
|
|
|
return 'Everything Okay' |
|
|
|
return 'Everything Okay' |
|
|
|
|
|
|
|
|
|
|
|
def estimatorFeatureSelection(clf): |
|
|
|
def estimatorFeatureSelection(Data, clf): |
|
|
|
|
|
|
|
|
|
|
|
resultsFS = [] |
|
|
|
resultsFS = [] |
|
|
|
permList = [] |
|
|
|
permList = [] |
|
|
|
PerFeatureAccuracy = [] |
|
|
|
PerFeatureAccuracy = [] |
|
|
|
PerFeatureAccuracyAll = [] |
|
|
|
PerFeatureAccuracyAll = [] |
|
|
|
|
|
|
|
|
|
|
|
perm = PermutationImportance(clf, cv = None, refit = True, n_iter = 25).fit(XData, yData) |
|
|
|
perm = PermutationImportance(clf, cv = None, refit = True, n_iter = 25).fit(Data, yData) |
|
|
|
permList.append(perm.feature_importances_) |
|
|
|
permList.append(perm.feature_importances_) |
|
|
|
n_feats = XData.shape[1] |
|
|
|
n_feats = Data.shape[1] |
|
|
|
PerFeatureAccuracy = [] |
|
|
|
PerFeatureAccuracy = [] |
|
|
|
for i in range(n_feats): |
|
|
|
for i in range(n_feats): |
|
|
|
scores = model_selection.cross_val_score(clf, XData.values[:, i].reshape(-1, 1), yData, cv=crossValidation) |
|
|
|
scores = model_selection.cross_val_score(clf, Data.values[:, i].reshape(-1, 1), yData, cv=crossValidation) |
|
|
|
PerFeatureAccuracy.append(scores.mean()) |
|
|
|
PerFeatureAccuracy.append(scores.mean()) |
|
|
|
PerFeatureAccuracyAll.append(PerFeatureAccuracy) |
|
|
|
PerFeatureAccuracyAll.append(PerFeatureAccuracy) |
|
|
|
|
|
|
|
|
|
|
|
clf.fit(XData, yData) |
|
|
|
clf.fit(Data, yData) |
|
|
|
yPredict = clf.predict(XData) |
|
|
|
yPredict = clf.predict(Data) |
|
|
|
yPredict = np.nan_to_num(yPredict) |
|
|
|
yPredict = np.nan_to_num(yPredict) |
|
|
|
|
|
|
|
|
|
|
|
perm_imp_eli5PD = pd.DataFrame(permList) |
|
|
|
perm_imp_eli5PD = pd.DataFrame(permList) |
|
|
@ -492,9 +515,9 @@ def estimatorFeatureSelection(clf): |
|
|
|
PerFeatureAccuracyPandas = PerFeatureAccuracyPandas.to_json() |
|
|
|
PerFeatureAccuracyPandas = PerFeatureAccuracyPandas.to_json() |
|
|
|
|
|
|
|
|
|
|
|
bestfeatures = SelectKBest(score_func=chi2, k='all') |
|
|
|
bestfeatures = SelectKBest(score_func=chi2, k='all') |
|
|
|
fit = bestfeatures.fit(XData,yData) |
|
|
|
fit = bestfeatures.fit(Data,yData) |
|
|
|
dfscores = pd.DataFrame(fit.scores_) |
|
|
|
dfscores = pd.DataFrame(fit.scores_) |
|
|
|
dfcolumns = pd.DataFrame(XData.columns) |
|
|
|
dfcolumns = pd.DataFrame(Data.columns) |
|
|
|
featureScores = pd.concat([dfcolumns,dfscores],axis=1) |
|
|
|
featureScores = pd.concat([dfcolumns,dfscores],axis=1) |
|
|
|
featureScores.columns = ['Specs','Score'] #naming the dataframe columns |
|
|
|
featureScores.columns = ['Specs','Score'] #naming the dataframe columns |
|
|
|
featureScores = featureScores.to_json() |
|
|
|
featureScores = featureScores.to_json() |
|
|
@ -514,6 +537,17 @@ def sendFeatureImportance(): |
|
|
|
} |
|
|
|
} |
|
|
|
return jsonify(response) |
|
|
|
return jsonify(response) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/data/sendFeatImpComp', methods=["GET", "POST"]) |
|
|
|
|
|
|
|
def sendFeatureImportanceComp(): |
|
|
|
|
|
|
|
global featureCompareData |
|
|
|
|
|
|
|
global columnsKeep |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response = { |
|
|
|
|
|
|
|
'ImportanceCompare': featureCompareData, |
|
|
|
|
|
|
|
'FeatureNames': columnsKeep |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return jsonify(response) |
|
|
|
|
|
|
|
|
|
|
|
def solve(sclf,XData,yData,crossValidation,scoringIn,loop): |
|
|
|
def solve(sclf,XData,yData,crossValidation,scoringIn,loop): |
|
|
|
scoresLoc = [] |
|
|
|
scoresLoc = [] |
|
|
|
temp = model_selection.cross_val_score(sclf, XData, yData, cv=crossValidation, scoring=scoringIn, n_jobs=-1) |
|
|
|
temp = model_selection.cross_val_score(sclf, XData, yData, cv=crossValidation, scoring=scoringIn, n_jobs=-1) |
|
|
@ -1060,6 +1094,16 @@ def Seperation(): |
|
|
|
global packCorr |
|
|
|
global packCorr |
|
|
|
packCorr = [] |
|
|
|
packCorr = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AbbreviatedFeatures = [] |
|
|
|
|
|
|
|
for index, value in enumerate(XData.columns.values.tolist()): |
|
|
|
|
|
|
|
realIndex = index + 1 |
|
|
|
|
|
|
|
AbbreviatedFeatures.append('F'+str(realIndex)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AbbreviatedFeaturesOriginal = [] |
|
|
|
|
|
|
|
for index, value in enumerate(XDataStored.columns.values.tolist()): |
|
|
|
|
|
|
|
realIndex = index + 1 |
|
|
|
|
|
|
|
AbbreviatedFeaturesOriginal.append('F'+str(realIndex)) |
|
|
|
|
|
|
|
|
|
|
|
packCorr.append(list(XData.columns.values.tolist())) |
|
|
|
packCorr.append(list(XData.columns.values.tolist())) |
|
|
|
packCorr.append(json.dumps(target_names)) |
|
|
|
packCorr.append(json.dumps(target_names)) |
|
|
|
packCorr.append(json.dumps(probabilityPredictions)) |
|
|
|
packCorr.append(json.dumps(probabilityPredictions)) |
|
|
@ -1101,6 +1145,8 @@ def Seperation(): |
|
|
|
packCorr.append(json.dumps(MI5List)) |
|
|
|
packCorr.append(json.dumps(MI5List)) |
|
|
|
|
|
|
|
|
|
|
|
packCorr.append(list(XDataStored.columns.values.tolist())) |
|
|
|
packCorr.append(list(XDataStored.columns.values.tolist())) |
|
|
|
|
|
|
|
packCorr.append(AbbreviatedFeatures) |
|
|
|
|
|
|
|
packCorr.append(AbbreviatedFeaturesOriginal) |
|
|
|
|
|
|
|
|
|
|
|
return 'Everything Okay' |
|
|
|
return 'Everything Okay' |
|
|
|
|
|
|
|
|
|
|
@ -1140,5 +1186,55 @@ def ManipulFeat(): |
|
|
|
featureProcess = request.get_data().decode('utf8').replace("'", '"') |
|
|
|
featureProcess = request.get_data().decode('utf8').replace("'", '"') |
|
|
|
featureProcess = json.loads(featureProcess) |
|
|
|
featureProcess = json.loads(featureProcess) |
|
|
|
featureProcessExtract = featureProcess['featureAddRem'] |
|
|
|
featureProcessExtract = featureProcess['featureAddRem'] |
|
|
|
executeModel(featureProcessExtract) |
|
|
|
executeModel(featureProcessExtract, 1) |
|
|
|
|
|
|
|
return 'Okay' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cross_origin(origin='localhost',headers=['Content-Type','Authorization']) |
|
|
|
|
|
|
|
@app.route('/data/AddRemGenFun', methods=["GET", "POST"]) |
|
|
|
|
|
|
|
def ManipulFeatGen(): |
|
|
|
|
|
|
|
featureProcess = request.get_data().decode('utf8').replace("'", '"') |
|
|
|
|
|
|
|
featureProcess = json.loads(featureProcess) |
|
|
|
|
|
|
|
featureProcessExtract = featureProcess['featureAddRemGen'] |
|
|
|
|
|
|
|
executeModel(featureProcessExtract, 2) |
|
|
|
|
|
|
|
return 'Okay' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cross_origin(origin='localhost',headers=['Content-Type','Authorization']) |
|
|
|
|
|
|
|
@app.route('/data/compareFun', methods=["GET", "POST"]) |
|
|
|
|
|
|
|
def CompareFunPy(): |
|
|
|
|
|
|
|
global featureCompareData |
|
|
|
|
|
|
|
global columnsKeep |
|
|
|
|
|
|
|
global XDataGen |
|
|
|
|
|
|
|
global IDsToCompare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
retrieveComparison = request.get_data().decode('utf8').replace("'", '"') |
|
|
|
|
|
|
|
retrieveComparison = json.loads(retrieveComparison) |
|
|
|
|
|
|
|
compareMode = retrieveComparison['compareNumber'] |
|
|
|
|
|
|
|
IDsToCompare = retrieveComparison['getIDs'] |
|
|
|
|
|
|
|
XDataGen = XDataStored.copy() |
|
|
|
|
|
|
|
columns = XData.columns.values.tolist() |
|
|
|
|
|
|
|
columnsKeep = [] |
|
|
|
|
|
|
|
columnsKeepID = [] |
|
|
|
|
|
|
|
for indx, col in enumerate(columns): |
|
|
|
|
|
|
|
if indx in IDsToCompare: |
|
|
|
|
|
|
|
columnsKeep.append(col) |
|
|
|
|
|
|
|
columnsKeepID.append(str(indx+1)) |
|
|
|
|
|
|
|
if (compareMode == 1): |
|
|
|
|
|
|
|
XDataGen = XData[columnsKeep] |
|
|
|
|
|
|
|
feat1 = XDataGen.iloc[:,0] |
|
|
|
|
|
|
|
feat2 = XDataGen.iloc[:,1] |
|
|
|
|
|
|
|
XDataGen['F'+columnsKeepID[0]+'+F'+columnsKeepID[1]] = feat1 + feat2 |
|
|
|
|
|
|
|
XDataGen['|F'+columnsKeepID[0]+'-F'+columnsKeepID[1]+'|'] = abs(feat1 - feat2) |
|
|
|
|
|
|
|
XDataGen['F'+columnsKeepID[0]+'xF'+columnsKeepID[1]] = feat1 + feat2 |
|
|
|
|
|
|
|
XDataGen['F'+columnsKeepID[0]+'/F'+columnsKeepID[1]] = feat1 / feat2 |
|
|
|
|
|
|
|
XDataGen['F'+columnsKeepID[1]+'/F'+columnsKeepID[0]] = feat2 / feat1 |
|
|
|
|
|
|
|
columnsKeep.append('F'+columnsKeepID[0]+'+F'+columnsKeepID[1]) |
|
|
|
|
|
|
|
columnsKeep.append('|F'+columnsKeepID[0]+'-F'+columnsKeepID[1]+'|') |
|
|
|
|
|
|
|
columnsKeep.append('F'+columnsKeepID[0]+'xF'+columnsKeepID[1]) |
|
|
|
|
|
|
|
columnsKeep.append('F'+columnsKeepID[0]+'/F'+columnsKeepID[1]) |
|
|
|
|
|
|
|
columnsKeep.append('F'+columnsKeepID[1]+'/F'+columnsKeepID[0]) |
|
|
|
|
|
|
|
elif (compareMode == 2): |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
featureCompareData = estimatorFeatureSelection(XDataGen, estimator) |
|
|
|
return 'Okay' |
|
|
|
return 'Okay' |