Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created cookbook for passing vectors/matrix to features object #4142

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions doc/cookbook/source/examples/getting_started/features.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
=======================
Passing data to Shogun
=======================

In this getting started guide, we will look at how to pass data random data to a matrix & pass it through a features object . We will create a matrix as shown :

+-------------+-------------+-----------+-----------+
| | Sample 1 | Sample 2 | Sample 3 |
| | | | |
+=============+=============+===========+===========+
| Feature 1 | 1 | 2 | 3 |
+-------------+-------------+-----------+-----------+
| Feature 2 | 4 | 5 | 6 |
+-------------+-------------+-----------+-----------+

Then, we extract features for example 1 (values 1 and 4)


-------
Example
-------

We start off by creating a real matrix and inserting values 1 through 6.

.. sgexample:: features.sg:create_matrix

Now we can pass the data from the matrix to the features object.

.. sgexample:: features.sg:create_features

We've got a features object containg our data , so we can now extract the features
for Sample 1.

.. sgexample:: features.sg:get_features

This vector now contains values 1 and 4.

----
NOTE
----

It is important to note that conventionally, data is stored in a row-major fashion,
meaning two row vector of size 3.
However, in Shogun, this will be column vectors of dimension 2.

Note that data is stored in column major format, i.e. each column of the matrix corresponds to
an observation / feature vector, where each vector consists of a number of variables that is equal
to the number of rows of the matrix.

Also, it is essential to map the data types of the features object & vector i.e one cannot pass
a vector of integers to a method that expects floats.
Note that features are type-safe, e.g. you can only pass 64 bit floating point numbers to :sgclass:`RealFeatures` .

----------
References
----------
:wiki:`Feature (machine learning)`

:wiki:`Row- and column-major order`

10 changes: 10 additions & 0 deletions doc/cookbook/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Quickstart

quickstart/interfaces

Getting Started
---------------

.. toctree::
:maxdepth: 1
:glob:
:caption: Getting started

examples/getting_started/**

Binary classifier
-----------------

Expand Down
18 changes: 18 additions & 0 deletions examples/meta/src/getting_started/features.sg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#![create_matrix]
RealMatrix real_matrix(2,3)
real_matrix[0,0]= 1
real_matrix[0,1]= 2
real_matrix[0,2]= 3
real_matrix[1,0]= 4
real_matrix[1,1]= 5
real_matrix[1,2]= 6
#![create_matrix]

#![create_features]
RealFeatures features(real_matrix)
#![create_features]

#![get_features]
features.get_feature_vector(0)
#![get_features]