Pandas Dataframe Algorithms
Pandas Dataframes
Pandas dataframes are obviously not going to scale as well as our Spark and SQL Algorithms, but for 'moderate' sized data these algorithms provide some nice functionality.
Pandas Dataframe Algorithms
Workbench has a growing set of algorithms and data processing tools for Pandas Dataframes. In general these algorithm will take a dataframe as input and give you back a dataframe with additional columns.
FeatureSpaceProximity
Bases: Proximity
Source code in src/workbench/algorithms/dataframe/feature_space_proximity.py
__init__(model, n_neighbors=10)
Initialize the FeatureSpaceProximity class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
A Workbench model object. |
required |
n_neighbors
|
int
|
Number of neighbors to compute. Defaults to 10. |
10
|
Source code in src/workbench/algorithms/dataframe/feature_space_proximity.py
FingerprintProximity
Bases: Proximity
Source code in src/workbench/algorithms/dataframe/fingerprint_proximity.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
__init__(df, id_column, fingerprint_column, n_neighbors=5)
Initialize the FingerprintProximity class for binary fingerprint similarity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame containing fingerprints. |
required |
id_column
|
Union[int, str]
|
Name of the column used as an identifier. |
required |
fingerprint_column
|
str
|
Name of the column containing fingerprints. |
required |
n_neighbors
|
int
|
Default number of neighbors to compute. |
5
|
Source code in src/workbench/algorithms/dataframe/fingerprint_proximity.py
all_neighbors(min_similarity=None, include_self=False, add_columns=None)
Find neighbors for all fingerprints in the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_similarity
|
float
|
Minimum similarity threshold (0-1) |
None
|
include_self
|
bool
|
Whether to include self in results |
False
|
add_columns
|
List[str]
|
Additional columns to include in results |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing neighbors and similarities |
Source code in src/workbench/algorithms/dataframe/fingerprint_proximity.py
build_proximity_model()
Prepare the fingerprint data for nearest neighbor calculations. Converts fingerprint strings to binary arrays and initializes NearestNeighbors.
Source code in src/workbench/algorithms/dataframe/fingerprint_proximity.py
neighbors(query_df, min_similarity=None, include_self=False, add_columns=None)
Find neighbors for each row in the query DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_df
|
DataFrame
|
DataFrame containing query fingerprints |
required |
min_similarity
|
float
|
Minimum similarity threshold (0-1) |
None
|
include_self
|
bool
|
Whether to include self in results (if present) |
False
|
add_columns
|
List[str]
|
Additional columns to include in results |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing neighbors and similarities |
Note: The query DataFrame must include the feature columns. The id_column is optional.
Source code in src/workbench/algorithms/dataframe/fingerprint_proximity.py
prep_features_for_query(query_df)
Prepare the query DataFrame by converting fingerprints to binary arrays.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_df
|
DataFrame
|
DataFrame containing query fingerprints. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Binary feature matrix for the query fingerprints. |
Source code in src/workbench/algorithms/dataframe/fingerprint_proximity.py
Projection2D
Perform Dimensionality Reduction on a DataFrame using TSNE, MDS, PCA, or UMAP.
Source code in src/workbench/algorithms/dataframe/projection_2d.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
__init__()
fit_transform(input_df, features=None, projection='UMAP')
Fit and transform a DataFrame using the selected dimensionality reduction method.
This method creates a copy of the input DataFrame, processes the specified features for normalization and projection, and returns a new DataFrame with added 'x' and 'y' columns containing the projected 2D coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_df
|
DataFrame
|
The DataFrame containing features to project. |
required |
features
|
list
|
List of feature column names. If None, numeric columns are auto-selected. |
None
|
projection
|
str
|
The projection to use ('UMAP', 'TSNE', 'MDS' or 'PCA'). Default 'UMAP'. |
'UMAP'
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame (a copy of input_df) with added 'x' and 'y' columns. |
Source code in src/workbench/algorithms/dataframe/projection_2d.py
resolve_coincident_points(df)
staticmethod
Resolve coincident points in a DataFrame by adding jitter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The DataFrame containing x and y projection coordinates. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The DataFrame with resolved coincident points. |
Source code in src/workbench/algorithms/dataframe/projection_2d.py
Questions?
The SuperCowPowers team is happy to answer any questions you may have about AWS and Workbench. Please contact us at workbench@supercowpowers.com or on chat us up on Discord