Skip to content

Instantly share code, notes, and snippets.

@ZackAkil
Last active December 2, 2022 11:54
Show Gist options
  • Save ZackAkil/6b4f5da352accb62decc6c07a645bab1 to your computer and use it in GitHub Desktop.
Save ZackAkil/6b4f5da352accb62decc6c07a645bab1 to your computer and use it in GitHub Desktop.
Build a desicion tree from a spreadsheet.ipynb
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
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment