Last active
December 2, 2022 11:54
-
-
Save ZackAkil/6b4f5da352accb62decc6c07a645bab1 to your computer and use it in GitHub Desktop.
Build a desicion tree from a spreadsheet.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
var ui = SpreadsheetApp.getUi(); | |
ui.createMenu("🔮 Predictions for cell") | |
.addItem('🌸 Iris', 'predict_on_row') | |
.addToUi(); | |
} | |
const output_column_number = 5 | |
function predict_on_row() { | |
var spreadsheet = SpreadsheetApp.getActive(); | |
const row_number = spreadsheet.getActiveCell().getRowIndex() | |
const values = spreadsheet.getActiveRange().getValues() | |
Logger.log(values) | |
const prediction = CloudFunction(values[0]) | |
spreadsheet.getActiveSheet().getRange(row_number, output_column_number).setValue(prediction) | |
} | |
function CloudFunction(values) { | |
const payload = JSON.stringify( | |
{ | |
"input":values | |
} | |
); | |
const url = "YOUR CLOUD FUNCTION URL"; | |
const response = UrlFetchApp.fetch(url, { | |
method: 'POST', | |
contentType: 'application/json', | |
payload: payload, | |
muteHttpExceptions: true | |
}).getContentText(); | |
Logger.log(response) | |
const json_resp = JSON.parse(response) | |
Logger.log(json_resp) | |
return json_resp.prediction | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment