MCPcopy Create free account
hub / github.com/catboost/catboost / CalcPrediction

Method CalcPrediction

catboost/node-package/src/model.cpp:110–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110Napi::Value TModel::CalcPrediction(const Napi::CallbackInfo& info) {
111 Napi::Env env = info.Env();
112 if (!NHelper::Check(env, this->ModelLoaded, "Trying to predict from the empty model")) {
113 return env.Undefined();
114 }
115
116 if (!NHelper::Check(env, info.Length() >= 1, "Wrong number of arguments - expected at least 1")) {
117 return env.Undefined();
118 }
119
120
121 // Numerical features
122
123 if (!NHelper::CheckIsMatrix(
124 env,
125 info[0],
126 NHelper::NAT_NUMBER,
127 "Expected the first argument to be a matrix of floats - "
128 ))
129 {
130 return env.Undefined();
131 }
132
133 const Napi::Array floatFeatures = info[0].As<Napi::Array>();
134 const uint32_t sampleCount = floatFeatures.Length();
135 if (sampleCount == 0) {
136 return Napi::Array::New(env);
137 }
138
139
140 // Categorical features
141 Napi::Value catFeatures;
142 bool catFeaturesAreHashes = false;
143
144 if (info.Length() >= 2) {
145 catFeatures = info[1];
146 if (!NHelper::CheckIsMatrix(
147 env,
148 catFeatures,
149 NHelper::NAT_NUMBER_OR_STRING,
150 "Expected the second argument to be a matrix of strings or numbers - "
151 ))
152 {
153 return env.Undefined();
154 }
155 const Napi::Array catFeaturesArray = catFeatures.As<Napi::Array>();
156
157 if (!NHelper::Check(
158 env,
159 catFeaturesArray.Length() == sampleCount,
160 "Expected the number of samples to be the same for both float and categorical features"
161 ))
162 {
163 return env.Undefined();
164 }
165 if (sampleCount) {
166 const Napi::Array catRow = catFeaturesArray[0u].As<Napi::Array>();
167 if (catRow.Length()) {

Callers

nothing calls this directly

Calls 4

CheckIsMatrixFunction · 0.85
CheckFunction · 0.70
NewFunction · 0.50
LengthMethod · 0.45

Tested by

no test coverage detected