lib/rumale/kernel_machine/kernel_svc.rb in rumale-0.13.8 vs lib/rumale/kernel_machine/kernel_svc.rb in rumale-0.14.0
- old
+ new
@@ -50,14 +50,13 @@
# If nil is given, the methods do not execute in parallel.
# If zero or less is given, it becomes equal to the number of processors.
# This parameter is ignored if the Parallel gem is not loaded.
# @param random_seed [Integer] The seed value using to initialize the random generator.
def initialize(reg_param: 1.0, max_iter: 1000, probability: false, n_jobs: nil, random_seed: nil)
- check_params_float(reg_param: reg_param)
- check_params_integer(max_iter: max_iter)
+ check_params_numeric(reg_param: reg_param, max_iter: max_iter)
check_params_boolean(probability: probability)
- check_params_type_or_nil(Integer, n_jobs: n_jobs, random_seed: random_seed)
+ check_params_numeric_or_nil(n_jobs: n_jobs, random_seed: random_seed)
check_params_positive(reg_param: reg_param, max_iter: max_iter)
@params = {}
@params[:reg_param] = reg_param
@params[:max_iter] = max_iter
@params[:probability] = probability
@@ -75,12 +74,12 @@
# @param x [Numo::DFloat] (shape: [n_training_samples, n_training_samples])
# The kernel matrix of the training data to be used for fitting the model.
# @param y [Numo::Int32] (shape: [n_training_samples]) The labels to be used for fitting the model.
# @return [KernelSVC] The learned classifier itself.
def fit(x, y)
- check_sample_array(x)
- check_label_array(y)
+ x = check_convert_sample_array(x)
+ y = check_convert_label_array(y)
check_sample_label_size(x, y)
@classes = Numo::Int32[*y.to_a.uniq.sort]
n_classes = @classes.size
n_features = x.shape[1]
@@ -115,22 +114,22 @@
#
# @param x [Numo::DFloat] (shape: [n_testing_samples, n_training_samples])
# The kernel matrix between testing samples and training samples to compute the scores.
# @return [Numo::DFloat] (shape: [n_testing_samples, n_classes]) Confidence score per sample.
def decision_function(x)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
x.dot(@weight_vec.transpose)
end
# Predict class labels for samples.
#
# @param x [Numo::DFloat] (shape: [n_testing_samples, n_training_samples])
# The kernel matrix between testing samples and training samples to predict the labels.
# @return [Numo::Int32] (shape: [n_testing_samples]) Predicted class label per sample.
def predict(x)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
return Numo::Int32.cast(decision_function(x).ge(0.0)) * 2 - 1 if @classes.size <= 2
n_samples, = x.shape
decision_values = decision_function(x)
@@ -146,10 +145,10 @@
#
# @param x [Numo::DFloat] (shape: [n_testing_samples, n_training_samples])
# The kernel matrix between testing samples and training samples to predict the labels.
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Predicted probability of each class per sample.
def predict_proba(x)
- check_sample_array(x)
+ x = check_convert_sample_array(x)
if @classes.size > 2
probs = 1.0 / (Numo::NMath.exp(@prob_param[true, 0] * decision_function(x) + @prob_param[true, 1]) + 1.0)
return (probs.transpose / probs.sum(axis: 1)).transpose
end