ogboost 0.5.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ogboost/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ # ogboost/__init__.py
2
+
3
+ # Re-export key components from submodules
4
+ from .data import load_wine_quality
5
+ from .main import GradientBoostingOrdinal, concordance_index, LinkFunctions
6
+
7
+ # Define the public API
8
+ __all__ = ["load_wine_quality", "GradientBoostingOrdinal", "concordance_index", "LinkFunctions"]
ogboost/data.py ADDED
@@ -0,0 +1,103 @@
1
+ """
2
+ Module for loading the Wine Quality Dataset.
3
+
4
+ This module provides functionality to download and load the Wine Quality Dataset from the
5
+ UCI Machine Learning Repository. The dataset includes information about physicochemical
6
+ tests (e.g., pH, alcohol content) and quality scores for red and white wines.
7
+
8
+ The module contains the following functionality:
9
+ - Automatically downloads the datasets if not found locally.
10
+ - Loads the red and white wine datasets into pandas DataFrames.
11
+ - Rescales the 'quality' column to start from 0 and ensures it is of integer type.
12
+
13
+ Functions
14
+ ---------
15
+ load_wine_quality():
16
+ Loads the wine quality dataset. Automatically downloads the datasets
17
+ if they are not found locally and returns them as pandas DataFrames.
18
+
19
+ _download_wine_quality_datasets(destination: str):
20
+ Downloads the wine quality datasets (red and white) from the UCI repository
21
+ to the specified destination folder.
22
+
23
+ Examples
24
+ --------
25
+ >>> from mymodule import load_wine_quality
26
+ >>> red_wine, white_wine = load_wine_quality()
27
+ >>> print(red_wine.head())
28
+ >>> print(white_wine.head())
29
+ """
30
+ import os
31
+ import urllib.request
32
+ import pandas as pd
33
+
34
+ def load_wine_quality():
35
+ """
36
+ Loads the wine quality dataset from the UCI repository.
37
+ If the datasets are not already downloaded,
38
+ they will be downloaded automatically.
39
+
40
+ Returns
41
+ -------
42
+ tuple of pandas.DataFrame
43
+ A tuple containing two DataFrames:
44
+ - The first for red wine data.
45
+ - The second for white wine data.
46
+ """
47
+ # Define the local paths for the datasets
48
+ dataset_folder = os.path.join(os.path.dirname(__file__), "data")
49
+ red_wine_path = os.path.join(dataset_folder, "winequality-red.csv")
50
+ white_wine_path = os.path.join(dataset_folder, "winequality-white.csv")
51
+
52
+ # Check if the datasets exist locally; if not, download them
53
+ if not os.path.exists(red_wine_path) or not os.path.exists(white_wine_path):
54
+ print("Datasets not found locally. Downloading from UCI repository...")
55
+ os.makedirs(dataset_folder, exist_ok=True)
56
+ _download_wine_quality_datasets(dataset_folder)
57
+
58
+ # Load the datasets into pandas DataFrames
59
+ red_wine_df = pd.read_csv(red_wine_path, sep=";")
60
+ white_wine_df = pd.read_csv(white_wine_path, sep=";")
61
+
62
+ # rescale quality to start from 0
63
+ red_wine_df["quality"] -= red_wine_df["quality"].min()
64
+ white_wine_df["quality"] -= white_wine_df["quality"].min()
65
+
66
+ # ensure data type for response is integer
67
+ red_wine_df["quality"] = red_wine_df["quality"].astype(int)
68
+ white_wine_df["quality"] = white_wine_df["quality"].astype(int)
69
+
70
+ return red_wine_df, white_wine_df
71
+
72
+
73
+ def _download_wine_quality_datasets(destination: str):
74
+ """
75
+ Downloads the wine quality datasets from the UCI repository.
76
+
77
+ Parameters
78
+ ----------
79
+ destination : str
80
+ Directory where the datasets will be saved.
81
+ """
82
+ # UCI repository URLs
83
+ red_wine_url = (
84
+ "https://archive.ics.uci.edu/ml/machine-learning-databases/"
85
+ "wine-quality/winequality-red.csv"
86
+ )
87
+ white_wine_url = (
88
+ "https://archive.ics.uci.edu/ml/machine-learning-databases/"
89
+ "wine-quality/winequality-white.csv"
90
+ )
91
+
92
+ # Define file paths
93
+ red_wine_path = os.path.join(destination, "winequality-red.csv")
94
+ white_wine_path = os.path.join(destination, "winequality-white.csv")
95
+
96
+ # Download the datasets
97
+ print(f"Downloading red wine dataset to {red_wine_path}...")
98
+ urllib.request.urlretrieve(red_wine_url, red_wine_path)
99
+ print("Red wine dataset downloaded.")
100
+
101
+ print(f"Downloading white wine dataset to {white_wine_path}...")
102
+ urllib.request.urlretrieve(white_wine_url, white_wine_path)
103
+ print("White wine dataset downloaded.")