Skip to content

Instantly share code, notes, and snippets.

@pubis
Created Jul 20, 2012
Embed
What would you like to do?
Klinker goes Veritable
require 'veritable'
API_KEY = ENV['VERITABLE_KEY']
api = Veritable.connect(api_key: API_KEY)
rows = Veritable::Util.read_csv('klinkers-data.csv')
schema = {
'account' => {'type' => 'categorical'},
'category' => {'type' => 'categorical'},
'amount' => {'type' => 'real'},
'weekday' => {'type' => 'categorical'}
}
Veritable::Util.clean_data(rows, schema)
api.delete_table('klinkers-data') if api.has_table?('klinkers-data')
table = api.create_table('klinkers-data')
table.batch_upload_rows(rows)
table.delete_analysis('my-analysis') if table.has_analysis?('my-analysis')
analysis = table.create_analysis(schema, 'my-analysis')
analysis.wait
new_transaction = {
'account' => 'Direktkonto',
'category' => 'Lunch',
'amount' => nil,
'weekday' => ''
}
result = []
%w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday].each do |weekday|
new_transaction['weekday'] = weekday
prediction = analysis.predict(new_transaction)
result << {weekday: weekday, prediction: prediction}
end
puts result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment