|
|
@ -19,6 +19,7 @@ from bayes_opt import BayesianOptimization |
|
|
|
from sklearn.model_selection import cross_validate |
|
|
|
from sklearn.model_selection import cross_validate |
|
|
|
from sklearn.model_selection import cross_val_predict |
|
|
|
from sklearn.model_selection import cross_val_predict |
|
|
|
from sklearn.preprocessing import OneHotEncoder |
|
|
|
from sklearn.preprocessing import OneHotEncoder |
|
|
|
|
|
|
|
from sklearn.feature_selection import mutual_info_classif |
|
|
|
|
|
|
|
|
|
|
|
from statsmodels.stats.outliers_influence import variance_inflation_factor |
|
|
|
from statsmodels.stats.outliers_influence import variance_inflation_factor |
|
|
|
from statsmodels.tools.tools import add_constant |
|
|
|
from statsmodels.tools.tools import add_constant |
|
|
@ -466,7 +467,7 @@ def executeModel(): |
|
|
|
svc_bayesopt = BayesianOptimization(estimator, params) |
|
|
|
svc_bayesopt = BayesianOptimization(estimator, params) |
|
|
|
svc_bayesopt.maximize(init_points=5, n_iter=25, acq='ucb') |
|
|
|
svc_bayesopt.maximize(init_points=5, n_iter=25, acq='ucb') |
|
|
|
bestParams = svc_bayesopt.max['params'] |
|
|
|
bestParams = svc_bayesopt.max['params'] |
|
|
|
estimator = SVC(C=bestParams.get('C'), gamma=bestParams.get('gamma'), probability=True) |
|
|
|
estimator = SVC(C=bestParams.get('C'), gamma=bestParams.get('gamma'), probability=True, random_state=RANDOM_SEED) |
|
|
|
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') |
|
|
@ -540,8 +541,19 @@ def Seperation(): |
|
|
|
concatDF1 = pd.concat([DataRows1, hotEncoderDF1], axis=1) |
|
|
|
concatDF1 = pd.concat([DataRows1, hotEncoderDF1], axis=1) |
|
|
|
corrMatrixComb1 = concatDF1.corr() |
|
|
|
corrMatrixComb1 = concatDF1.corr() |
|
|
|
corrMatrixComb1 = corrMatrixComb1.iloc[:,-len(uniqueTarget1):] |
|
|
|
corrMatrixComb1 = corrMatrixComb1.iloc[:,-len(uniqueTarget1):] |
|
|
|
|
|
|
|
X1 = add_constant(DataRows1.dropna()) |
|
|
|
|
|
|
|
VIF1 = pd.Series([variance_inflation_factor(X1.values, i) |
|
|
|
|
|
|
|
for i in range(X1.shape[1])], |
|
|
|
|
|
|
|
index=X1.columns) |
|
|
|
|
|
|
|
if (len(targetRows1Arr) > 2): |
|
|
|
|
|
|
|
MI1 = mutual_info_classif(DataRows1, targetRows1Arr) |
|
|
|
|
|
|
|
MI1List = MI1.tolist() |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
MI1List = [] |
|
|
|
else: |
|
|
|
else: |
|
|
|
corrMatrixComb1 = pd.DataFrame() |
|
|
|
corrMatrixComb1 = pd.DataFrame() |
|
|
|
|
|
|
|
VIF1 = pd.Series() |
|
|
|
|
|
|
|
MI1List = [] |
|
|
|
|
|
|
|
|
|
|
|
if (len(targetRows2Arr) > 0): |
|
|
|
if (len(targetRows2Arr) > 0): |
|
|
|
onehotEncoder2 = OneHotEncoder(sparse=False) |
|
|
|
onehotEncoder2 = OneHotEncoder(sparse=False) |
|
|
@ -551,8 +563,19 @@ def Seperation(): |
|
|
|
concatDF2 = pd.concat([DataRows2, hotEncoderDF2], axis=1) |
|
|
|
concatDF2 = pd.concat([DataRows2, hotEncoderDF2], axis=1) |
|
|
|
corrMatrixComb2 = concatDF2.corr() |
|
|
|
corrMatrixComb2 = concatDF2.corr() |
|
|
|
corrMatrixComb2 = corrMatrixComb2.iloc[:,-len(uniqueTarget2):] |
|
|
|
corrMatrixComb2 = corrMatrixComb2.iloc[:,-len(uniqueTarget2):] |
|
|
|
|
|
|
|
X2 = add_constant(DataRows2.dropna()) |
|
|
|
|
|
|
|
VIF2 = pd.Series([variance_inflation_factor(X2.values, i) |
|
|
|
|
|
|
|
for i in range(X2.shape[1])], |
|
|
|
|
|
|
|
index=X2.columns) |
|
|
|
|
|
|
|
if (len(targetRows2Arr) > 2): |
|
|
|
|
|
|
|
MI2 = mutual_info_classif(DataRows2, targetRows2Arr) |
|
|
|
|
|
|
|
MI2List = MI2.tolist() |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
MI2List = [] |
|
|
|
else: |
|
|
|
else: |
|
|
|
corrMatrixComb2 = pd.DataFrame() |
|
|
|
corrMatrixComb2 = pd.DataFrame() |
|
|
|
|
|
|
|
VIF2 = pd.Series() |
|
|
|
|
|
|
|
MI2List = [] |
|
|
|
|
|
|
|
|
|
|
|
if (len(targetRows3Arr) > 0): |
|
|
|
if (len(targetRows3Arr) > 0): |
|
|
|
onehotEncoder3 = OneHotEncoder(sparse=False) |
|
|
|
onehotEncoder3 = OneHotEncoder(sparse=False) |
|
|
@ -562,8 +585,21 @@ def Seperation(): |
|
|
|
concatDF3 = pd.concat([DataRows3, hotEncoderDF3], axis=1) |
|
|
|
concatDF3 = pd.concat([DataRows3, hotEncoderDF3], axis=1) |
|
|
|
corrMatrixComb3 = concatDF3.corr() |
|
|
|
corrMatrixComb3 = concatDF3.corr() |
|
|
|
corrMatrixComb3 = corrMatrixComb3.iloc[:,-len(uniqueTarget3):] |
|
|
|
corrMatrixComb3 = corrMatrixComb3.iloc[:,-len(uniqueTarget3):] |
|
|
|
|
|
|
|
X3 = add_constant(DataRows3.dropna()) |
|
|
|
|
|
|
|
VIF3 = pd.Series([variance_inflation_factor(X3.values, i) |
|
|
|
|
|
|
|
for i in range(X3.shape[1])], |
|
|
|
|
|
|
|
index=X3.columns) |
|
|
|
|
|
|
|
if (len(targetRows3Arr) > 2): |
|
|
|
|
|
|
|
print(DataRows3) |
|
|
|
|
|
|
|
print(targetRows3Arr) |
|
|
|
|
|
|
|
MI3 = mutual_info_classif(DataRows3, targetRows3Arr) |
|
|
|
|
|
|
|
MI3List = MI3.tolist() |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
MI3List = [] |
|
|
|
else: |
|
|
|
else: |
|
|
|
corrMatrixComb3 = pd.DataFrame() |
|
|
|
corrMatrixComb3 = pd.DataFrame() |
|
|
|
|
|
|
|
VIF3 = pd.Series() |
|
|
|
|
|
|
|
MI3List = [] |
|
|
|
|
|
|
|
|
|
|
|
if (len(targetRows4Arr) > 0): |
|
|
|
if (len(targetRows4Arr) > 0): |
|
|
|
onehotEncoder4 = OneHotEncoder(sparse=False) |
|
|
|
onehotEncoder4 = OneHotEncoder(sparse=False) |
|
|
@ -573,16 +609,19 @@ def Seperation(): |
|
|
|
concatDF4 = pd.concat([DataRows4, hotEncoderDF4], axis=1) |
|
|
|
concatDF4 = pd.concat([DataRows4, hotEncoderDF4], axis=1) |
|
|
|
corrMatrixComb4 = concatDF4.corr() |
|
|
|
corrMatrixComb4 = concatDF4.corr() |
|
|
|
corrMatrixComb4 = corrMatrixComb4.iloc[:,-len(uniqueTarget4):] |
|
|
|
corrMatrixComb4 = corrMatrixComb4.iloc[:,-len(uniqueTarget4):] |
|
|
|
|
|
|
|
X4 = add_constant(DataRows4.dropna()) |
|
|
|
|
|
|
|
VIF4 = pd.Series([variance_inflation_factor(X4.values, i) |
|
|
|
|
|
|
|
for i in range(X4.shape[1])], |
|
|
|
|
|
|
|
index=X4.columns) |
|
|
|
|
|
|
|
if (len(targetRows4Arr) > 2): |
|
|
|
|
|
|
|
MI4 = mutual_info_classif(DataRows4, targetRows4Arr) |
|
|
|
|
|
|
|
MI4List = MI4.tolist() |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
MI4List = [] |
|
|
|
else: |
|
|
|
else: |
|
|
|
corrMatrixComb4 = pd.DataFrame() |
|
|
|
corrMatrixComb4 = pd.DataFrame() |
|
|
|
|
|
|
|
VIF4 = pd.Series() |
|
|
|
X1 = add_constant(DataRows1.dropna()) |
|
|
|
MI4List = [] |
|
|
|
|
|
|
|
|
|
|
|
VIF1 = pd.Series([variance_inflation_factor(X1.values, i) |
|
|
|
|
|
|
|
for i in range(X1.shape[1])], |
|
|
|
|
|
|
|
index=X1.columns) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(VIF1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
targetRows1ArrDF = pd.DataFrame(targetRows1Arr) |
|
|
|
targetRows1ArrDF = pd.DataFrame(targetRows1Arr) |
|
|
|
targetRows2ArrDF = pd.DataFrame(targetRows2Arr) |
|
|
|
targetRows2ArrDF = pd.DataFrame(targetRows2Arr) |
|
|
@ -630,6 +669,16 @@ def Seperation(): |
|
|
|
packCorr.append(json.dumps(uniqueTarget3)) |
|
|
|
packCorr.append(json.dumps(uniqueTarget3)) |
|
|
|
packCorr.append(json.dumps(uniqueTarget4)) |
|
|
|
packCorr.append(json.dumps(uniqueTarget4)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
packCorr.append(VIF1.to_json()) |
|
|
|
|
|
|
|
packCorr.append(VIF2.to_json()) |
|
|
|
|
|
|
|
packCorr.append(VIF3.to_json()) |
|
|
|
|
|
|
|
packCorr.append(VIF4.to_json()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
packCorr.append(json.dumps(MI1List)) |
|
|
|
|
|
|
|
packCorr.append(json.dumps(MI2List)) |
|
|
|
|
|
|
|
packCorr.append(json.dumps(MI3List)) |
|
|
|
|
|
|
|
packCorr.append(json.dumps(MI4List)) |
|
|
|
|
|
|
|
|
|
|
|
return 'Everything Okay' |
|
|
|
return 'Everything Okay' |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/data/returnCorrelations', methods=["GET", "POST"]) |
|
|
|
@app.route('/data/returnCorrelations', methods=["GET", "POST"]) |
|
|
|