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

metbit.metbit

Analysis and models module in metbit 5.0.1.

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)
get_oplsda_scores(self)

Get OPLS-DA scores

get_s_scores(self)

Get S scores

get_oplsda_model(self)

Get OPLS-DA model

get_cv_model(self)

Get cross-validation model

permutation_test(self, n_permutations=500, cv=3, n_jobs=-1, verbose=10)
get_permutation_scores(self)

Get permutation scores

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, marker_size=12, fig_width=1000, fig_height=500, filter_=False, vip_transform=True, font_size=20, title_font_size=20, xaxis_direction='reversed')

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, x_='t_scores', y_='t_ortho', color_=None, color_dict=None, symbol_=None, symbol_dict=None, fig_height=900, fig_width=1300, marker_size=35, marker_opacity=0.7, font_size=20, title_font_size=21, legend_name=['Group', 'Time point'], individual_ellipse=True)

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, fig_height=500, fig_width=1000, font_size=14, title_font_size=20)

Plot histogram of permutation scores

Parameters

nbins_int, default=50

Number of bins for histogram.

fig_heightint, default=500

Height of the figure.

fig_widthint, default=1000

Width of the figure.

plot_s_scores(self, fig_height=900, fig_width=2000, range_color_=[-0.05, 0.05], color_continuous_scale_='jet', marker_size=14, font_size=20, title_font_size=20)

Plot S-plot

Parameters

fig_heightint, default=900

Height of the figure.

fig_widthint, 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, fig_height=900, fig_width=2000, range_color_=[-0.05, 0.05], color_continuous_scale_='jet', marker_size=5, font_size=20, title_font_size=20, xaxis_direction='reversed', xaxis_title='𝛿<sub>H</sub> in ppm')

Plot loading plot

Parameters

fig_heightint, default=900

Height of the figure.

fig_widthint, 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: pd.DataFrame, label: list=None, features_name: list=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, fig_height=600, fig_width=800, font_size=15)

Visualise explained variance plot

Returns

figplotly.graph_objects.Figure

Explained variance plot.

plot_cumulative_observed(self, fig_height=600, fig_width=800, font_size=15, marker_size=10)

Visualise cumulative variance plot

Returns

figplotly.graph_objects.Figure

Cumulative variance plot.

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, font_size=20, title_font_size=21, individual_ellipse=True, legend_name=['Group', 'Time point'])

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'], fig_height=600, fig_width=1800, font_size=20, title_font_size=20, marker_size=1, x_axis_title='𝛿<sub>H</sub> in ppm', xaxis_direction='reversed')

Visualise PCA loadings

Parameters

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

Principle component to plot.

fig_heightint, default=600

Height of figure.

fig_widthint, 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, fig_height=900, fig_width=1300, marker_size=35, marker_opacity=0.7, title_font_size=20, font_size=20, legend_name=['Group', 'Time point'])

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.

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.

Returns

figplotly.graph_objects.Figure

Plotly figure.

plot_3d_pca(self, pc=['PC1', 'PC2', 'PC3'], color_=None, color_dict=None, symbol_=None, symbol_dict=None, fig_height=900, fig_width=1300, marker_size=35, marker_opacity=0.7, font_size=20, title_font_size=20, legend_name=['Group', 'Time point'])

Source

metbit/metbit.py at v5.0.1
Downloads for metbit 5.0.1PyPI 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 5.0.1 documentation