fixed first component

master
parent 1d6e2cf9c2
commit 81a9e520ac
  1. BIN
      __pycache__/run.cpython-37.pyc
  2. 7
      frontend/src/components/Algorithms.vue
  3. 33
      frontend/src/components/BarChart.vue
  4. 1
      frontend/src/components/DataSetExecController.vue
  5. 2
      frontend/src/components/DataSpace.vue
  6. 25
      frontend/src/components/FeatureSelection.vue
  7. 33
      frontend/src/components/Heatmap.vue
  8. 120
      frontend/src/components/Main.vue
  9. 2
      frontend/src/components/PredictionsSpace.vue
  10. 42
      frontend/src/components/StretchedChord.vue
  11. 226
      run.py

Binary file not shown.

@ -22,6 +22,7 @@ export default {
},
methods: {
boxplot () {
d3.selectAll("#exploding_boxplot > *").remove();
//generate random data
const PerformAlgor1 = JSON.parse(this.PerformanceAllModels[0])
const PerformAlgor2 = JSON.parse(this.PerformanceAllModels[1])
@ -30,13 +31,13 @@ export default {
var median = []
var sum = 0
for (let i = 0; i < Object.keys(PerformAlgor1.mean_test_score).length; i++) {
algorithm1.push({Performance: Object.values(PerformAlgor1.mean_test_score)[i]*100,Algorithm:'KNN',Model:'Model ' + i + ', Accuracy '})
algorithm1.push({Accuracy: Object.values(PerformAlgor1.mean_test_score)[i]*100,Algorithm:'KNN',Model:'Model ' + i + ', Accuracy '})
sum = sum + Object.values(PerformAlgor1.mean_test_score)[i]*100
}
median.push(sum/Object.keys(PerformAlgor1.mean_test_score).length)
sum = 0
for (let i = 0; i < Object.keys(PerformAlgor2.mean_test_score).length; i++) {
algorithm2.push({Performance: Object.values(PerformAlgor2.mean_test_score)[i]*100,Algorithm:'RF',Model:'Model ' + i + ', Accuracy '})
algorithm2.push({Accuracy: Object.values(PerformAlgor2.mean_test_score)[i]*100,Algorithm:'RF',Model:'Model ' + i + ', Accuracy '})
sum = sum + Object.values(PerformAlgor1.mean_test_score)[i]*100
}
var data = algorithm1.concat(algorithm2)
@ -52,7 +53,7 @@ export default {
// group : how to group data on x axis
// color : color of the point / boxplot
// label : displayed text in toolbox
var chart = exploding_boxplot(data, {y:'Performance',group:'Algorithm',color:'Algorithm',label:'Model'})
var chart = exploding_boxplot(data, {y:'Accuracy',group:'Algorithm',color:'Algorithm',label:'Model'})
//call chart on a div
chart('#exploding_boxplot')

@ -34,32 +34,41 @@ export default {
const PerClassMetrics = JSON.parse(this.BarChartResults[4])
const ClassNames = JSON.parse(this.BarChartResults[5])
const limit = JSON.parse(this.BarChartResults[12])
let ClassifierswithoutFI = JSON.parse(this.BarChartResults[8])
let ClassifierswithFI = JSON.parse(this.BarChartResults[9])
var Classifiers
Classifiers = ClassifierswithoutFI.concat(ClassifierswithFI)
var PerClassMetricsRed = []
var limitList = []
if (limit == '') {
for (let i = 0; i < PerClassMetrics.length; i++) {
limitList.push(i)
for (let i = 0; i < Classifiers.length; i++) {
limitList.push(Classifiers[i])
}
} else {
limitList = []
for (let i = 0; i < limit.length; i++) {
limitList.push(Number(limit[i].match(/\d+/)[0]))
for (let j = 0; j < Classifiers.length; j++) {
if (Number(limit[i].match(/\d+/)[0]) == Classifiers[j]) {
limitList.push(Number(limit[i].match(/\d+/)[0]))
}
}
}
}
console.log(limitList)
const precisionPerClass = []
const recallPerClass = []
const f1ScorePerClass = []
for (let j = 0; j < ClassNames.length; j++) {
precisionPerClass[j] = []
recallPerClass[j] = []
f1ScorePerClass[j] = []
for (let i = 0; i < limitList.length; i++) { // Fix this tomorrow! 0 to 16 and we want the ids..
precisionPerClass[j].push(PerClassMetrics[limitList[i]][ClassNames[j]].precision)
recallPerClass[j].push(PerClassMetrics[limitList[i]][ClassNames[j]].recall)
f1ScorePerClass[j].push(PerClassMetrics[limitList[i]][ClassNames[j]]['f1-score'])
}
precisionPerClass[j] = []
recallPerClass[j] = []
f1ScorePerClass[j] = []
for (let i = 0; i < limitList.length; i++) { // Fix this tomorrow! 0 to 16 and we want the ids..
precisionPerClass[j].push(PerClassMetrics[limitList[i]][ClassNames[j]].precision)
recallPerClass[j].push(PerClassMetrics[limitList[i]][ClassNames[j]].recall)
f1ScorePerClass[j].push(PerClassMetrics[limitList[i]][ClassNames[j]]['f1-score'])
}
}
var precisionData

@ -60,7 +60,6 @@ export default {
const fileName = document.getElementById('selectFile')
this.RetrieveValueCSV = fileName.options[fileName.selectedIndex].value
this.RetrieveValueCSV = this.RetrieveValueCSV.split('.')[0]
console.log(this.RetrieveValueCSV)
EventBus.$emit('SendToServerDataSetConfirmation', this.RetrieveValueCSV)
},
execute () {

@ -16,7 +16,7 @@ export default {
},
methods: {
ScatterPlotDataView () {
const XandYCoordinates = this.DataSpace[0]
const XandYCoordinates = JSON.parse(this.DataSpace[10])
var result = XandYCoordinates.reduce(function(r, a) {
a.forEach(function(s, i) {

@ -18,12 +18,27 @@ export default {
FeatureSelection () {
document.getElementById("myDynamicTable").innerHTML = "";
let Features= this.GetResults[0]
let ClassifierswithoutFI = this.GetResults[1]
let ClassifierswithFI = this.GetResults[2]
let Features= JSON.parse(this.GetResults[7])
let ClassifierswithoutFI = JSON.parse(this.GetResults[8])
let ClassifierswithFI = JSON.parse(this.GetResults[9])
const limit = JSON.parse(this.GetResults[12])
var Classifiers
Classifiers = ClassifierswithoutFI.concat(ClassifierswithFI)
console.log(Classifiers)
var limitList = []
if (limit == '') {
for (let i = 0; i < Classifiers.length; i++) {
limitList.push(Classifiers[i])
}
} else {
limitList = []
for (let i = 0; i < limit.length; i++) {
for (let j = 0; j < Classifiers.length; j++) {
if (Number(limit[i].match(/\d+/)[0]) == Classifiers[j]) {
limitList.push(Number(limit[i].match(/\d+/)[0]))
}
}
}
}
var myTableDiv = document.getElementById("myDynamicTable");
var table = document.createElement('TABLE');
table.border = '1';
@ -32,7 +47,7 @@ export default {
table.appendChild(tableBody);
var checkBoxArray = []
for (var i = 0; i < Classifiers.length+1; i++) {
for (var i = 0; i < limitList.length+1; i++) {
var tr = document.createElement('TR');
tableBody.appendChild(tr);
for (var j = 0; j < Features.length; j++) {

@ -18,13 +18,31 @@ export default {
},
methods: {
Heatmap () {
// Clear Heatmap first
var svg = d3.select("#Heatmap");
svg.selectAll("*").remove();
// Clear Heatmap first
var svg = d3.select("#Heatmap");
svg.selectAll("*").remove();
let FeaturesAccuracy = this.GetResultsAll[0]
let Features= this.GetResultsAll[1]
let Classifiers = this.GetResultsAll[2]
var FeaturesAccuracy = JSON.parse(this.GetResultsAll[6])
var Features= JSON.parse(this.GetResultsAll[7])
const limit = JSON.parse(this.GetResultsAll[12])
var Classifiers = JSON.parse(this.GetResultsAll[8])
if (Classifiers != '') {
var limitList = []
if (limit == '') {
for (let i = 0; i < Classifiers.length; i++) {
limitList.push(Classifiers[i])
}
} else {
limitList = []
for (let i = 0; i < limit.length; i++) {
for (let j = 0; j < Classifiers.length; j++) {
if (Number(limit[i].match(/\d+/)[0]) == Classifiers[j]) {
limitList.push(Number(limit[i].match(/\d+/)[0]))
}
}
}
}
let len = Features.length
let indicesYAxis = new Array(len)
@ -46,7 +64,7 @@ export default {
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
let len2 = Classifiers.length
let len2 = limitList.length
let indicesXAxis = new Array(len)
for (let i = 0; i < len2; i++) {
indicesXAxis[i] = i
@ -97,6 +115,7 @@ export default {
.attr("height", y.bandwidth() )
.style("fill", function(d) { return myColor(d.value)} )
}
}
},
mounted () {

@ -45,13 +45,24 @@
</b-col>
<b-col cols="6">
<mdb-card>
<mdb-card-header color="primary-color" tag="h5" class="text-center">Models, Features, and Classes Connection</mdb-card-header>
<mdb-card-body>
<StretchedChord/>
</mdb-card-body>
<mdb-card-body>
<Heatmap/>
</mdb-card-body>
<mdb-card-header color="primary-color" tag="h5" class="text-center">Subset Feature Selection Per Model</mdb-card-header>
<b-row>
<b-col cols="4">
<mdb-card-body>
<StretchedChord/>
</mdb-card-body>
</b-col>
<b-col cols="4">
<mdb-card-body>
<Heatmap/>
</mdb-card-body>
</b-col>
<b-col cols="4">
<mdb-card-body>
<FeatureSelection/>
</mdb-card-body>
</b-col>
</b-row>
</mdb-card>
</b-col>
<b-col cols="3">
@ -74,15 +85,7 @@
</mdb-card-body>
</mdb-card>
</b-col>
<b-col cols="6">
<mdb-card>
<mdb-card-header color="primary-color" tag="h5" class="text-center">Subset Feature Selection</mdb-card-header>
<mdb-card-body>
<FeatureSelection/>
</mdb-card-body>
</mdb-card>
</b-col>
<b-col cols="3">
<b-col cols="3" offset-md="6">
<mdb-card>
<mdb-card-header color="primary-color" tag="h5" class="text-center">Meta-Model Performance</mdb-card-header>
<mdb-card-body>
@ -148,7 +151,10 @@ export default Vue.extend({
selectedAlgorithm: '',
PerformancePerModel: '',
brushed: 0,
brushedAll: [],
ExecutionStart: false,
reset: false,
limitModels: 64
}
},
methods: {
@ -200,14 +206,15 @@ export default Vue.extend({
console.log('Server successfully sent all the data related to visualizations!')
EventBus.$emit('emittedEventCallingScatterPlot', this.OverviewResults)
var length = JSON.parse(this.OverviewResults[0]).length
if (length < 64) {
console.log(this.ClassifierIDsList)
if (length < this.limitModels) {
this.OverviewResults.push(JSON.stringify(this.ClassifierIDsList))
EventBus.$emit('emittedEventCallingBarChart', this.OverviewResults)
/*EventBus.$emit('emittedEventCallingChordView', this.OverviewResults)
EventBus.$emit('emittedEventCallingChordView', this.OverviewResults)
EventBus.$emit('emittedEventCallingHeatmapView', this.OverviewResults)
EventBus.$emit('emittedEventCallingTableView', this.OverviewResults)
EventBus.$emit('emittedEventCallingDataSpacePlotView', this.OverviewResults)
EventBus.$emit('emittedEventCallingPredictionsSpacePlotView', this.OverviewResults)*/
EventBus.$emit('emittedEventCallingPredictionsSpacePlotView', this.OverviewResults)
this.OverviewResults.pop()
}
this.getFinalResults()
@ -256,14 +263,14 @@ export default Vue.extend({
axios.post(path, postData, axiosConfig)
.then(response => {
console.log('Sent the selected points to the server (scatterplot)!')
if (this.ClassifierIDsList.length < 64) {
if (this.ClassifierIDsList.length < this.limitModels) {
this.OverviewResults.push(JSON.stringify(this.ClassifierIDsList))
EventBus.$emit('emittedEventCallingBarChart', this.OverviewResults)
/*EventBus.$emit('emittedEventCallingChordView', this.OverviewResults)
EventBus.$emit('emittedEventCallingChordView', this.OverviewResults)
EventBus.$emit('emittedEventCallingHeatmapView', this.OverviewResults)
EventBus.$emit('emittedEventCallingTableView', this.OverviewResults)
EventBus.$emit('emittedEventCallingDataSpacePlotView', this.OverviewResults)
EventBus.$emit('emittedEventCallingPredictionsSpacePlotView', this.OverviewResults)*/
EventBus.$emit('emittedEventCallingPredictionsSpacePlotView', this.OverviewResults)
this.OverviewResults.pop()
}
this.getFinalResults()
@ -343,7 +350,7 @@ export default Vue.extend({
SendBrushedParameters () {
EventBus.$emit('emittedEventCallingModelBrushed')
const path = `http://127.0.0.1:5000/data/SendBrushedParam`
console.log(this.selectedAlgorithm)
this.brushedAll.push(this.brushed)
const postData = {
brushed: this.brushed,
algorithm: this.selectedAlgorithm
@ -368,28 +375,85 @@ export default Vue.extend({
console.log(error)
})
},
UpdateBasedonFeatures () {
const path = `http://127.0.0.1:5000/data/FeaturesSelection`
const postData = {
featureSelection: this.SelectedFeaturesPerClassifier,
brushedAll: this.brushedAll
}
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.post(path, postData, axiosConfig)
.then(response => {
console.log('Sent specific features per model!')
this.getFinalResults()
})
.catch(error => {
console.log(error)
})
},
CallPCP () {
EventBus.$emit('emittedEventCallingModelClear')
EventBus.$emit('emittedEventCallingModelSelect', this.selectedAlgorithm)
EventBus.$emit('emittedEventCallingModel', this.PerformancePerModel)
},
Reset () {
const path = `http://127.0.0.1:5000/data/Reset`
this.reset = true
const postData = {
ClassifiersList: this.reset
}
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.post(path, postData, axiosConfig)
.then(response => {
console.log('The server side was reset! Done.')
this.reset = false
})
.catch(error => {
console.log(error)
})
}
},
created() {
// does the browser support the Navigation Timing API?
if (window.performance) {
console.info("window.performance is supported");
}
// do something based on the navigation type...
if(performance.navigation.type === 1) {
console.info("TYPE_RELOAD");
this.Reset();
}
},
mounted() {
loadProgressBar()
this.fileNameSend()
window.onbeforeunload = function(e) {
//put here the reset function!
return 'Dialog text here.'
}
$(window).unload(function() {
alert('Handler for .unload() called.')
$(window).on("unload", function(e) {
alert('Handler for .unload() called.');
})
EventBus.$on('ReturningBrushedPoints', data => { this.brushed = data })
EventBus.$on('SendSelectedPointsToServerEvent', data => { this.ClassifierIDsList = data })
EventBus.$on('SendSelectedPointsToServerEvent', this.SendSelectedPointsToServer)
EventBus.$on('SendSelectedFeaturesEvent', data => { this.SelectedFeaturesPerClassifier = data })
EventBus.$emit('SendToServerDataSetConfirmation', data => { this.RetrieveValueFile = data })
EventBus.$emit('SendToServerDataSetConfirmation', data => { this.fileNameSend })
EventBus.$on('SendSelectedFeaturesEvent', this.UpdateBasedonFeatures )
EventBus.$on('SendToServerDataSetConfirmation', data => { this.RetrieveValueFile = data })
EventBus.$on('SendToServerDataSetConfirmation', this.fileNameSend)
EventBus.$on('PCPCall', data => { this.selectedAlgorithm = data })
EventBus.$on('PCPCall', this.CallPCP)
EventBus.$on('PCPCallDB', this.SendBrushedParameters)

@ -15,7 +15,7 @@ export default {
},
methods: {
ScatterPlotDataView () {
const XandYCoordinates = this.PredictionsData[0]
const XandYCoordinates = JSON.parse(this.PredictionsData[11])
var result = XandYCoordinates.reduce(function(r, a) {
a.forEach(function(s, i) {

@ -19,20 +19,46 @@ export default {
},
methods: {
StretchChord () {
const FeatureImportance = this.AllResults[0]
const ClassNames = this.AllResults[1]
const ClassifiersIDs = this.AllResults[2]
if (ClassifiersIDs != ''){
d3.selectAll("#chart > *").remove();
const FeatureImportance = JSON.parse(this.AllResults[3])
const ClassNames = JSON.parse(this.AllResults[5])
const ClassifiersIDs = JSON.parse(this.AllResults[9])
const limit = JSON.parse(this.AllResults[12])
var limitList = []
if (limit == '') {
for (let i = 0; i < ClassifiersIDs.length; i++) {
limitList.push(ClassifiersIDs[i])
}
} else {
limitList = []
for (let i = 0; i < limit.length; i++) {
for (let j = 0; j < ClassifiersIDs.length; j++) {
if (Number(limit[i].match(/\d+/)[0]) == ClassifiersIDs[j]) {
limitList.push(Number(limit[i].match(/\d+/)[0]))
}
}
}
}
if (limitList.length != 0){
var SortFeaturesPerClass = []
var MergeSortFeaturesPerClass = []
var counter = 0
var SortFeaturesPerClassRemoveEmpty = []
var returnvalue = 0
FeatureImportance.forEach(classifier => {
var length = this.ObjectSize(classifier)
for (let i = 0; i < length; i++) {
SortFeaturesPerClass.push(this.sortObject(classifier[i], ClassifiersIDs[counter], ClassNames[i]))
for (let i = 0; i < limitList.length; i++) {
returnvalue = this.sortObject(classifier[i], limitList[counter], ClassNames[i])
if (returnvalue === undefined || returnvalue.length == 0) {
} else {
if (returnvalue[0]['classifier'] != 'M undefined') {
console.log(returnvalue)
SortFeaturesPerClass.push(returnvalue)
}
}
}
counter++
})
//var SortFeaturesPerClassRemoveEmpty = SortFeaturesPerClass.filter(e => e.length);
MergeSortFeaturesPerClass = SortFeaturesPerClass[0]
for (let i = 0; i < SortFeaturesPerClass.length - 1; i++) {
MergeSortFeaturesPerClass = MergeSortFeaturesPerClass.concat(SortFeaturesPerClass[i+1])
@ -405,7 +431,7 @@ export default {
//if ((this.LimitFeatureImportance/100) < Math.abs(obj[prop])) {
arr.push({
'feature': 'F ' + prop,
'classifier': 'Cl ' + classifierID,
'classifier': 'M ' + classifierID,
'class': ClassName,
'importancerate': Math.abs(Math.round(obj[prop] * 100))
})

226
run.py

@ -38,6 +38,73 @@ mongo = PyMongo(app)
cors = CORS(app, resources={r"/data/*": {"origins": "*"}})
# Retrieve data from client
@cross_origin(origin='localhost',headers=['Content-Type','Authorization'])
@app.route('/data/Reset', methods=["GET", "POST"])
def Reset():
global DataRawLength
global DataResultsRaw
global RANDOM_SEED
RANDOM_SEED = 42
global XData
XData = []
global yData
yData = []
global algorithmList
algorithmList = []
global ClassifierIDsList
ClassifierIDsList = ''
# Initializing models
global classifiersId
classifiersId = []
global classifiersIDwithFI
classifiersIDwithFI = []
global classifiersIDPlusParams
classifiersIDPlusParams = []
global classifierID
classifierID = 0
global resultsList
resultsList = []
global RetrieveModelsList
RetrieveModelsList = []
global allParametersPerformancePerModel
allParametersPerformancePerModel = []
global all_classifiers
all_classifiers = []
global crossValidation
crossValidation = 3
global scoring
#scoring = {'accuracy': 'accuracy', 'f1_macro': 'f1_weighted', 'precision': 'precision_weighted', 'recall': 'recall_weighted', 'jaccard': 'jaccard_weighted', 'neg_log_loss': 'neg_log_loss', 'r2': 'r2', 'neg_mean_absolute_error': 'neg_mean_absolute_error', 'neg_mean_absolute_error': 'neg_mean_absolute_error'}
scoring = {'accuracy': 'accuracy', 'f1_macro': 'f1_weighted', 'precision': 'precision_weighted', 'recall': 'recall_weighted', 'jaccard': 'jaccard_weighted'}
global yPredictProb
yPredictProb = []
global loopFeatures
loopFeatures = 2
global columns
columns = []
global results
results = []
global target_names
target_names = []
return 'The reset was done!'
# Retrieve data from client
@cross_origin(origin='localhost',headers=['Content-Type','Authorization'])
@app.route('/data/ServerRequest', methods=["GET", "POST"])
@ -60,6 +127,9 @@ def RetrieveFileName():
global ClassifierIDsList
ClassifierIDsList = ''
global algorithmList
algorithmList = []
# Initializing models
global classifiersId
@ -71,6 +141,9 @@ def RetrieveFileName():
global classifierID
classifierID = 0
global RetrieveModelsList
RetrieveModelsList = []
global resultsList
resultsList = []
@ -87,14 +160,14 @@ def RetrieveFileName():
#scoring = {'accuracy': 'accuracy', 'f1_macro': 'f1_weighted', 'precision': 'precision_weighted', 'recall': 'recall_weighted', 'jaccard': 'jaccard_weighted', 'neg_log_loss': 'neg_log_loss', 'r2': 'r2', 'neg_mean_absolute_error': 'neg_mean_absolute_error', 'neg_mean_absolute_error': 'neg_mean_absolute_error'}
scoring = {'accuracy': 'accuracy', 'f1_macro': 'f1_weighted', 'precision': 'precision_weighted', 'recall': 'recall_weighted', 'jaccard': 'jaccard_weighted'}
global yPredictProb
yPredictProb = []
global loopFeatures
loopFeatures = 2
global flag
flag = 0
global yPredictProb
yPredictProb = []
global columns
columns = []
global results
results = []
@ -223,8 +296,9 @@ def GridSearch(clf, params, FI):
PerFeatureAccuracy = []
global subset
global loopFeatures
global flag
global yPredictProb
global columns
columns = []
counter = 0
subset = XData
for i, eachClassifierParams in enumerate(grid.cv_results_['params']):
@ -244,22 +318,13 @@ def GridSearch(clf, params, FI):
subset = XData
else:
featureSelected = []
if (int(''.join(x for x in featureSelection['featureSelection'][loopFeatures] if x.isdigit())) == 1):
featureSelected.append('petal_l')
loopFeatures = loopFeatures + 3
if (int(''.join(x for x in featureSelection['featureSelection'][loopFeatures] if x.isdigit())) == 1):
featureSelected.append('petal_w')
loopFeatures = loopFeatures + 3
if (int(''.join(x for x in featureSelection['featureSelection'][loopFeatures] if x.isdigit())) == 1):
featureSelected.append('sepal_l')
loopFeatures = loopFeatures + 3
if (int(''.join(x for x in featureSelection['featureSelection'][loopFeatures] if x.isdigit())) == 1):
featureSelected.append('sepal_w')
loopFeatures = loopFeatures + 3
for indices, each in enumerate(XData.columns):
if (int(''.join(x for x in featureSelection['featureSelection'][loopFeatures] if x.isdigit())) == 1):
featureSelected.append(each)
loopFeatures = loopFeatures + 3
subset = XData[featureSelected]
element = (column_index(XData, featureSelected))
columns[flag] = element
flag = flag + 1
columns.append(element)
grid.fit(subset, yData)
if (FI == 0):
n_feats = XData.shape[1]
@ -368,6 +433,8 @@ def InitializeEnsemble():
return Results
# Retrieve data from client
@cross_origin(origin='localhost',headers=['Content-Type','Authorization'])
@app.route('/data/ServerRequestSelPoin', methods=["GET", "POST"])
@ -378,6 +445,53 @@ def RetrieveSelClassifiersID():
EnsembleModel(ClassifierIDsList, key)
return 'Everything Okay'
# Retrieve data from client
@cross_origin(origin='localhost',headers=['Content-Type','Authorization'])
@app.route('/data/FeaturesSelection', methods=["GET", "POST"])
def FeatureSelPerModel():
global featureSelection
global loopFeatures
global ClassifierIDsList
RetrieveModelsPar = request.get_data().decode('utf8').replace("'", '"')
RetrieveModelsPar = json.loads(RetrieveModelsPar)
RetrieveModelsParRed = []
print(RetrieveModelsPar['brushedAll']) # FIX THIS THING!!!!!
for j, i in enumerate(RetrieveModelsPar['brushedAll']):
print(j)
RetrieveModelsParRed = [for j, i in enumerate(RetrieveModelsPar['brushedAll']) if j not in ClassifierIDsList]
RetrieveModelsParPandas = pd.DataFrame(RetrieveModelsParRed)
RetrieveModelsParPandas = RetrieveModelsParPandas.drop(columns=['performance'])
RetrieveModelsParPandas = RetrieveModelsParPandas.to_dict(orient='list')
print(RetrieveModelsParPandas)
RetrieveModels = {}
for key, value in RetrieveModelsParPandas.items():
withoutDuplicates = Remove(value)
RetrieveModels[key] = withoutDuplicates
global RetrieveModelsListNew
RetrieveModelsListNew.append(RetrieveModels)
loopFeatures = 2
featureSelection = request.get_data().decode('utf8').replace("'", '"')
featureSelection = json.loads(featureSelection)
global algorithmList
results = []
for index, eachalgor in enumerate(algorithmList):
if (eachalgor == 'KNN'):
clf = KNeighborsClassifier()
params = RetrieveModelsListNew[index]
IF = 0
results.append(GridSearch(clf, params, IF))
resultsList.append(results[0])
else:
clf = RandomForestClassifier()
params = RetrieveModelsListNew[index]
IF = 1
results.append(GridSearch(clf, params, IF))
resultsList.append(results[0])
key = 2
EnsembleModel(ClassifierIDsList, key)
return 'Everything Okay'
def FunMDS (data):
mds = MDS(n_components=2, random_state=RANDOM_SEED)
XTransformed = mds.fit_transform(data).T
@ -393,19 +507,23 @@ def EnsembleModel (ClassifierIDsList, keyRetrieved):
global scores
scores = []
global all_classifiersSelection
all_classifiersSelection = []
global columns
global all_classifiers
if (keyRetrieved == 0):
columnsInit = []
all_classifiers = []
columns = []
columns = [XData.columns.get_loc(c) for c in XData.columns if c in XData]
columnsInit = [XData.columns.get_loc(c) for c in XData.columns if c in XData]
for index, eachelem in enumerate(algorithmList):
if (eachelem == 'KNN'):
for each in resultsList[index][1]:
all_classifiers.append(make_pipeline(ColumnSelector(cols=columns), KNeighborsClassifier().set_params(**each)))
all_classifiers.append(make_pipeline(ColumnSelector(cols=columnsInit), KNeighborsClassifier().set_params(**each)))
else:
for each in resultsList[index][1]:
all_classifiers.append(make_pipeline(ColumnSelector(cols=columns), RandomForestClassifier().set_params(**each)))
all_classifiers.append(make_pipeline(ColumnSelector(cols=columnsInit), RandomForestClassifier().set_params(**each)))
lr = LogisticRegression()
sclf = StackingCVClassifier(classifiers=all_classifiers,
@ -413,14 +531,7 @@ def EnsembleModel (ClassifierIDsList, keyRetrieved):
meta_classifier=lr,
random_state=RANDOM_SEED,
n_jobs = -1)
for clf, label in zip([sclf],
['StackingClassifier']):
scores = model_selection.cross_val_score(clf, XData, yData,
cv=crossValidation, scoring='accuracy')
else:
all_classifiersSelection = []
elif (keyRetrieved == 1):
ClassifierIDsList = json.loads(ClassifierIDsList)
for loop in ClassifierIDsList['ClassifiersList']:
temp = [int(s) for s in re.findall(r'\b\d+\b', loop)]
@ -432,12 +543,51 @@ def EnsembleModel (ClassifierIDsList, keyRetrieved):
meta_classifier=lr,
random_state=RANDOM_SEED,
n_jobs = -1)
else:
columnsReduce = columns.copy()
lr = LogisticRegression()
if (len(all_classifiersSelection) == 0):
all_classifiers = []
for index, eachelem in enumerate(algorithmList):
if (eachelem == 'KNN'):
for j, each in enumerate(resultsList[index][1]):
all_classifiers.append(make_pipeline(ColumnSelector(cols=columnsReduce[j]), KNeighborsClassifier().set_params(**each)))
del columnsReduce[0:len(resultsList[index][1])]
else:
for j, each in enumerate(resultsList[index][1]):
all_classifiers.append(make_pipeline(ColumnSelector(cols=columnsReduce[j]), RandomForestClassifier().set_params(**each)))
del columnsReduce[0:len(resultsList[index][1])]
print(all_classifiers)
sclf = StackingCVClassifier(classifiers=all_classifiers,
use_probas=True,
meta_classifier=lr,
random_state=RANDOM_SEED,
n_jobs = -1)
else:
for index, eachelem in enumerate(algorithmList):
if (eachelem == 'KNN'):
print(resultsList[index][1])
for j, each in enumerate(resultsList[index][1]):
all_classifiersSelection.append(make_pipeline(ColumnSelector(cols=columnsReduce[j]), KNeighborsClassifier().set_params(**each)))
del columnsReduce[0:len(resultsList[index][1])]
else:
for j, each in enumerate(resultsList[index][1]):
all_classifiersSelection.append(make_pipeline(ColumnSelector(cols=columnsReduce[j]), RandomForestClassifier().set_params(**each)))
del columnsReduce[0:len(resultsList[index][1])]
print(all_classifiersSelection)
sclf = StackingCVClassifier(classifiers=all_classifiersSelection,
use_probas=True,
meta_classifier=lr,
random_state=RANDOM_SEED,
n_jobs = -1)
for clf, label in zip([sclf],
['StackingClassifier']):
scores = model_selection.cross_val_score(clf, XData, yData,
cv=crossValidation, scoring='accuracy')
for clf, label in zip([sclf],
['StackingClassifier']):
scores = model_selection.cross_val_score(clf, XData, yData,
cv=crossValidation, scoring='accuracy')
# Sending the final results to be visualized as a line plot
@app.route('/data/SendFinalResultsBacktoVisualize', methods=["GET", "POST"])
@ -461,7 +611,6 @@ def SendToPlot():
}
return jsonify(response)
algorithmList = []
# Retrieve data from client
@cross_origin(origin='localhost',headers=['Content-Type','Authorization'])
@app.route('/data/ServerRequestSelParameters', methods=["GET", "POST"])
@ -543,11 +692,12 @@ def RetrieveModelsParam():
for key, value in RetrieveModelsParPandas.items():
withoutDuplicates = Remove(value)
RetrieveModels[key] = withoutDuplicates
global RetrieveModelsList
RetrieveModelsList.append(RetrieveModels)
global classifierID
global algorithmList
results = []
print(algorithm)
algorithmList.append(algorithm)
if (algorithm == 'KNN'):
clf = KNeighborsClassifier()

Loading…
Cancel
Save