Skip to content

Instantly share code, notes, and snippets.

@abronte
Last active February 24, 2016 19:21
Show Gist options
  • Save abronte/72b81b7f56802d2d0589 to your computer and use it in GitHub Desktop.
Save abronte/72b81b7f56802d2d0589 to your computer and use it in GitHub Desktop.
Ruby liblinear model training
require 'liblinear'
# reference
# games = {1 => "csgo", 2 => "dota2", 3 => "hearthstone", 4 => "minecraft", 5 => "starcraft"}
# Setting parameters
param = Liblinear::Parameter.new
param.solver_type = Liblinear::L2R_LR
label_ids = {}
labels = []
examples = []
id = 1
File.open("training_set.txt", "r").each_line do |line|
split = line.split(",")
game = split[0].gsub("\"", "")
if label_ids[game].nil?
label_ids[game] = id
id += 1
end
labels << label_ids[game]
examples << split[1..-1].map{|x| x.to_f}
end
bias = 0.5
prob = Liblinear::Problem.new(labels, examples, bias)
model = Liblinear::Model.new(prob, param)
model.save("games.model")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment