Activity
Posted in API low-level caching
Hi,
You could cache like this:
def method_name
return Rails.cache.fetch('method_name', :expires_in => 1.hours) {
# do something
}
end
Why not?
What is stopping you? :)
Ivan Raszl, you did not understand. Read my question on SO:
https://stackoverflow.com/questions/56828359/how-do-i-temporarily-redirect-stderr-in-ruby-on-rails
Hi, gays. I would like to ask for advice.
I asked this question on StackOverflow , but I did not receive an answer.
Help please.
I can't get this code to work on rails! But in ruby it works.
You can try:
require 'csv'
require 'ruby-fann'
def silence_stdout(log = '/dev/null')
orig = $stdout.dup
$stdout.reopen(File.new(log, 'w'))
begin
yield
ensure
$stdout = orig
end
end
x_data = []
y_data = []
# Load data from CSV file into two arrays - one for independent variables X and one for the dependent variable Y
CSV.foreach("./data/admission.csv", :headers => false) do |row|
x_data.push( [row[0].to_f, row[1].to_f] )
#x_data.push( [row[0].to_f, row[1].to_f] )
y_data.push( [row[2].to_i] )
end
# Divide data into a training set and test set
test_size_percentange = 20.0 # 20.0%
test_set_size = x_data.size * (test_size_percentange/100.to_f)
test_x_data = x_data[0 .. (test_set_size-1)]
test_y_data = y_data[0 .. (test_set_size-1)]
training_x_data = x_data[test_set_size .. x_data.size]
training_y_data = y_data[test_set_size .. y_data.size]
# Setup training data model
train = RubyFann::TrainData.new( :inputs=> training_x_data, :desired_outputs=>training_y_data )
# Setup model and train using training data
model = RubyFann::Standard.new(
num_inputs: 2,
hidden_neurons: [6],
num_outputs: 1 )
silence_stdout('ttt.log') do
# 5000 max_epochs, 100 errors between reports and 0.01 desired mean-squared-error
model.train_on_data(train, 5000, 500, 0.01)
end
# Predict single class
prediction = model.run( [45, 55] )
# Round the output to get the prediction
puts "Algorithm predicted class: #{prediction.map{ |e| e.round }}"
predicted = []
test_x_data.each do |params|
predicted.push( model.run(params).map{ |e| e.round } )
end
correct = predicted.collect.with_index { |e,i| (e == test_y_data[i]) ? 1 : 0 }.inject{ |sum,e| sum+e }
puts "Accuracy: #{((correct.to_f / test_set_size) * 100).round(2)}% - test set of size #{test_size_percentange}%"
Tell me please how to get this output to a file? or to a string? -
Max epochs 5000. Desired error: 0.0099999998.
Epochs 1. Current error: 0.2511504292. Bit fail 80.
Epochs 500. Current error: 0.0143846525. Bit fail 3.
Epochs 1000. Current error: 0.0127008855. Bit fail 3.
Epochs 1500. Current error: 0.0125084650. Bit fail 3.
Epochs 2000. Current error: 0.0118288267. Bit fail 3.
Epochs 2500. Current error: 0.0111219604. Bit fail 2.
Epochs 3000. Current error: 0.0118827689. Bit fail 3.
Epochs 3500. Current error: 0.0118078245. Bit fail 2.
Epochs 4000. Current error: 0.0112144882. Bit fail 1.
Epochs 4500. Current error: 0.0117674908. Bit fail 2.
Epochs 5000. Current error: 0.0127671538. Bit fail 4.
I made a demo, but I can not show the console output at the finish.
Any ideas? Thank you.
P.S. admission.csv
SEEKING WORK (relocation or remote).
Hi everybody.
I'm a full-stack developer (ruby / rails, php). Currently based, unfortunatelly, in Russia, St.Petersburg. I dream of leaving Russia forever, I am looking for the possibility of remote work or relocation now.
My skills:
Ruby, Ruby on Rails, PHP, MySQL, PostgreSQL, jQuery, AJAX, XML, JSON.
HTML5, CSS3 / SCSS, Nginx, Apache, Git.
Creating an eCommerce websites - Prestashop, Magento, OpenCart, Joomla, VirtueMart, K2Store, JoomShopping, WordPress.
Development of extensions for the popular cms.
Maintaining a distributed Unix infrastructure, Linux Administration (RHEL/CentOS/Fedora, OpenSuse Leap/Tumbleweed). AWS (including Cloud formation and Cloud-init) and VMware (KVM, VirtualBox) as Infrastructure.
Github: https://github.com/cmirnow
Heroku: https://masterpro.herokuapp.com
Portfolio: https://masterpro.ws
Email: info@masterpro.ws
Posted in How do I handle Koala error
My examples of handling Twitter limit overruns. Hope this helps.
Posted in Request for code review
Hello.
Can I ask for a little review of my code?
I have been a php-developer for a long time. I really want to learn professional programming on rubi / ruby on rails.
This is my class, this is my controller. Please tell me what needs to be changed?
The app works well, my question is about code style only.
Thanks in advance.