-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcatboost-cli.rb
114 lines (99 loc) · 4.52 KB
/
catboost-cli.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require "yaml"
module ::Utils
def self.add_clang_version_to_conan_settings(version)
system "conan", "config", "init"
conan_home = safe_popen_read("conan", "config", "home").strip
settings_file = "#{conan_home}/settings.yml"
settings = YAML.load_file(settings_file, aliases: true)
clang_versions = settings["compiler"]["clang"]["version"]
unless clang_versions.include?(version)
clang_versions << version
File.write(settings_file, YAML.dump(settings))
end
end
end
class CatboostCli < Formula
desc "Fast, scalable, high performance Gradient Boosting on Decision Trees cli tool"
homepage "https://catboost.ai"
url "https://github.com/catboost/catboost.git",
tag: "v1.2.7",
revision: "f903943a8cd903a117c3d3c8421cc72d3910562c"
license "Apache-2.0"
revision 1
head "https://github.com/catboost/catboost.git", branch: "master"
bottle do
root_url "https://ghcr.io/v2/cdalvaro/tap"
sha256 cellar: :any_skip_relocation, arm64_sequoia: "819a3816780727daf529031ce75100d8f73c93de675ceac91d624cbd3f382a3e"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "bfc60e148b491433769e11cd82c4bc70a2c98d3780646107a4e5ec1e973f9e6d"
sha256 cellar: :any_skip_relocation, ventura: "a47ac5ded36947b7b8ff6bb5c77a783b61ec69c5e65d37c0b82e3f142c2eb024"
sha256 cellar: :any_skip_relocation, x86_64_linux: "0620595b4b0945ca8f2e86ff2ebadf1624e77b7c1c0995507ff88432dab5a2a2"
end
depends_on "cmake" => :build
depends_on "conan@1" => :build
depends_on "ninja" => :build
uses_from_macos "llvm" => :build
on_linux do
depends_on "lld"
end
resource "disable_clang_warnings" do
url "https://raw.githubusercontent.com/cdalvaro/homebrew-tap/e4af26f68ec938f1a03bd16d3c1feb2e7419ab03/patches/catboost-cli/disable_clang_warnings.diff"
sha256 "3659fadc68fae81fc760ef5dc0d2e9cb0982cfc3205e445f3a01df26c89517dd"
end
resource "testdata" do
url "https://github.com/catboost/tutorials.git",
branch: "master",
revision: "b85bed6b57feafc84e3984872260f9888c9f3bae"
end
def install
Utils.add_clang_version_to_conan_settings(Formula["llvm"].version.major.to_s) if ENV.key?("GITHUB_ACTIONS")
if OS.linux?
resource("disable_clang_warnings").stage do
system "patch", "-p1", "-d", buildpath, "-i", "#{pwd}/disable_clang_warnings.diff"
end
end
args = [
"-DCATBOOST_COMPONENTS=app",
"-DCMAKE_POSITION_INDEPENDENT_CODE=On",
"-DHAVE_CUDA=no",
"-DCMAKE_TOOLCHAIN_FILE=#{buildpath}/build/toolchains/clang.toolchain",
]
cmakepath = buildpath/"cmake-build"
system "cmake", "-S", ".", "-B", cmakepath, "-G", "Ninja", *args, *std_cmake_args
system "ninja", "-C", cmakepath, "catboost"
bin.install cmakepath/"catboost/app/catboost"
end
test do
assert_match %r{Branch: tags/v#{version}}, shell_output("#{bin}/catboost --version")
resource("testdata").stage do
cd "cmdline_tutorial" do
system bin/"catboost", "fit", "--learn-set", "train.tsv", "--test-set", "test.tsv", "--column-description",
"train.cd", "--loss-function", "RMSE", "--iterations", "1000", "--seed", 1, "--verbose", "0"
system bin/"catboost", "calc", "-m", "model.bin", "--input-path", "test.tsv", "--cd", "train.cd", "-o",
"eval.tsv", "-T", "1", "--output-columns", "DocId,Probability,Target,name,profession,#3"
assert_equal <<~EOF, File.read("eval.tsv")
DocId\tProbability\tTarget\tname\tprofession\t#3
0\t0.5755451606\t0\tAlex\tdoctor\tsenior
1\t0.5819929128\t1\tDemid\tdentist\tjunior
2\t0.6399684939\t1\tValentin\tprogrammer\tsenior
3\t0.6479485073\t1\tIvan\tdoctor\tmiddle
4\t0.5757021776\t0\tIvan\tdentist\tsenior
5\t0.5543948515\t0\tValentin\tdentist\tmiddle
6\t0.6022880215\t0\tMilan\tlawyer\tmiddle
7\t0.5760162599\t0\tMilan\tprogrammer\tsenior
8\t0.6423663059\t1\tValentin\tlawyer\tsenior
9\t0.656955474\t1\tDemid\tdoctor\tmiddle
10\t0.5992072123\t0\tValentin\tdentist\tmiddle
11\t0.5782185863\t0\tMilan\tprogrammer\tsenior
12\t0.6055756528\t1\tValentin\tdentist\tjunior
13\t0.5209084714\t0\tIvan\tdoctor\tsenior
14\t0.5840158456\t0\tValentin\tdentist\tsenior
15\t0.60573894\t0\tMilan\tdentist\tsenior
16\t0.5926617612\t0\tDemid\tlawyer\tmiddle
17\t0.6298311784\t0\tValentin\tprogrammer\tsenior
18\t0.6230447361\t1\tMilan\tlawyer\tsenior
19\t0.6311443544\t1\tValentin\tlawyer\tjunior
EOF
end
end
end
end