/
You are viewing the documentation for metbit 1.7.3. Change release context

metbit.metbit

Analysis and models module in metbit 1.7.3.

import metbit.metbit

Classes

opls_da

Methods

__init__(self, X, y, features_name=None, n_components=2, scale='pareto', kfold=3, estimator='opls', random_state=42, auto_ncomp=True)
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 score

Parameters

modelobject, default=None

OPLS-DA model.

features_namearray-like, shape (n_features,), default=None

Name of features.

get_vip_scores(self, filter_=False, threshold=1)

Get VIP score

Parameters

filter_bool, default=False

If True, filter VIP score based on threshold.

thresholdint, default=1

Threshold of VIP score.

vip_plot(self, x_range=9, threshold=2, size=12, width=1000, height=500, filter_=False, vip_trans_form=False)

Plot VIP score

Parameters

x_rangeint, default=9

Range of x-axis.

thresholdint, default=2

Threshold of VIP score.

sizeint, default=12

Size of the marker.

widthint, default=1000

Width of the figure.

heightint, default=500

Height of the figure.

filter_bool, default=False

If True, filter VIP score based on threshold.

plot_oplsda_scores(self, color_=None, color_dict=None, symbol_=None, symbol_dict=None, fig_height=900, fig_width=1300, marker_size=35, marker_opacity=0.7)

Plot OPLS-DA scores plot

Parameters

color_array-like, shape (n_samples,), default=None

color_ of the group. If None, color_ will be based on the group in y.

color_dictdict, default=None

Dictionary of color_ for the group. If None, color_ will be based on the group in y.

symbol_array-like, shape (n_samples,), default=None

symbol_ of the group. If None, symbol_ will be based on the group in y.

symbol_dictdict, default=None

Dictionary of symbol_ for the group. If None, symbol_ will be based on the group in y.

fig_heightint, default=900

Height of the figure.

fig_widthint, default=1300

Width of the figure.

marker_sizeint, default=35

Size of the marker.

marker_opacityfloat, default=0.7

Opacity of the marker.

plot_hist(self, nbins_=50, height_=500, width_=1000)

Plot histogram of permutation scores

Parameters

nbins_int, default=50

Number of bins for histogram.

height_int, default=500

Height of the figure.

width_int, default=1000

Width of the figure.

plot_s_scores(self, height_=900, width_=2000, range_color_=[-0.05, 0.05], color_continuous_scale_='jet')

Plot S-plot

Parameters

height_int, default=900

Height of the figure.

width_int, default=2000

Width of the figure.

range_colorlist, default=[-0.05,0.05]

Range of color_ for the plot.

color_continuous_scale_str, default='jet'

color_ scale for the plot.

plot_loading(self, height_=900, width_=2000, range_color_=[-0.05, 0.05], color_continuous_scale_='jet')

Plot loading plot

Parameters

height_int, default=900

Height of the figure.

width_int, default=2000

Width of the figure.

range_colorlist, default=[-0.05,0.05]

Range of color_ for the plot.

color_continuous_scale_str, default='jet'

color_ scale for the plot.

pca

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=None

Name of features.

n_componentsint, default=2

Number 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=42

Random state for permutation test.

test_sizefloat, default=0.3

Size 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)
fit(self)
get_explained_variance(self)
get_scores(self)
get_loadings(self)
get_q2_test(self)
plot_observe_variance(self)

Visualise explained variance plot

Returns

figplotly.graph_objects.Figure

Explained variance plot.

plot_cumulative_observed(self)
plot_pca_scores(self, pc=['PC1', 'PC2'], color_=None, color_dict=None, symbol_=None, symbol_dict=None, fig_height=900, fig_width=1300, marker_size=35, marker_opacity=0.7, text_=None)

Visualise PCA scores plot

Parameters

pclist, default=['PC1', 'PC2']

List of principal components to plot.

colorarray-like, shape (n_samples,), default=None

Target data, where n_samples is the number of samples.

color_dictdict, default=None

Dictionary of color_ mapping.

symbol_array-like, shape (n_samples,), default=None

Target data, where n_samples is the number of samples.

symbol_dictdict, default=None

Dictionary of symbol_ mapping.

fig_heightint, default=900

Height of figure.

fig_widthint, default=1300

Width of figure.

marker_sizeint, default=35

Size of marker.

marker_opacityfloat, default=0.7

Opacity of marker.

text_array-like, shape (n_samples,), default=None

Text to display on each point.

Returns

figplotly.graph_objects.Figure

PCA scores plot.

plot_loading_(self, pc=['PC1', 'PC2'], height_=600, width_=1800)

Visualise PCA loadings

Parameters

pclist, default=['PC1', 'PC2']

Principle component to plot.

height_int, default=600

Height of figure.

width_int, default=1800

Width of figure.

Returns

figplotly.graph_objects.Figure

Plotly figure.

----------

plot_pca_trajectory(self, time_, time_order, stat_=['mean', 'sem'], pc=['PC1', 'PC2'], color_dict=None, symbol_dict=None, height_=900, width_=1300, marker_size=35, marker_opacity=0.7)

Visualise PCA trajectory

Parameters

time_array-like, shape (n_samples,)

Time point of samples.

time_orderdictionary

Order of time point.

stat_list, default=['mean', 'sem']

Statistic to calculate. First element is mean or median, second element is sem or std.

pclist, default=['PC1', 'PC2']

Principle component to plot.

color_dictdictionary, default=None

Dictionary of color_ for each group.

symbol_dictdictionary, default=None

Dictionary of symbol_ for each time point.

height_int, default=900

Height of figure.

width_int, default=1300

Width of figure.

marker_sizeint, default=35

Size of marker.

marker_opacityfloat, default=0.7

Opacity of marker.

Returns

figplotly.graph_objects.Figure

Plotly figure.

Source

metbit/metbit.py at v1.7.3
Downloads for metbit 1.7.3PyPI and GitHub measure different distribution channels. Statistics refresh daily.

Counts are distribution activity, not unique users. GitHub source archives and Git clones are not included. Sources: PyPI Stats, Pepy, ClickPy, and GitHub Releases.

metbit 1.7.3 documentation