metbit.dev
Other module in metbit 6.7.0.
import metbit.devClasses
opls_da
Methods
__init__(self, X, y, features_name=None, n_components=2, scale='pareto', kfold=3, estimator='opls', random_state=42)
fit(self)
permutation_test(self, n_permutations=500, cv=3, n_jobs=-1, verbose=10)
vip_scores(self, model=None, features_name=None)
get_vip_scores(self)
vip_plot(self, x_range=9, threshold=2, size=12, width=1000, height=500, filter_=False)
plot_oplsda_scores(self, color_dict=None, symbol=None, symbol_dict=None, fig_height=900, fig_width=1300, marker_size=35, marker_opacity=0.7)
plot_hist(self, nbins_=50, height_=500, width_=1000)
plot_s_scores(self, height_=900, width_=2000, range_color_=[-0.05, 0.05], color_continuous_scale_='jet')
plot_loading(self, height_=900, width_=2000, range_color_=[-0.05, 0.05], color_continuous_scale_='jet')
pca
Principal Component Analysis (PCA) model.
Parameters
Xarray-like, shape (n_samples, n_features)Training data, where n_samples is the number of samples and n_features is the number of features.
labelarray-like, shape (n_samples,)Target data, where n_samples is the number of samples.
features_namearray-like, shape (n_features,), default=NoneName of features.
n_componentsint, default=2Number of components to keep.
scalestr, default='pareto'Method of scaling. 'pareto' for pareto scaling, 'mean' for mean centering, 'uv' for unitvarian scaling.
random_stateint, default=42Random state for permutation test.
test_sizefloat, default=0.3Size of test set.
Examples
import pandas as pd import numpy as np from metbit import pca
# Create a dataset data = pd.DataFrame(np.random.rand(500, 50000)) class_ = pd.Series(np.random.choice(['A', 'B', 'C'], 500), name='Group') time = pd.Series(np.random.choice(['1-wk', '2-wk', '3-wk', '4-wk'], 500), name='Time point')
# Assign X and target X = datasets.iloc[:, 2:] y = datasets['Group'] time = datasets['Time point'] features_name = list(X.columns.astype(float))
## Perform PCA model pca_mod = pca(X=X, label=y, features_name=features_name, n_components=2, scale='pareto', random_state=42, test_size=0.3) pca_mod.fit()
# Visualisation of PCA model pca_mod.plot_observe_variance() pca_mod.plot_cumulative_observed() shape_ = {'1-wk': 'circle', '2-wk': 'square', '3-wk': 'diamond', '4-wk': 'cross'} pca_mod.plot_pca_scores(symbol=time, symbol_dict=shape_) pca_mod.plot_loading_() pca_mod.plot_pca_trajectory(time_=time, time_order={'1-wk': 0, '2-wk': 1, '3-wk': 2, '4-wk': 3}, color_dict={'A': '#636EFA', 'B': '#EF553B', 'C': '#00CC96'}, symbol_dict=shape_)
Methods
__init__(self, X, label, features_name=None, n_components=2, scale='pareto', random_state=42, test_size=0.3)
Initialize the PCA model.
Parameters
Xarray-like, shape (n_samples, n_features)Training data, where n_samples is the number of samples and n_features is the number of features.
labelarray-like, shape (n_samples,)Target data, where n_samples is the number of samples.
features_namearray-like, shape (n_features,), default=NoneName of features.
n_componentsint, default=2Number of components to keep.
scalestr, default='pareto'Method of scaling. 'pareto' for pareto scaling, 'mean' for mean centering, 'uv' for unitvarian scaling.
random_stateint, default=42Random state for permutation test.
test_sizefloat, default=0.3Size of test set.