semvec/pypi-packages huggingface dataset:
fairness-ranking 0.1.1
A package for generating synthetic data, reranking students, and calculating fairness metrics.
Requires Python: >=3.6

# Fairness Ranking

This package provides functions for generating synthetic data, reranking students based on tolerance, and calculating fairness metrics.

## Installation

To install the package from PyPI, run:

```bash
pip install fairness_ranking



Usage
Here is an example of how to use the package:



import fairness_ranking.ranking as fr

# Define the number of candidates and tolerance
num_candidates = 10
tolerance = 252

# Generate synthetic data
synthetic_data = fr.generate_synthetic_data(num_candidates, 'A vs B')

# Rerank the synthetic data
reranked_data = fr.rerank_students(synthetic_data, tolerance)

# Calculate rewards and totals
data_with_rewards, total_w, total_b = fr.add_rewards_and_calculate_totals(reranked_data, 'linear')

# Calculate fairness metric
initial_rewards = {'w': total_w, 'b': total_b}
post_reranking_rewards = {'w': total_w, 'b': total_b}
fairness_metric = fr.calculate_fairness_metric(initial_rewards, post_reranking_rewards)

print(f"Fairness Metric: {fairness_metric}")



Functions
generate_synthetic_data(num_candidates, gap_scenario, seed=42)
Generates synthetic data with varying gaps between candidate scores.

num_candidates: Number of candidates.
gap_scenario: The scenario defining the score gaps ('A vs B', 'A vs C', 'A vs D', 'MIX').
seed: Seed for random number generation (default is 42).
rerank_students(students, tolerance)
Reranks students based on a given tolerance.

students: List of student dictionaries with scores and groups.
tolerance: Tolerance value for reranking.
calculate_logarithmic_rewards(n)
Calculates logarithmic rewards.

n: Number of candidates.
add_rewards_and_calculate_totals(data, reward_type='linear')
Adds rewards to the data and calculates total rewards for each group.

data: List of candidate dictionaries with scores and groups.
reward_type: Type of rewards ('linear' or 'logarithmic').
calculate_fairness_metric(initial_rewards, post_reranking_rewards)
Calculates the fairness metric based on initial and post-reranking rewards.

initial_rewards: Dictionary with initial total rewards for each group.
post_reranking_rewards: Dictionary with post-reranking total rewards for each group.
dlt-source-morphais 0.0.5
A DLT source for Morphais
Requires Python: >=3.12

---
description: dlt source for morphais.com
keywords: [Morphais API, morphais.com]
---

# dlt-source-morphais

[![PyPI version](https://img.shields.io/pypi/v/dlt-source-morphais)](https://pypi.org/project/dlt-source-morphais/)

[DLT](https://dlthub.com/) source for [Morphais](https://www.morphais.com/).

Currently loads the following data:

| Table | Contains |
| -- | -- |
| `persons` | Items of the `Person` model with all properties |
| `persons_*` | Multi-value properties derived of the `Person` model |
| `highlights` | Unique [highlights](https://morphais.readme.io/reference/filter-functions#highlights) |
| `audiences` | Unique audiences (B2B, B2C, etc.)  |
| `legal_forms` | Unique legal forms (GmbH, Ltd., etc.) |
| `funding_stages` | Unique funding stages (Pre-Seed, Seed, etc.)  |
| `industries` | Unique [industries](https://morphais.readme.io/reference/filter-functions#industries) |
| `solutions` | Unique [solutions](https://morphais.readme.io/reference/filter-functions#solutions) |
| `startups` | Items of the `Startup` model with all properties |
| `startups_*` | Multi-value properties derived of the `Startup` model |

## Usage

Create a `.dlt/secrets.toml` with your API key and email:

```toml
morphais_email="<YOUR-EMAIL>"
morphais_api_key="<YOUR_API_KEY>"
```

and then run the default source with optional list references:

```py
from dlt_source_morphais import source as morphais_source

pipeline = dlt.pipeline(
   pipeline_name="morphais_pipeline",
   destination="duckdb",
   dev_mode=True,
)
morphais_data = morphais_source()
pipeline.run(morphais_data)
```

## Development

This project is using [devenv](https://devenv.sh/).

Commands:

| Command | What does it do? |
| -- | -- |
| `generate-model` | generates the morphais Pydantic model from the current spec file, applies patches, etc. |
| `update-spec` | Pulls in the latest `main#HEAD` of [planet-a-ventures/morphais-openapi-spec](https://github.com/planet-a-ventures/morphais-openapi-spec) |
| `refresh-model` | Both commands above plus adds it to git and commits the changes. |
| `format` | Formats & lints all code |
| `sample-pipeline-run` | Runs the sample pipeline. By default `dev_mode=True` which fetches resources with a limit of 1 (page) |
| `sample-pipeline-show` | Starts the streamlit-based dlt hub |

### Run the sample

```sh
MORPHAIS_EMAIL=[...] \
   MORPHAIS_API_KEY=[...] \
   sample-pipeline-run
```

alternatively you can also create a `.dlt/secrets.toml`
(excluded from git) with the following content:

```toml
morphais_api_key="..."
morphais_email="you@domain.com"
```