vbdp
affinity_propagation_features(X)
¶
Clusters the features of a dataframe using Affinity Propagation.
This function takes a dataframe with features and clusters them using the Affinity Propagation algorithm. The resulting dataframe contains the original features as well as a new feature representing the cluster labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
DataFrame
|
A dataframe with features. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with the original features and a new cluster feature. |
Examples:
>>> df = pd.DataFrame({"a": [True, False, True], "b": [True, True, False], "c": [False, False, True]})
>>> df
a b c
0 True True False
1 False True False
2 True False True
>>> affinity_propagation_features(df)
Estimated number of clusters: 3
a b c cluster
0 True True False 0
1 False True False 1
2 True False True 2
Source code in spotpython/data/vbdp.py
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 |
|
cluster_features(X)
¶
Clusters the features of a dataframe based on similarity.
This function takes a dataframe with features and clusters them based on similarity. The resulting dataframe contains the original features as well as new features representing the clusters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
DataFrame
|
A dataframe with features. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with the original features and new cluster features. |
Examples:
>>> df = pd.DataFrame({"a": [True, False, True], "b": [True, True, False], "c": [False, False, True]})
>>> df
a b c
0 True True False
1 False True False
2 True False True
>>> cluster_features(df)
a b c c_0 c_1 c_2 c_3
0 True True False 0 0 0 0
1 False True False 0 0 0 0
2 True False True 0 0 0 0
Source code in spotpython/data/vbdp.py
9 10 11 12 13 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 |
|