Created
July 20, 2012 16:16
-
-
Save pubis/3151619 to your computer and use it in GitHub Desktop.
Klinker goes Veritable
This file contains hidden or 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
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