From c15b556c82eaf906804044144e572335aab4233d Mon Sep 17 00:00:00 2001 From: Angelos Chatzimparmpas Date: Wed, 5 Aug 2020 14:09:56 +0200 Subject: [PATCH] round --- __pycache__/run.cpython-37.pyc | Bin 13061 -> 18163 bytes frontend/src/components/Main.vue | 25 ++- run.py | 251 +++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+), 1 deletion(-) diff --git a/__pycache__/run.cpython-37.pyc b/__pycache__/run.cpython-37.pyc index f38a6eeb0ea8d47d88e76ee459808db229ca89cf..9e55b2ae94c2106df54f3e7f2153f0bcef95318a 100644 GIT binary patch delta 5860 zcmb_g3vgUj89wLUo6Wu-d9_JOo1|@$P1`(nw`oh$mNsdmGo>)JwlvC=?cQygu-Q$| z-bh=|dYMV_F=LrJ*U=GCH-pS5IzTBZ0#bb83sC`IS5Z{t4L(qLDB%D9yV*xtQD#i$ ze&_%GbMAlt@0`2m{`X#Y=%tg~zs=`!Gx)n~uIGSLe#F06=~Pa4-^xwBM_+YVwoXsISx4!&TPl+HMx!@C;*TRw-v&%!G!y!CwFl%ySry?41f@2AkwM*Oikz zrx}XWCe>M@fTF2GU;n(IluHwdZb@xI=fCeq% z)@$=#>7C<4?8sI7nBfBt1O{{wx(PjiOmeA6b=E0ex_5|GCS&;XfkHxaypWFcnExfe zx1Zh{|8sgiNYAX8EXXgoFuw)qjaE$GdYHbqo!%*aR8kjNRPretT?5|nq==*KNM#c76r4B#hV8(y zal>xdmAqy+Gc`S9#Epqex)4Tu7)~&4HI*5M>tx0wb`9V_zc>i~aKLua1i}2kG|ZbY z4f7^U!@LjQZrdlAx2?90p0#SmR+-yQGV_ODe$W_wOc$TdFhwHcjFl$tIQJ1`NAe$%g%{WW!EZvQ=Hx zwG&KgBe27#>ESAB%v)JdEQ*uGMIPa1{ zh`87=-Fc5(3}&<8p7g@*-3(7VkM2FGORCEQt$)p5Z8U6(rJV~$R_J_cs9&(R1d6P_e1<8m=fsM1C;OmMgv?vIIH9? zkQd||Va1lFwQ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F(`6e44&s$4|I<8V1eVMV5u(AhD0zu$PBM8U6nn65^3<3s7=khi> zOZW1Z&~1vw&ZOu5??LoIex7Ih>CRX#ed(ym6B;Rj5_y3c0>&2U*K;pFJpmz(RcyD6 zV`Z0+MwfBbYjoF0#qlvcH9nfc31WF0M$N+XmGPmlk2S>E$8iiCU$scZ0zNUEb*s_M zd5uKbwYN4Mk7R+{i2JTx@%%>2H!5}`Su@IS6xpB{%aYrS(rs>S);yxKIN`fjs-EkN zlyJ)5V542z^sw|err*sMLfmtG%P?W4FSkOa6{@XJ!#%p;8!PUc9&iss;2ws+Jq$IR zW>;{*@JZz@ISQ00P{SyKCf^|Imfsu^0npT{s8OKdOsgU<5E8{o2Ua_p#+Z?=L+w7{N zNNGcA8`5xpzI`hfUEi=}+ { console.log('Sent the thresholds to the server side!') - this.returnCorrel() + this.returnCorrelTranformed() }) .catch(error => { console.log(error) @@ -503,7 +504,29 @@ export default Vue.extend({ .catch(error => { console.log(error) }) + }, + returnCorrelTranformed () { + const path = `http://127.0.0.1:5000/data/returnCorrelationsTransformed` + + const axiosConfig = { + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token', + 'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE, OPTIONS' + } } + axios.get(path, axiosConfig) + .then(response => { + console.log('Server successfully send the correlation matrices!') + this.correlResulTranformed = response.data.correlResulTranformed + console.log(this.correlResulTranformed) + this.returnCorrel() + }) + .catch(error => { + console.log(error) + }) + } }, created () { // does the browser support the Navigation Timing API? diff --git a/run.py b/run.py index d57bad5..37c83b8 100644 --- a/run.py +++ b/run.py @@ -474,6 +474,245 @@ def executeModel(): return 'Everything Okay' +def Transformation(quadrant1, quadrant2, quadrant3, quadrant4): + + XDataNumeric = XData.select_dtypes(include='number') + numberOfColumns = len(XDataNumeric.columns) + columns = list(XDataNumeric) + decimals = 0 + + global packCorrTransformed + packCorrTransformed = [] + + for i in columns: + + dicTransf = {} + + d={} + XDataNumericCopy = XDataNumeric.copy() + XDataNumericCopy[i] = XDataNumericCopy[i].round() + for number in range(1,5): + quadrantVariable = str('quadrant%s' % number) + illusion = locals()[quadrantVariable] + d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] + dicTransf["round"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + + d={} + XDataNumericCopy = XDataNumeric.copy() + XDataNumericCopy[i] = np.log(XDataNumericCopy[i]) + XDataNumericCopy[i] = XDataNumericCopy[i].round() + for number in range(1,5): + quadrantVariable = str('quadrant%s' % number) + illusion = locals()[quadrantVariable] + d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] + dicTransf["roundLogE"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + + d={} + XDataNumericCopy = XDataNumeric.copy() + XDataNumericCopy[i] = np.log2(XDataNumericCopy[i]) + XDataNumericCopy[i] = XDataNumericCopy[i].round() + for number in range(1,5): + quadrantVariable = str('quadrant%s' % number) + illusion = locals()[quadrantVariable] + d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] + dicTransf["roundLog2"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + + d={} + XDataNumericCopy = XDataNumeric.copy() + XDataNumericCopy[i] = np.log10(XDataNumericCopy[i]) + XDataNumericCopy[i] = XDataNumericCopy[i].round() + for number in range(1,5): + quadrantVariable = str('quadrant%s' % number) + illusion = locals()[quadrantVariable] + d["DataRows{0}".format(number)] = XDataNumericCopy.iloc[illusion, :] + dicTransf["roundLog10"] = NewComputationTransf(d['DataRows1'], d['DataRows2'], d['DataRows3'], d['DataRows4'], quadrant1, quadrant2, quadrant3, quadrant4) + + packCorrTransformed.append(dicTransf) + + return 'Everything Okay' + +def NewComputationTransf(DataRows1, DataRows2, DataRows3, DataRows4, quadrant1, quadrant2, quadrant3, quadrant4): + + # Main Features + corrMatrix1 = DataRows1.corr() + corrMatrix1 = corrMatrix1.abs() + corrMatrix2 = DataRows2.corr() + corrMatrix2 = corrMatrix2.abs() + corrMatrix3 = DataRows3.corr() + corrMatrix3 = corrMatrix3.abs() + corrMatrix4 = DataRows4.corr() + corrMatrix4 = corrMatrix4.abs() + + DataRows1 = DataRows1.reset_index(drop=True) + DataRows2 = DataRows2.reset_index(drop=True) + DataRows3 = DataRows3.reset_index(drop=True) + DataRows4 = DataRows4.reset_index(drop=True) + + targetRows1 = [yData[i] for i in quadrant1] + targetRows2 = [yData[i] for i in quadrant2] + targetRows3 = [yData[i] for i in quadrant3] + targetRows4 = [yData[i] for i in quadrant4] + + targetRows1Arr = np.array(targetRows1) + targetRows2Arr = np.array(targetRows2) + targetRows3Arr = np.array(targetRows3) + targetRows4Arr = np.array(targetRows4) + + uniqueTarget1 = unique(targetRows1) + uniqueTarget2 = unique(targetRows2) + uniqueTarget3 = unique(targetRows3) + uniqueTarget4 = unique(targetRows4) + + if (len(targetRows1Arr) > 0): + onehotEncoder1 = OneHotEncoder(sparse=False) + targetRows1Arr = targetRows1Arr.reshape(len(targetRows1Arr), 1) + onehotEncoder1 = onehotEncoder1.fit_transform(targetRows1Arr) + hotEncoderDF1 = pd.DataFrame(onehotEncoder1) + concatDF1 = pd.concat([DataRows1, hotEncoderDF1], axis=1) + corrMatrixComb1 = concatDF1.corr() + corrMatrixComb1 = corrMatrixComb1.abs() + 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: + corrMatrixComb1 = pd.DataFrame() + VIF1 = pd.Series() + MI1List = [] + + if (len(targetRows2Arr) > 0): + onehotEncoder2 = OneHotEncoder(sparse=False) + targetRows2Arr = targetRows2Arr.reshape(len(targetRows2Arr), 1) + onehotEncoder2 = onehotEncoder2.fit_transform(targetRows2Arr) + hotEncoderDF2 = pd.DataFrame(onehotEncoder2) + concatDF2 = pd.concat([DataRows2, hotEncoderDF2], axis=1) + corrMatrixComb2 = concatDF2.corr() + corrMatrixComb2 = corrMatrixComb2.abs() + 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: + corrMatrixComb2 = pd.DataFrame() + VIF2 = pd.Series() + MI2List = [] + + if (len(targetRows3Arr) > 0): + onehotEncoder3 = OneHotEncoder(sparse=False) + targetRows3Arr = targetRows3Arr.reshape(len(targetRows3Arr), 1) + onehotEncoder3 = onehotEncoder3.fit_transform(targetRows3Arr) + hotEncoderDF3 = pd.DataFrame(onehotEncoder3) + concatDF3 = pd.concat([DataRows3, hotEncoderDF3], axis=1) + corrMatrixComb3 = concatDF3.corr() + corrMatrixComb3 = corrMatrixComb3.abs() + 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): + MI3 = mutual_info_classif(DataRows3, targetRows3Arr) + MI3List = MI3.tolist() + else: + MI3List = [] + else: + corrMatrixComb3 = pd.DataFrame() + VIF3 = pd.Series() + MI3List = [] + + if (len(targetRows4Arr) > 0): + onehotEncoder4 = OneHotEncoder(sparse=False) + targetRows4Arr = targetRows4Arr.reshape(len(targetRows4Arr), 1) + onehotEncoder4 = onehotEncoder4.fit_transform(targetRows4Arr) + hotEncoderDF4 = pd.DataFrame(onehotEncoder4) + concatDF4 = pd.concat([DataRows4, hotEncoderDF4], axis=1) + corrMatrixComb4 = concatDF4.corr() + corrMatrixComb4 = corrMatrixComb4.abs() + 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: + corrMatrixComb4 = pd.DataFrame() + VIF4 = pd.Series() + MI4List = [] + + targetRows1ArrDF = pd.DataFrame(targetRows1Arr) + targetRows2ArrDF = pd.DataFrame(targetRows2Arr) + targetRows3ArrDF = pd.DataFrame(targetRows3Arr) + targetRows4ArrDF = pd.DataFrame(targetRows4Arr) + + concatAllDF1 = pd.concat([DataRows1, targetRows1ArrDF], axis=1) + concatAllDF2 = pd.concat([DataRows2, targetRows2ArrDF], axis=1) + concatAllDF3 = pd.concat([DataRows3, targetRows3ArrDF], axis=1) + concatAllDF4 = pd.concat([DataRows4, targetRows4ArrDF], axis=1) + + corrMatrixCombTotal1 = concatAllDF1.corr() + corrMatrixCombTotal1 = corrMatrixCombTotal1.abs() + corrMatrixCombTotal2 = concatAllDF2.corr() + corrMatrixCombTotal2 = corrMatrixCombTotal2.abs() + corrMatrixCombTotal3 = concatAllDF3.corr() + corrMatrixCombTotal3 = corrMatrixCombTotal3.abs() + corrMatrixCombTotal4 = concatAllDF4.corr() + corrMatrixCombTotal4 = corrMatrixCombTotal4.abs() + + corrMatrixCombTotal1 = pd.concat([corrMatrixCombTotal1.tail(1)]) + corrMatrixCombTotal2 = pd.concat([corrMatrixCombTotal2.tail(1)]) + corrMatrixCombTotal3 = pd.concat([corrMatrixCombTotal3.tail(1)]) + corrMatrixCombTotal4 = pd.concat([corrMatrixCombTotal4.tail(1)]) + + packCorrLoc = [] + + packCorrLoc.append(corrMatrix1.to_json()) + packCorrLoc.append(corrMatrix2.to_json()) + packCorrLoc.append(corrMatrix3.to_json()) + packCorrLoc.append(corrMatrix4.to_json()) + + packCorrLoc.append(corrMatrixComb1.to_json()) + packCorrLoc.append(corrMatrixComb2.to_json()) + packCorrLoc.append(corrMatrixComb3.to_json()) + packCorrLoc.append(corrMatrixComb4.to_json()) + + packCorrLoc.append(corrMatrixCombTotal1.to_json()) + packCorrLoc.append(corrMatrixCombTotal2.to_json()) + packCorrLoc.append(corrMatrixCombTotal3.to_json()) + packCorrLoc.append(corrMatrixCombTotal4.to_json()) + + packCorrLoc.append(json.dumps(uniqueTarget1)) + packCorrLoc.append(json.dumps(uniqueTarget2)) + packCorrLoc.append(json.dumps(uniqueTarget3)) + packCorrLoc.append(json.dumps(uniqueTarget4)) + + packCorrLoc.append(VIF1.to_json()) + packCorrLoc.append(VIF2.to_json()) + packCorrLoc.append(VIF3.to_json()) + packCorrLoc.append(VIF4.to_json()) + + packCorrLoc.append(json.dumps(MI1List)) + packCorrLoc.append(json.dumps(MI2List)) + packCorrLoc.append(json.dumps(MI3List)) + packCorrLoc.append(json.dumps(MI4List)) + + return packCorrLoc + @cross_origin(origin='localhost',headers=['Content-Type','Authorization']) @app.route('/data/thresholdDataSpace', methods=["GET", "POST"]) def Seperation(): @@ -503,11 +742,14 @@ def Seperation(): else: quadrant4.append(index) + Transformation(quadrant1, quadrant2, quadrant3, quadrant4) + DataRows1 = XData.iloc[quadrant1, :] DataRows2 = XData.iloc[quadrant2, :] DataRows3 = XData.iloc[quadrant3, :] DataRows4 = XData.iloc[quadrant4, :] + # Main Features corrMatrix1 = DataRows1.corr() corrMatrix1 = corrMatrix1.abs() corrMatrix2 = DataRows2.corr() @@ -691,6 +933,15 @@ def Seperation(): return 'Everything Okay' +@app.route('/data/returnCorrelationsTransformed', methods=["GET", "POST"]) +def SendCorrelTransformed(): + global packCorrTransformed + + response = { + 'correlResulTranformed': packCorrTransformed + } + return jsonify(response) + @app.route('/data/returnCorrelations', methods=["GET", "POST"]) def SendCorrel(): global packCorr