Principal Component Analysis on Histogram-Binned Distributional Data
Project description
🚀 Quick Start
import pandas as pd
from histopca import prep_histogram, ridit_score_centered, histogram_pca_r_compatible
# Load your data
data = pd.read_csv("your_data.csv")
# Create histograms from your variables
Hist1 = prep_histogram(X=data['price'].values, Z=data['category'].values, k=5)['Vhistogram']
Hist2 = prep_histogram(X=data['size'].values, Z=data['category'].values, k=5)['Vhistogram']
Hist3 = prep_histogram(X=data['rating'].values, Z=data['category'].values, k=5)['Vhistogram']
# Calculate ridit scores
score1 = ridit_score_centered(Hist1)
score2 = ridit_score_centered(Hist2)
score3 = ridit_score_centered(Hist3)
# Run PCA with automatic visualization
results = histogram_pca_r_compatible(
variables=[Hist1, Hist2, Hist3],
scores=[score1, score2, score3],
col_names=['Price', 'Size', 'Rating'],
row_names=list(Hist1.index),
plotgraph=True
)
# View results
print(results['PourCentageComposante']) # Variance explained
print(results['Correlation']) # Variable loadings
📖 For detailed examples, see EXAMPLE_USAGE.md
📊 Examples
Real Estate Analysis
Analyze property distributions by type:
from histopca import prep_histogram, ridit_score_centered, histogram_pca_r_compatible
# Create histograms for 5 variables
Hist_Price = prep_histogram(X=data['Price'].values, Z=data['Property Type'].values, k=5)['Vhistogram']
Hist_Size = prep_histogram(X=data['Square Footage'].values, Z=data['Property Type'].values, k=5)['Vhistogram']
Hist_Beds = prep_histogram(X=data['Bedrooms'].values, Z=data['Property Type'].values, k=5)['Vhistogram']
Hist_Baths = prep_histogram(X=data['Bathrooms'].values, Z=data['Property Type'].values, k=5)['Vhistogram']
Hist_Acre = prep_histogram(X=data['Acreage'].values, Z=data['Property Type'].values, k=5)['Vhistogram']
# Calculate scores and run PCA
scores = [ridit_score_centered(h) for h in [Hist_Price, Hist_Size, Hist_Beds, Hist_Baths, Hist_Acre]]
results = histogram_pca_r_compatible(
variables=[Hist_Price, Hist_Size, Hist_Beds, Hist_Baths, Hist_Acre],
scores=scores,
col_names=['Price', 'Size', 'Bedrooms', 'Bathrooms', 'Acreage'],
row_names=list(Hist_Price.index),
plotgraph=True
)
See EXAMPLE_USAGE.md for more examples:
- Customer purchase analysis
- Product performance by category
- Time series by region
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
histopca-0.1.2.tar.gz
(21.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
histopca-0.1.2-py3-none-any.whl
(15.6 kB
view details)
File details
Details for the file histopca-0.1.2.tar.gz.
File metadata
- Download URL: histopca-0.1.2.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3433b30073d925f98931041d9481496774bbfb3d8cc36ef1e176edddfda7abe1
|
|
| MD5 |
31e9c55e5a454c0dd6f8f85ef2f86d21
|
|
| BLAKE2b-256 |
284269b79ef92ecf1452d8c2f86f1aaf0e114a694bd02b598a20019330a93a33
|
File details
Details for the file histopca-0.1.2-py3-none-any.whl.
File metadata
- Download URL: histopca-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1a5f69827d870fa32fffab682811adb63e34cbe9b543a83e2c94dae6b7e12e9
|
|
| MD5 |
6e672d0ad9660ec6d3024e144359684b
|
|
| BLAKE2b-256 |
1450a331c138da8e45e6851343dda7330881b85f2bf542d62921d74a7ea0df40
|