Skip to content

Instantly share code, notes, and snippets.

@pubis
Created July 20, 2012 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pubis/3151619 to your computer and use it in GitHub Desktop.
Save pubis/3151619 to your computer and use it in GitHub Desktop.
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