Class: PCA
- Inherits:
-
Object
- Object
- PCA
- Defined in:
- lib/pca.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#explained_variance ⇒ Object
readonly
Returns the value of attribute explained_variance.
-
#explained_variance_ratio ⇒ Object
readonly
Returns the value of attribute explained_variance_ratio.
-
#mean ⇒ Object
Returns the value of attribute mean.
-
#singular_values ⇒ Object
readonly
Returns the value of attribute singular_values.
-
#std ⇒ Object
Returns the value of attribute std.
Instance Method Summary collapse
- #fit(x) ⇒ Object
- #fit_transform(x) ⇒ Object
-
#initialize(opts = {}) ⇒ PCA
constructor
A new instance of PCA.
- #inverse_transform(x) ⇒ Object
- #transform(x) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ PCA
Returns a new instance of PCA.
7 8 9 10 |
# File 'lib/pca.rb', line 7 def initialize opts = {} @n_components = opts[:components] @scale_data = opts[:scale_data] end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
4 5 6 |
# File 'lib/pca.rb', line 4 def components @components end |
#explained_variance ⇒ Object (readonly)
Returns the value of attribute explained_variance.
4 5 6 |
# File 'lib/pca.rb', line 4 def explained_variance @explained_variance end |
#explained_variance_ratio ⇒ Object (readonly)
Returns the value of attribute explained_variance_ratio.
4 5 6 |
# File 'lib/pca.rb', line 4 def explained_variance_ratio @explained_variance_ratio end |
#mean ⇒ Object
Returns the value of attribute mean.
5 6 7 |
# File 'lib/pca.rb', line 5 def mean @mean end |
#singular_values ⇒ Object (readonly)
Returns the value of attribute singular_values.
4 5 6 |
# File 'lib/pca.rb', line 4 def singular_values @singular_values end |
#std ⇒ Object
Returns the value of attribute std.
5 6 7 |
# File 'lib/pca.rb', line 5 def std @std end |
Instance Method Details
#fit(x) ⇒ Object
12 13 14 15 16 |
# File 'lib/pca.rb', line 12 def fit x x = prepare_data x _fit x self end |
#fit_transform(x) ⇒ Object
23 24 25 26 27 |
# File 'lib/pca.rb', line 23 def fit_transform x x = prepare_data x _fit x _transform x end |
#inverse_transform(x) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/pca.rb', line 29 def inverse_transform x x = ensure_matrix x xit = x * @components undo_scale(xit) if @scale_data undo_mean_normalize xit xit end |
#transform(x) ⇒ Object
18 19 20 21 |
# File 'lib/pca.rb', line 18 def transform x x = prepare_data x, use_saved_mean_and_std: true _transform x end |