### Install Rumale Gem Source: https://yoshoku.github.io/rumale/doc/index Instructions for installing the Rumale gem. This involves adding the gem to your application's Gemfile and running bundle install, or installing it directly using the gem install command. ```ruby gem 'rumale' ``` ```bash $ bundle ``` ```bash $ gem install rumale ``` -------------------------------- ### RVFLClassifier Initialization and Usage Example (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/NeuralNetwork/RVFLClassifier Demonstrates how to initialize and use the RVFLClassifier for a machine learning task. It requires the 'numo/linalg' and 'rumale/neural_network/rvfl_classifier' libraries. The example shows fitting the model to training data and predicting on testing data. ```ruby require 'numo/linalg' require 'rumale/neural_network/rvfl_classifier' estimator = Rumale::NeuralNetwork::RVFLClassifier.new(hidden_units: 128, reg_param: 100.0) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### NMF Initialization and Transformation Example (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/NMF Demonstrates how to initialize an NMF decomposer and use it to transform sample data. It requires the 'rumale/decomposition/nmf' library. ```ruby require 'rumale/decomposition/nmf' decomposer = Rumale::Decomposition::NMF.new(n_components: 2) representaion = decomposer.fit_transform(samples) ``` -------------------------------- ### GradientBoostingClassifier - Ruby Example Source: https://yoshoku.github.io/rumale/doc/Rumale/Ensemble/GradientBoostingClassifier Example of how to initialize and use the GradientBoostingClassifier from the Rumale library. This involves fitting the model to training data and predicting on testing data. Requires the 'rumale/ensemble/gradient_boosting_classifier' library. ```ruby require 'rumale/ensemble/gradient_boosting_classifier' estimator = \ Rumale::Ensemble::GradientBoostingClassifier.new( n_estimators: 100, learning_rate: 0.3, reg_lambda: 0.001, random_seed: 1) estimator.fit(training_samples, traininig_values) results = estimator.predict(testing_samples) ``` -------------------------------- ### VRTreeClassifier Initialization and Usage Example Source: https://yoshoku.github.io/rumale/doc/Rumale/Tree/VRTreeClassifier This example demonstrates how to initialize and use the VRTreeClassifier for classification tasks. It shows setting hyperparameters like criterion, max_depth, and random_seed, fitting the model to training data, and making predictions on testing data. It requires the 'rumale/tree/vr_tree_classifier' library. ```ruby require 'rumale/tree/vr_tree_classifier' estimator = Rumale::Tree::VRTreeClassifier.new( criterion: 'gini', max_depth: 3, max_leaf_nodes: 10, min_samples_leaf: 5, random_seed: 1) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### VRTreeClassifier Initialization and Usage Source: https://yoshoku.github.io/rumale/doc/Rumale/Tree/VRTreeClassifier This section details how to initialize and use the VRTreeClassifier, including its parameters and a code example. ```APIDOC ## Rumale::Tree::VRTreeClassifier ### Description VRTreeClassifier is a class that implements Variable-Random (VR) tree for classification. **Reference** * Liu, F. T., Ting, K. M., Yu, Y., and Zhou, Z. H., “Spectrum of Variable-Random Trees,” Journal of Artificial Intelligence Research, vol. 32, pp. 355–384, 2008. #### Examples: ```ruby require 'rumale/tree/vr_tree_classifier' estimator = Rumale::Tree::VRTreeClassifier.new( criterion: 'gini', max_depth: 3, max_leaf_nodes: 10, min_samples_leaf: 5, random_seed: 1) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` ### Instance Attribute Summary * **classes** (Numo::Int32, readonly) Return the class labels. * **feature_importances** (Numo::DFloat, readonly) Return the importance for each feature. * **leaf_labels** (Numo::Int32, readonly) Return the labels assigned each leaf. * **rng** (Random, readonly) Return the random generator for random selection of feature index. * **tree** (Node, readonly) Return the learned tree. ### Attributes inherited from Base::Estimator * #params ### Instance Method Summary * **initialize**(criterion: 'gini', alpha: 0.5, max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1, max_features: nil, random_seed: nil) (VRTreeClassifier) Create a new classifier with variable-random tree algorithm. ### Methods inherited from DecisionTreeClassifier * #fit * #predict * #predict_proba ### Methods included from Base::Classifier * #fit * #predict * #score ### Methods inherited from BaseDecisionTree * #apply ## Constructor Details ### initialize(criterion: 'gini', alpha: 0.5, max_depth: nil, max_leaf_nodes: nil, min_samples_leaf: 1, max_features: nil, random_seed: nil) Create a new classifier with variable-random tree algorithm. **Parameters** * **criterion** (String) - The function to measure the quality of a split. Supported criteria are "gini" and "entropy". * **alpha** (Float) - The parameter that controls the degree of randomness in splitting. Default is 0.5. * **max_depth** (Integer, nil) - The maximum depth of the tree. If nil, then nodes are expanded until all leaves are pure or contain less than min_samples_split samples. * **max_leaf_nodes** (Integer, nil) - Grow a tree with max_leaf_nodes in best-first fashion. Best-first grows a node by node based as the reduction of impurity. If nil, then number of leaf nodes is not restricted. * **min_samples_leaf** (Integer) - The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min_samples_leaf training samples in each of the left and right branches. This may prevent overfitting the model. * **max_features** (Integer, Float, String, nil) - The number of features to consider when looking for the best split. If integer, then consider max_features features at each split. If float, then max_features is a percentage and rounds up the children of n_samples. * **random_seed** (Integer, nil) - If an integer value is given, then that value is used as the seed for the random number generator. Otherwise, the random number generator is initialized randomly. **Returns** * (VRTreeClassifier) - The initialized VRTreeClassifier object. ``` -------------------------------- ### ExtraTreesRegressor Example in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Ensemble/ExtraTreesRegressor This code snippet demonstrates how to initialize and use the ExtraTreesRegressor class from the Rumale library for regression tasks. It shows how to set hyperparameters, fit the model to training data, and make predictions on testing data. Ensure the 'rumale-ensemble' gem is installed and accessible. ```ruby @require 'rumale/ensemble/extra_trees_regressor' estimator = \ Rumale::Ensemble::ExtraTreesRegressor.new( n_estimators: 10, criterion: 'mse', max_depth: 3, max_leaf_nodes: 10, min_samples_leaf: 5, random_seed: 1) estimator.fit(training_samples, traininig_values) results = estimator.predict(testing_samples) ``` -------------------------------- ### HDBSCAN Clustering with Rumale Source: https://yoshoku.github.io/rumale/doc/Rumale/Clustering/HDBSCAN Example of initializing and using the HDBSCAN analyzer to fit and predict cluster labels for given samples. ```ruby require 'rumale/clustering/hdbscan' analyzer = Rumale::Clustering::HDBSCAN.new(min_samples: 5) cluster_labels = analyzer.fit_predict(samples) ``` -------------------------------- ### StackingClassifier Example in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Ensemble/StackingClassifier This example demonstrates how to initialize and use the StackingClassifier in Ruby. It involves setting up base estimators, a meta-estimator, fitting the model to training data, and predicting on testing data. Dependencies include various Rumale estimators like LogisticRegression, MLPClassifier, and RandomForestClassifier. ```ruby require 'rumale/ensemble/stacking_classifier' estimators = { lgr: Rumale::LinearModel::LogisticRegression.new(reg_param: 1e-2), mlp: Rumale::NeuralNetwork::MLPClassifier.new(hidden_units: [256], random_seed: 1), rnd: Rumale::Ensemble::RandomForestClassifier.new(random_seed: 1) } meta_estimator = Rumale::LinearModel::LogisticRegression.new classifier = Rumale::Ensemble::StackedClassifier.new( estimators: estimators, meta_estimator: meta_estimator, random_seed: 1 ) classifier.fit(training_samples, training_labels) results = classifier.predict(testing_samples) ``` -------------------------------- ### Install Numo::Linalg Alternative Gem (Bash) Source: https://yoshoku.github.io/rumale/doc/index This command installs the `numo-linalg-alt` gem, which provides an alternative implementation for linear algebra operations using Numo::NArray. This can potentially accelerate machine learning algorithms in Rumale that frequently perform matrix and vector products by leveraging OpenBLAS libraries. ```bash $ gem install numo-linalg-alt ``` -------------------------------- ### MeanShift Clustering with Rumale Source: https://yoshoku.github.io/rumale/doc/Rumale/Clustering/MeanShift This example demonstrates how to initialize and use the MeanShift clustering algorithm from the Rumale library. It takes samples as input and predicts cluster labels. ```ruby require 'rumale/clustering/mean_shift' analyzer = Rumale::Clustering::MeanShift.new(bandwidth: 1.5) cluster_labels = analyzer.fit_predict(samples) ``` -------------------------------- ### FactorAnalysis Instance Methods Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/FactorAnalysis Details of the instance methods available for the FactorAnalysis class, including fit, fit_transform, initialize, and transform. ```APIDOC ## Instance Method Summary * #**fit**(x) ⇒ FactorAnalysis Fit the model with given training data. * #**fit_transform**(x) ⇒ Numo::DFloat Fit the model with training data, and then transform them with the learned model. * #**initialize**(n_components: 2, max_iter: 100, tol: 1e-8) ⇒ FactorAnalysis (constructor) Create a new transformer with factor analysis. * #**transform**(x) ⇒ Numo::DFloat Transform the given data with the learned model. ``` -------------------------------- ### Install Parallel Gem (Bash) Source: https://yoshoku.github.io/rumale/doc/index This command installs the `parallel` gem, which is used by Rumale to enable parallel processing for several of its estimators. Installing this gem allows Rumale to distribute computations across multiple processors, potentially speeding up training times. ```bash $ gem install parallel ``` -------------------------------- ### FScore Example Usage (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/EvaluationMeasure/FScore Example of how to instantiate and use the FScore class to calculate scores. It requires the 'rumale/evaluation_measure/f_score' library. ```Ruby require 'rumale/evaluation_measure/f_score' evaluator = Rumale::EvaluationMeasure::FScore.new puts evaluator.score(ground_truth, predicted) ``` -------------------------------- ### KernelCalculator: Initialize and Use in a Pipeline Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/KernelCalculator This example demonstrates how to initialize Rumale::Preprocessing::KernelCalculator with specific kernel parameters (rbf, gamma) and integrate it into a Rumale::Pipeline for a complete machine learning workflow. It shows fitting the pipeline with training data and making predictions on test data. ```ruby require 'rumale/preprocessing/kernel_calculator' require 'rumale/kernel_machine/kernel_ridge' require 'rumale/pipeline/pipeline' transformer = Rumale::Preprocessing::KernelCalculator.new(kernel: 'rbf', gamma: 0.5) regressor = Rumale::KernelMachine::KernelRidge.new pipeline = Rumale::Pipeline::Pipeline.new( steps: { trs: transformer, est: regressor } ) pipeline.fit(x_train, y_train) results = pipeline.predict(x_test) ``` -------------------------------- ### KNeighborsClassifier Example (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/NearestNeighbors/KNeighborsClassifier Demonstrates how to initialize, train, and predict using the KNeighborsClassifier. It requires the 'rumale/nearest_neighbors/k_neighbors_classifier' library and uses training samples and labels to fit the model, then predicts labels for testing samples. ```ruby require 'rumale/nearest_neighbors/k_neighbors_classifier' estimator = Rumale::NearestNeighbors::KNeighborsClassifier.new(n_neighbors: 5) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### Calculate Silhouette Score Example Source: https://yoshoku.github.io/rumale/doc/Rumale/EvaluationMeasure/SilhouetteScore An example demonstrating how to use the SilhouetteScore class to calculate the silhouette coefficient. It requires the 'rumale/evaluation_measure/silhouette_score' library and takes input data 'x' and cluster predictions 'predicted' to compute the score. ```ruby require 'rumale/evaluation_measure/silhouette_score' evaluator = Rumale::EvaluationMeasure::SilhouetteScore.new puts evaluator.score(x, predicted) ``` -------------------------------- ### NegationNB Classifier Initialization and Usage (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/NaiveBayes/NegationNB Demonstrates how to initialize and use the Rumale::NaiveBayes::NegationNB classifier. This involves creating an instance, fitting it with training data, and then predicting labels for testing data. The smoothing_param can be adjusted during initialization. ```ruby require 'rumale/naive_bayes/negation_nb' estimator = Rumale::NaiveBayes::NegationNB.new(smoothing_param: 1.0) estimator.fit(training_samples, training_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### SVC: Initialize, Fit, and Predict in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/LinearModel/SVC Demonstrates the basic usage of Rumale::LinearModel::SVC. It includes initializing the estimator, fitting it with training data, and predicting labels for testing samples. Requires the 'rumale/linear_model/svc' library. ```ruby require 'rumale/linear_model/svc' estimator = Rumale::LinearModel::SVC.new(reg_param: 1.0) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### GaussianMixture Clustering with Rumale Source: https://yoshoku.github.io/rumale/doc/Rumale/Clustering/GaussianMixture Demonstrates how to initialize and use the GaussianMixture class for cluster analysis. It shows fitting the model and predicting cluster labels for samples. This example assumes the 'samples' data is already prepared. ```ruby require 'rumale/clustering/gaussian_mixture' analyzer = Rumale::Clustering::GaussianMixture.new(n_clusters: 10, max_iter: 50) cluster_labels = analyzer.fit_predict(samples) ``` -------------------------------- ### FeatureUnion Usage Example (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/Pipeline/FeatureUnion Demonstrates how to use FeatureUnion to combine different transformers, such as RBF kernel approximation and PCA. It shows the process of initializing FeatureUnion, fitting it with training data, and then predicting or transforming test data. The example highlights how the number of output features is determined by the combined transformers. ```ruby require 'rumale/kernel_approximation/rbf' require 'rumale/decomposition/pca' require 'rumale/pipeline/feature_union' fu = Rumale::Pipeline::FeatureUnion.new( transformers: { 'rbf': Rumale::KernelApproximation::RBF.new(gamma: 1.0, n_components: 96, random_seed: 1), 'pca': Rumale::Decomposition::PCA.new(n_components: 32) } ) fu.fit(training_samples, traininig_labels) results = fu.predict(testing_samples) # > p results.shape[1] # > 128 ``` -------------------------------- ### Bernoulli Naive Bayes Classifier Example (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/NaiveBayes/BernoulliNB Demonstrates how to initialize and use the Bernoulli Naive Bayes classifier from the Rumale library. It shows the process of creating an estimator, fitting it with training data, and making predictions on testing data. Dependencies include the 'rumale/naive_bayes/bernoulli_nb' library. ```ruby require 'rumale/naive_bayes/bernoulli_nb' estimator = Rumale::NaiveBayes::BernoulliNB.new(smoothing_param: 1.0, bin_threshold: 0.0) estimator.fit(training_samples, training_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### TF-IDF Transformation Example using HashVectorizer and TfidfTransformer in Rumale Source: https://yoshoku.github.io/rumale/doc/Rumale/FeatureExtraction/TfidfTransformer This example demonstrates how to use Rumale's HashVectorizer to convert sparse text data into a term frequency matrix, followed by TfidfTransformer to convert this matrix into a tf-idf representation. It shows the input and output of both steps. ```ruby require 'rumale/feature_extraction/hash_vectorizer' require 'rumale/feature_extraction/tfidf_transformer' encoder = Rumale::FeatureExtraction::HashVectorizer.new x = encoder.fit_transform([ { foo: 1, bar: 2 }, { foo: 3, baz: 1 } ]) # > pp x # Numo::DFloat#shape=[2,3] # [[2, 0, 1], # [0, 1, 3]] transformer = Rumale::FeatureExtraction::TfidfTransformer.new x_tfidf = transformer.fit_transform(x) # > pp x_tfidf # Numo::DFloat#shape=[2,3] # [[0.959056, 0, 0.283217], # [0, 0.491506, 0.870874]] ``` -------------------------------- ### KernelRidge Class API Source: https://yoshoku.github.io/rumale/doc/Rumale/KernelMachine/KernelRidge Documentation for the KernelRidge class, including its overview, instance attributes, and methods. ```APIDOC ## Class: Rumale::KernelMachine::KernelRidge ### Description KernelRidge is a class that implements kernel ridge regression. #### Examples: ```ruby require 'numo/linalg/autoloader' require 'rumale/pairwise_metric' require 'rumale/kernel_machine/kernel_ridge' kernel_mat_train = Rumale::PairwiseMetric::rbf_kernel(training_samples) kridge = Rumale::KernelMachine::KernelRidge.new(reg_param: 1.0) kridge.fit(kernel_mat_train, traininig_values) kernel_mat_test = Rumale::PairwiseMetric::rbf_kernel(test_samples, training_samples) results = kridge.predict(kernel_mat_test) ``` ### Instance Attribute Summary * **weight_vec** (Numo::DFloat) - readonly Return the weight vector. ### Instance Method Summary * **fit**(x, y) (KernelRidge) Fit the model with given training data. * **initialize**(reg_param: 1.0) (KernelRidge) - constructor Create a new regressor with kernel ridge regression. * **predict**(x) (Numo::DFloat) Predict values for samples. ### Constructor Details #### #**initialize**(reg_param: 1.0) ⇒ `KernelRidge` Create a new regressor with kernel ridge regression. Parameters: * **reg_param** (Float/Numo::DFloat) _(defaults to: 1.0)_ — The regularization parameter. ### Request Example ```json { "reg_param": 1.0 } ``` ### Response #### Success Response (200) - **weight_vec** (Numo::DFloat) - The weight vector. #### Response Example ```json { "weight_vec": [1.0, 2.0, 3.0] } ``` ``` -------------------------------- ### PCA Instance Methods Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/PCA Provides documentation for core PCA instance methods: fit, fit_transform, and inverse_transform. ```APIDOC ## fit(x) ### Description Fit the model with given training data. ### Method `fit` ### Parameters #### Path Parameters - **x** (`Numo::DFloat`) - Required - The training data to be used for fitting the model. (shape: [n_samples, n_features]) ### Returns - `PCA` - The learned transformer itself. --- ## fit_transform(x) ### Description Fit the model with training data, and then transform them with the learned model. ### Method `fit_transform` ### Parameters #### Path Parameters - **x** (`Numo::DFloat`) - Required - The training data to be used for fitting the model. (shape: [n_samples, n_features]) ### Returns - `Numo::DFloat` - The transformed data. (shape: [n_samples, n_components]) --- ## inverse_transform(z) ### Description Inverse transform the given transformed data with the learned model. ### Method `inverse_transform` ### Parameters #### Path Parameters - **z** (`Numo::DFloat`) - Required - The transformed data to be inverted. ### Returns - `Numo::DFloat` - The original data. ``` -------------------------------- ### Rumale Dataset Handling Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/MaxAbsScaler Documentation for dataset handling utilities in the Rumale library. ```APIDOC ## Namespace Rumale::Dataset ### Description Utilities for handling and managing datasets within the Rumale library. ``` -------------------------------- ### Get Estimator Attribute Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/CrossValidation Retrieves the estimator that is being evaluated. This attribute holds the classifier instance passed during initialization. ```ruby def estimator @estimator end ``` -------------------------------- ### SparsePCA: Initialize, Fit, and Transform Data (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/SparsePCA This example demonstrates how to use the Rumale::Decomposition::SparsePCA class. It shows initialization with specific parameters, fitting the model to sample data, and transforming the data to obtain its sparse representation. Dependencies include 'numo/linalg' for numerical operations and 'rumale/decomposition/sparse_pca' for the SparsePCA class itself. ```ruby require 'numo/linalg' require 'rumale/decomposition/sparse_pca' decomposer = Rumale::Decomposition::SparsePCA.new(n_components: 2, reg_param: 0.1) representaion = decomposer.fit_transform(samples) sparse_components = decomposer.components ``` -------------------------------- ### Get Evaluator Attribute Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/CrossValidation Retrieves the evaluator used for calculating scores. This attribute holds the evaluator instance passed during initialization. ```ruby def evaluator @evaluator end ``` -------------------------------- ### Initialize and Use Linear Regression Source: https://yoshoku.github.io/rumale/doc/Rumale/LinearModel/LinearRegression Demonstrates how to initialize a LinearRegression estimator, fit it with training data, and make predictions on testing data. It also shows how to specify the 'svd' solver if Numo::Linalg is installed. ```ruby require 'rumale/linear_model/linear_regression' estimator = Rumale::LinearModel::LinearRegression.new estimator.fit(training_samples, traininig_values) results = estimator.predict(testing_samples) # If Numo::Linalg is installed, you can specify 'svd' for the solver option. require 'numo/linalg/autoloader' require 'rumale/linear_model/linear_regression' estimator = Rumale::LinearModel::LinearRegression.new(solver: 'svd') estimator.fit(training_samples, traininig_values) results = estimator.predict(testing_samples) ``` -------------------------------- ### Get Max Absolute Vector in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/MaxAbsScaler Retrieves the pre-calculated vector containing the maximum absolute value for each feature. This is a read-only attribute. ```ruby def max_abs_vec @max_abs_vec end ``` -------------------------------- ### SVR: Initialize and Fit Model (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/LinearModel/SVR This snippet demonstrates how to initialize a Support Vector Regressor (SVR) model with specified parameters and then fit it to training data. It requires the 'rumale/linear_model/svr' library. The input 'training_samples' and 'traininig_target_values' are expected to be compatible data structures for the model. ```ruby require 'rumale/linear_model/svr' estimator = Rumale::LinearModel::SVR.new(reg_param: 1.0, epsilon: 0.1) estimator.fit(training_samples, traininig_target_values) results = estimator.predict(testing_samples) ``` -------------------------------- ### Get VotingClassifier Estimators Attribute Source: https://yoshoku.github.io/rumale/doc/Rumale/Ensemble/VotingClassifier Returns the sub-classifiers that were used for voting in the VotingClassifier. This attribute is read-only. ```ruby # File 'rumale-ensemble/lib/rumale/ensemble/voting_classifier.rb', line 33 def estimators @estimators end ``` -------------------------------- ### Get VotingClassifier Classes Attribute Source: https://yoshoku.github.io/rumale/doc/Rumale/Ensemble/VotingClassifier Returns the class labels learned by the VotingClassifier. This attribute is read-only. ```ruby # File 'rumale-ensemble/lib/rumale/ensemble/voting_classifier.rb', line 37 def classes @classes end ``` -------------------------------- ### MinMaxScaler API Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/MinMaxScaler Documentation for the MinMaxScaler class, including its attributes, methods, and constructor. ```APIDOC ## Class: Rumale::Preprocessing::MinMaxScaler ### Description Normalize samples by scaling each feature to a given range. ### Attributes #### Instance Attributes - **max_vec** (Numo::DFloat) - Readonly: Returns the vector consisting of the maximum value for each feature. - **min_vec** (Numo::DFloat) - Readonly: Returns the vector consisting of the minimum value for each feature. ### Methods #### Instance Methods - **fit**(x) - Description: Calculate the minimum and maximum value of each feature for scaling. - Returns: MinMaxScaler - **fit_transform**(x) - Description: Calculate the minimum and maximum values, and then normalize samples to feature_range. - Returns: Numo::DFloat - **initialize**(feature_range: [0.0, 1.0]) - Description: Creates a new normalizer for scaling each feature to a given range. - Parameters: - **feature_range** (Array) - Optional - The desired range of samples. Defaults to `[0.0, 1.0]`. - Returns: MinMaxScaler - **transform**(x) - Description: Perform scaling the given samples according to feature_range. - Returns: Numo::DFloat ### Constructor Details #### #initialize(feature_range: [0.0, 1.0]) Creates a new normalizer for scaling each feature to a given range. Parameters: - **feature_range** (Array) _(defaults to:`[0.0, 1.0]`)_ — The desired range of samples. ### Examples ```ruby require 'rumale/preprocessing/min_max_scaler' normalizer = Rumale::Preprocessing::MinMaxScaler.new(feature_range: [0.0, 1.0]) new_training_samples = normalizer.fit_transform(training_samples) new_testing_samples = normalizer.transform(testing_samples) ``` ``` -------------------------------- ### Factor Analysis Initialization and Transformation (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/FactorAnalysis Demonstrates how to initialize a FactorAnalysis object and use it to fit and transform sample data. Requires the 'numo/linalg' and 'rumale/decomposition/factor_analysis' libraries. The fit_transform method takes a dataset (samples) and returns its lower-dimensional representation. ```ruby require 'numo/linalg/autoloader' require 'rumale/decomposition/factor_analysis' decomposer = Rumale::Decomposition::FactorAnalysis.new(n_components: 2) representaion = decomposer.fit_transform(samples) ``` -------------------------------- ### Get Number of Output Features Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/PolynomialFeatures Returns the calculated number of output polynomial features. This is a read-only attribute. ```ruby # File 'rumale-preprocessing/lib/rumale/preprocessing/polynomial_features.rb', line 40 def n_output_features @n_output_features end ``` -------------------------------- ### Get Return Train Score Attribute Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/CrossValidation Retrieves the boolean flag indicating whether to calculate the score of the training dataset. This is determined at initialization. ```ruby def return_train_score @return_train_score end ``` -------------------------------- ### PCA Initialization and Transformation in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/PCA Demonstrates how to initialize and use the PCA class for dimensionality reduction. It shows examples with different solver options ('fpt' and 'evd') and how the solver is chosen automatically if Numo::Linalg is loaded. The fit_transform method takes sample data and returns the transformed representation. ```ruby require 'rumale/decomposition/pca' decomposer = Rumale::Decomposition::PCA.new(n_components: 2, solver: 'fpt') representaion = decomposer.fit_transform(samples) ``` ```ruby require 'numo/linalg/autoloader' require 'rumale/decomposition/pca' decomposer = Rumale::Decomposition::PCA.new(n_components: 2, solver: 'evd') representaion = decomposer.fit_transform(samples) ``` ```ruby # If Numo::Linalg is loaded and the solver option is not given, # the solver option is choosen 'evd' automatically. decomposer = Rumale::Decomposition::PCA.new(n_components: 2) representaion = decomposer.fit_transform(samples) ``` -------------------------------- ### Rumale Metric Learning Algorithms Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/MaxAbsScaler API documentation for metric learning algorithms in the Rumale library. ```APIDOC ## Namespace Rumale::MetricLearning ### Description This namespace provides algorithms for learning distance metrics. ### Classes * **FisherDiscriminantAnalysis** (inherits from Estimator) * **LocalFisherDiscriminantAnalysis** (inherits from Estimator) ``` -------------------------------- ### Get FScore Average Type (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/EvaluationMeasure/FScore Retrieves the average type used for F1-score calculation. This attribute is read-only. ```Ruby def average @average end ``` -------------------------------- ### FastICA Instance Methods Source: https://yoshoku.github.io/rumale/doc/Rumale/Decomposition/FastICA Documentation for instance methods of the FastICA class. ```APIDOC ## FastICA Instance Methods ### `fit(x)` #### Description Fit the model with given training data. #### Method `fit` #### Parameters - **x** (Numo::DFloat) - The training data to be used for fitting the model. (shape: [n_samples, n_features]) #### Returns - **FastICA** - The learned transformer itself. ### `fit_transform(x)` #### Description Fit the model with training data, and then transform them with the learned model. #### Method `fit_transform` #### Parameters - **x** (Numo::DFloat) - The training data to be used for fitting the model. (shape: [n_samples, n_features]) #### Returns - **Numo::DFloat** - The transformed data (shape: [n_samples, n_components]) ### `inverse_transform(z)` #### Description Inverse transform the given transformed data with the learned model. #### Method `inverse_transform` #### Parameters - **z** (Numo::DFloat) - The transformed data to be inverted. (shape: [n_samples, n_components]) #### Returns - **Numo::DFloat** - The original data (shape: [n_samples, n_features]) ### `transform(x)` #### Description Transform the given data with the learned model. #### Method `transform` #### Parameters - **x** (Numo::DFloat) - The data to be transformed. (shape: [n_samples, n_features]) #### Returns - **Numo::DFloat** - The transformed data (shape: [n_samples, n_components]) ``` -------------------------------- ### ROCAUC Class API Source: https://yoshoku.github.io/rumale/doc/Rumale/EvaluationMeasure/ROCAUC Documentation for the ROCAUC class, including its overview, examples, and instance methods for calculating ROC AUC. ```APIDOC ## Rumale::EvaluationMeasure::ROCAUC ### Description ROCAUC is a class that calculates the area under the receiver operating characteristic curve from predicted scores. ### Method N/A (Class Documentation) ### Endpoint N/A (Class Documentation) ### Parameters N/A (Class Documentation) ### Request Example ```ruby require 'rumale/preprocessing' require 'rumale/linear_model' require 'rumale/evaluation_measure/roc_auc' # Encode labels to integer array. labels = %w[A B B C A A C C C A] label_encoder = Rumale::Preprocessing::LabelEncoder.new y = label_encoder.fit_transform(labels) # Fit classifier. classifier = Rumale::LinearModel::LogisticRegression.new classifier.fit(x, y) # Predict class probabilities. y_score = classifier.predict_proba(x) # Encode labels to one-hot vectors. one_hot_encoder = Rumale::Preprocessing::OneHotEncoder.new y_onehot = one_hot_encoder.fit_transform(y) # Calculate ROC AUC. evaluator = Rumale::EvaluationMeasure::ROCAUC.new puts evaluator.score(y_onehot, y_score) ``` ### Response N/A (Class Documentation) --- ``` ```APIDOC ## POST /roc_auc/auc ### Description Calculates the area under the ROC curve using the trapezoidal rule. ### Method POST ### Endpoint `/roc_auc/auc` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **x** (Array>) - Required - The ground truth target values. - **y** (Array>) - Required - The target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded prediction values. ### Request Example ```json { "x": [[0, 1], [1, 0], [0, 1], [1, 0]], "y": [[0.1, 0.9], [0.8, 0.2], [0.3, 0.7], [0.6, 0.4]] } ``` ### Response #### Success Response (200) - **auc_score** (Float) - The calculated area under the ROC curve. #### Response Example ```json { "auc_score": 0.75 } ``` --- ``` ```APIDOC ## POST /roc_auc/roc_curve ### Description Calculates the receiver operating characteristic curve. ### Method POST ### Endpoint `/roc_auc/roc_curve` ### Parameters #### Path Parameters N/A #### Query Parameters - **pos_label** (Integer) - Optional - The label considered as the positive label. #### Request Body - **y_true** (Array) - Required - True binary labels. - **y_score** (Array) - Required - Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded prediction values. ### Request Example ```json { "y_true": [0, 1, 1, 0, 1, 0], "y_score": [0.1, 0.8, 0.7, 0.2, 0.9, 0.3], "pos_label": 1 } ``` ### Response #### Success Response (200) - **fpr** (Array) - False positive rates. - **tpr** (Array) - True positive rates. - **thresholds** (Array) - Thresholds used to compute fpr and tpr. #### Response Example ```json { "fpr": [0.0, 0.0, 0.5, 0.5, 1.0], "tpr": [0.0, 0.6666666666666666, 0.6666666666666666, 1.0, 1.0], "thresholds": [1.0, 0.9, 0.8, 0.7, 0.3] } ``` --- ``` ```APIDOC ## POST /roc_auc/score ### Description Calculates the area under the receiver operation characteristic curve (ROC AUC). ### Method POST ### Endpoint `/roc_auc/score` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **y_true** (Array>) - Required - Ground truth (correct) labels. - **y_score** (Array>) - Required - Estimated probabilities or confidence values of the positive class. ### Request Example ```json { "y_true": [[0, 1], [1, 0], [0, 1], [1, 0]], "y_score": [[0.1, 0.9], [0.8, 0.2], [0.3, 0.7], [0.6, 0.4]] } ``` ### Response #### Success Response (200) - **roc_auc_score** (Float) - The calculated ROC AUC score. #### Response Example ```json { "roc_auc_score": 0.75 } ``` --- ``` -------------------------------- ### Get Class Labels from DecisionTreeClassifier in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Tree/DecisionTreeClassifier Retrieves the unique class labels present in the training data. This attribute is read-only and is determined after the model has been fitted. ```ruby # File 'rumale-tree/lib/rumale/tree/decision_tree_classifier.rb', line 25 def classes @classes end ``` -------------------------------- ### Rumale Kernel Machines Source: https://yoshoku.github.io/rumale/doc/Rumale/Base Documentation for kernel machine algorithms in Rumale. ```APIDOC ## Rumale Kernel Machines ### Description This section covers kernel machine algorithms implemented in Rumale, utilizing kernel methods for non-linear modeling. ### Classes * **Rumale::KernelMachine::KernelFDA** * Inherits from: EstimatorRumale::KernelMachine * Description: Kernel Fisher Discriminant Analysis. * **Rumale::KernelMachine::KernelPCA** * Inherits from: EstimatorRumale::KernelMachine * Description: Kernel Principal Component Analysis. * **Rumale::KernelMachine::KernelRidge** * Inherits from: EstimatorRumale::KernelMachine * Description: Kernel Ridge Regression. * **Rumale::KernelMachine::KernelRidgeClassifier** * Inherits from: EstimatorRumale::KernelMachine * Description: Kernel Ridge Classification. * **Rumale::KernelMachine::KernelSVC** * Inherits from: EstimatorRumale::KernelMachine * Description: Kernel Support Vector Classification. ``` -------------------------------- ### Get Active Features from OneHotEncoder Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/OneHotEncoder Retrieves the indices of feature values that are present in the training dataset. This is a read-only attribute. ```ruby # File 'rumale-preprocessing/lib/rumale/preprocessing/one_hot_encoder.rb', line 33 def active_features @active_features end ``` -------------------------------- ### Initialize KernelFDA Source: https://yoshoku.github.io/rumale/doc/Rumale/KernelMachine/KernelFDA Initializes a new KernelFDA transformer. It accepts the number of components and a regularization parameter. Dependencies include the base transformer class from Rumale. The method sets up internal parameters for subsequent operations. ```ruby # File 'rumale-kernel_machine/lib/rumale/kernel_machine/kernel_fda.rb', line 36 def initialize(n_components: nil, reg_param: 1e-8) super() @params = { n_components: n_components, reg_param: reg_param } end ``` -------------------------------- ### Get Splitter Attribute Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/CrossValidation Retrieves the splitter used for dividing the dataset into training and testing sets. This attribute holds the splitter instance passed during initialization. ```ruby def splitter @splitter end ``` -------------------------------- ### Lasso Regression: Fit and Predict (Ruby) Source: https://yoshoku.github.io/rumale/doc/Rumale/LinearModel/Lasso Demonstrates how to initialize, fit, and predict using the Lasso regression model. Requires the rumale/linear_model/lasso library. ```ruby require 'rumale/linear_model/lasso' estimator = Rumale::LinearModel::Lasso.new(reg_param: 0.1) estimator.fit(training_samples, traininig_values) results = estimator.predict(testing_samples) ``` -------------------------------- ### RVFLClassifier Documentation Source: https://yoshoku.github.io/rumale/doc/Rumale/NeuralNetwork/RVFLClassifier Details on the RVFLClassifier class, including its inheritance, included modules, definition path, overview, references, and examples. ```APIDOC ## Class: Rumale::NeuralNetwork::RVFLClassifier ### Description RVFLClassifier is a class that implements classifier based on random vector functional link (RVFL) network. The current implementation uses sigmoid function as activation function. **Reference** * Malik, A. K., Gao, R., Ganaie, M. A., Tanveer, M., and Suganthan, P. N., “Random vector functional link network: recent developments, applications, and future directions,” Applied Soft Computing, vol. 143, 2023. * Zhang, L., and Suganthan, P. N., “A comprehensive evaluation of random vector functional link networks,” Information Sciences, vol. 367–368, pp. 1094–1105, 2016. ### Method N/A (This is a class documentation) ### Endpoint N/A (This is a class documentation) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ruby require 'numo/linalg' require 'rumale/neural_network/rvfl_classifier' estimator = Rumale::NeuralNetwork::RVFLClassifier.new(hidden_units: 128, reg_param: 100.0) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` ### Response #### Success Response (200) N/A #### Response Example N/A ## Instance Attribute Summary * **#classes** ⇒ Numo::Int32 (readonly) Return the class labels. * **#random_bias** ⇒ Numo::DFloat (readonly) Return the bias vector in the hidden layer of RVFL network. * **#random_weight_vec** ⇒ Numo::DFloat (readonly) Return the weight vector in the hidden layer of RVFL network. * **#rng** ⇒ Random (readonly) Return the random generator. * **#weight_vec** ⇒ Numo::DFloat (readonly) Return the weight vector. ### Attributes inherited from Base::Estimator * **#params** ``` -------------------------------- ### Rumale Kernel Machine Algorithms Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/MaxAbsScaler API documentation for kernel machine algorithms in the Rumale library. ```APIDOC ## Namespace Rumale::KernelMachine ### Description This namespace provides algorithms based on kernel methods. ### Classes * **KernelFDA** (inherits from Estimator) * **KernelPCA** (inherits from Estimator) * **KernelRidge** (inherits from Estimator) * **KernelRidgeClassifier** (inherits from Estimator) * **KernelSVC** (inherits from Estimator) ``` -------------------------------- ### Initialize and Use MiniBatchKMeans for Clustering Source: https://yoshoku.github.io/rumale/doc/Rumale/Clustering/MiniBatchKMeans Demonstrates how to create an instance of MiniBatchKMeans, fit it to sample data, and predict cluster labels. This involves initializing the analyzer with specific parameters like the number of clusters and maximum iterations. ```ruby require 'rumale/clustering/mini_batch_k_means' analyzer = Rumale::Clustering::MiniBatchKMeans.new(n_clusters: 10, max_iter: 50, batch_size: 50, random_seed: 1) cluster_labels = analyzer.fit_predict(samples) ``` -------------------------------- ### Get Best Score in GridSearchCV Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/GridSearchCV Retrieves the highest score achieved by the estimator when trained with the best identified parameters. This is a read-only attribute. ```ruby def best_score @best_score end ``` -------------------------------- ### MinMaxScaler Initialization and Usage in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Preprocessing/MinMaxScaler Demonstrates how to initialize and use the MinMaxScaler for feature scaling. It includes fitting the scaler to training data and transforming both training and testing samples. ```ruby require 'rumale/preprocessing/min_max_scaler' normalizer = Rumale::Preprocessing::MinMaxScaler.new(feature_range: [0.0, 1.0]) new_training_samples = normalizer.fit_transform(training_samples) new_testing_samples = normalizer.transform(testing_samples) ``` -------------------------------- ### Get Best Index in GridSearchCV Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/GridSearchCV Returns the index corresponding to the best parameter set identified during the cross-validation process. This is a read-only attribute. ```ruby def best_index @best_index end ``` -------------------------------- ### GroupShuffleSplit Initialization and Usage Example Source: https://yoshoku.github.io/rumale/doc/Rumale/ModelSelection/GroupShuffleSplit Demonstrates how to initialize and use the GroupShuffleSplit class for cross-validation. It generates train and test indices based on provided data and group labels. ```ruby require 'rumale/model_selection/group_shuffle_split' cv = Rumale::ModelSelection::GroupShuffleSplit.new(n_splits: 2, test_size: 0.2, random_seed: 1) x = Numo::DFloat.new(8, 2).rand groups = Numo::Int32[1, 1, 1, 2, 2, 3, 3, 3] cv.split(x, nil, groups).each do |train_ids, test_ids| puts '---' pp train_ids pp test_ids end ``` -------------------------------- ### SGDClassifier: Fit and Predict with Rumale Source: https://yoshoku.github.io/rumale/doc/Rumale/LinearModel/SGDClassifier This example demonstrates how to instantiate and use the SGDClassifier from the Rumale library. It shows the process of initializing the estimator with specific parameters, fitting it to training data, and then using it to predict on testing data. Dependencies include the 'rumale/linear_model/sgd_classifier' library. ```ruby require 'rumale/linear_model/sgd_classifier' estimator = Rumale::LinearModel::SGDClassifier.new(loss: 'hinge', reg_param: 1.0, max_iter: 1000, batch_size: 50, random_seed: 1) estimator.fit(training_samples, traininig_labels) results = estimator.predict(testing_samples) ``` -------------------------------- ### Get Random Generator from DecisionTreeClassifier in Ruby Source: https://yoshoku.github.io/rumale/doc/Rumale/Tree/DecisionTreeClassifier Returns the random number generator used internally by the classifier. This is useful for controlling the randomness in feature selection during tree building. ```ruby # File 'rumale-tree/lib/rumale/tree/decision_tree_classifier.rb', line 37 def rng @rng end ```