### Install and Import ucimlrepo Package Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/README.md Installs the ucimlrepo package using pip and imports the necessary functions for fetching and listing datasets. It's recommended to restart the kernel after installation. ```python !pip3 install -U ucimlrepo # Restart the kernel and import the module from ucimlrepo import fetch_ucirepo, list_available_datasets ``` -------------------------------- ### List Available Datasets with ucimlrepo Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Demonstrates how to list all available datasets from the UCI Machine Learning Repository using the `list_available_datasets` function. It also shows examples of filtering the list by project name and searching for datasets containing specific keywords. ```python list_available_datasets() list_available_datasets(filter='aim-ahead') # only list datasets for AIM-AHEAD project list_available_datasets(search='diabe') ``` -------------------------------- ### Fetch and Access Glioma Dataset Features in Python Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Fetches the Glioma dataset from the UCI ML Repository and then displays its features. This demonstrates how to load a new dataset and access its features for analysis. It requires the 'ucirepo' library to be installed. ```python glioma = fetch_ucirepo(name='glioma') glioma.data.features ``` -------------------------------- ### Install ucimlrepo Package Source: https://context7.com/uci-ml-repo/ucimlrepo/llms.txt Installs or upgrades the ucimlrepo Python package using pip. This is the first step to using the library's functionalities. ```bash pip install -U ucimlrepo ``` -------------------------------- ### Fetch Dataset and Data with ucimlrepo (Python) Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Fetches the Iris dataset (ID 189) from the UCI ML Repository using the ucimlrepo library. It retrieves the features (X) and targets (y) as pandas DataFrames and prints the dataset's metadata. This requires the 'ucimlrepo' library to be installed. ```python from ucimlrepo import fetch_ucirepo # fetch dataset iris = fetch_ucirepo(id=189) # data (as pandas dataframes) X = iris.data.features y = iris.data.targets # metadata print(iris.metadata) ``` -------------------------------- ### List Available Datasets Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/README.md Shows how to list all available datasets from the UCI Machine Learning Repository that can be imported using `fetch_ucirepo`. It also demonstrates filtering and searching capabilities. ```python # check which datasets can be imported list_available_datasets() # Example with filter (if applicable, e.g., 'aim-ahead') # list_available_datasets(filter='aim-ahead') # Example with search query # list_available_datasets(search='diabetes') ``` -------------------------------- ### Fetch and Access UCI Dataset Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/README.md Demonstrates how to fetch a dataset from the UCI Machine Learning Repository using its ID or name. It shows how to access the dataset's features (X), targets (y), metadata, and variable information. ```python # import dataset heart_disease = fetch_ucirepo(id=45) # alternatively: fetch_ucirepo(name='Heart Disease') # access data X = heart_disease.data.features y = heart_disease.data.targets # train model e.g. sklearn.linear_model.LinearRegression().fit(X, y) # access metadata print(heart_disease.metadata.uci_id) print(heart_disease.metadata.num_instances) print(heart_disease.metadata.additional_info.summary) # access variable info in tabular format print(heart_disease.variables) ``` -------------------------------- ### Handle Common Errors When Fetching UCI Datasets (Python) Source: https://context7.com/uci-ml-repo/ucimlrepo/llms.txt Illustrates how to use try-except blocks to gracefully handle potential errors during dataset fetching, such as a dataset not being found, invalid input parameters, network connection issues, or datasets not being available for Python import. ```python from ucimlrepo import fetch_ucirepo from ucimlrepo.fetch import DatasetNotFoundError # Handle dataset not found try: dataset = fetch_ucirepo(name='nonexistent_dataset') except DatasetNotFoundError as e: print(f"Dataset error: {e}") # Handle invalid input - cannot specify both id and name try: dataset = fetch_ucirepo(id=45, name='Heart Disease') except ValueError as e: print(f"Input error: {e}") # Output: Only specify either dataset name or ID, not both # Handle connection errors try: dataset = fetch_ucirepo(id=45) except ConnectionError as e: print(f"Network error: {e}") # Handle datasets not available for import try: dataset = fetch_ucirepo(name='some_dataset') except DatasetNotFoundError as e: # Some datasets exist but don't have standardized CSV files print(f"Dataset exists but cannot be imported: {e}") ``` -------------------------------- ### List Available Datasets from UCI ML Repository Source: https://context7.com/uci-ml-repo/ucimlrepo/llms.txt Displays a formatted table of datasets available for import via `fetch_ucirepo`. Supports filtering by category, searching by name, and filtering by subject area to help discover dataset IDs. ```python from ucimlrepo import list_available_datasets # List all available datasets list_available_datasets() # Output: # ------------------------------------- # The following datasets are available: # ------------------------------------- # Dataset Name ID # ------------ -- # Abalone 1 # Adult 2 # Heart Disease 45 # Iris 53 # Wine 109 # ... # Filter by category (e.g., AIM-AHEAD health datasets) list_available_datasets(filter='aim-ahead') # Output: # ----------------------------------------------- # The following aim-ahead datasets are available: # ----------------------------------------------- # Dataset Name ID Prediction Task # ------------ -- --------------- # Sepsis Survival Minimal Clinical Records 827 Predict survival status for sepsis patients # Heart Disease 45 Predict presence/absence of heart disease # ... # Search datasets by name list_available_datasets(search='diabetes') # Output: # -------------------------------------------------------------- # The following datasets are available for search query "diabetes": # -------------------------------------------------------------- # Dataset Name ID # ------------ -- # Diabetes 130-US hospitals for years 1999-2008 296 # Diabetic Retinopathy Debrecen 329 # Filter by subject area list_available_datasets(area='Life Science') ``` -------------------------------- ### Fetch UCI Dataset with Error Handling (Python) Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb This Python snippet demonstrates fetching a dataset from the UCI ML Repository using the `fetch_ucirepo` function. It includes a try-except block to catch and print exceptions that occur if the dataset is not found or if invalid input parameters are provided. This is useful for validating dataset availability and handling potential errors gracefully. ```python try: fetch_ucirepo(name='defungi') # # test invalid inputs # fetch_ucirepo(name='heart diseaseeeee') # fetch_ucirepo(id=10000) except Exception as e: print(e) ``` -------------------------------- ### Access Specific Metadata Fields (Python) Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Demonstrates accessing specific fields within the dataset's metadata after it has been fetched. This includes retrieving the target column name, the title of the introductory paper, and a summary of additional dataset information. These operations assume the dataset object and its metadata are already loaded. ```python sepsis.metadata.target_col ``` ```python sepsis.metadata.intro_paper.title ``` ```python sepsis.metadata.additional_info.summary ``` -------------------------------- ### Fetch and Inspect UCI Dataset Object Structure (Python) Source: https://context7.com/uci-ml-repo/ucimlrepo/llms.txt Demonstrates how to fetch a dataset using its ID and access its components (features, targets, metadata) through a structured object. The data is provided as pandas DataFrames, and metadata includes details about the dataset's origin, characteristics, and citation information. ```python from ucimlrepo import fetch_ucirepo # Fetch a dataset with multiple variable roles parkinsons = fetch_ucirepo(id=189) # Data structure print(parkinsons.data.features) # DataFrame of feature columns print(parkinsons.data.targets) # DataFrame of target columns print(parkinsons.data.ids) # DataFrame of ID columns (or None if no IDs) print(parkinsons.data.original) # Complete DataFrame with all columns print(parkinsons.data.headers) # Index of all column names # Metadata structure print(parkinsons.metadata.uci_id) # 189 print(parkinsons.metadata.name) # 'Parkinsons Telemonitoring' print(parkinsons.metadata.abstract) # Short description print(parkinsons.metadata.area) # 'Life Science' print(parkinsons.metadata.tasks) # ['Regression'] print(parkinsons.metadata.characteristics) # ['Multivariate'] print(parkinsons.metadata.num_instances) # 5875 print(parkinsons.metadata.num_features) # 26 print(parkinsons.metadata.target_col) # ['motor_UPDRS', 'total_UPDRS'] print(parkinsons.metadata.has_missing_values) # 'no' print(parkinsons.metadata.year_of_dataset_creation) # 2009 print(parkinsons.metadata.dataset_doi) # '10.24432/C5ZS3N' print(parkinsons.metadata.repository_url) # UCI dataset page URL print(parkinsons.metadata.creators) # List of creator names # Nested metadata access print(parkinsons.metadata.intro_paper.title) # Published paper title print(parkinsons.metadata.intro_paper.authors) # Paper authors print(parkinsons.metadata.intro_paper.year) # Publication year print(parkinsons.metadata.additional_info.summary) # Detailed description print(parkinsons.metadata.additional_info.citation) # Citation text # Variables DataFrame for inspection print(parkinsons.variables[['name', 'role', 'type', 'description']]) ``` -------------------------------- ### Import ucimlrepo Package Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Imports necessary functions from the `ucimlrepo` library for fetching and listing datasets. It also includes standard Python magic commands for code reloading. ```python %load_ext autoreload %autoreload 2 from ucimlrepo import fetch_ucirepo, list_available_datasets import pprint ``` -------------------------------- ### Fetch Dataset by ID and Print Metadata (Python) Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Fetches the Sepsis Survival Minimal Clinical Records dataset using its UCI ID (827) and prints its metadata. This requires the `ucimlrepo` library. The output includes details about the dataset's origin, structure, and associated research. ```python from ucimlrepo import fetch_ucirepo import pprint sepsis = fetch_ucirepo(id=827) pprint.pprint(sepsis.metadata) ``` -------------------------------- ### Display Iris Dataset Variables (Python) Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb This snippet demonstrates how to print the variable information for the Iris dataset. It assumes the 'iris' object is already loaded and accessible. No external libraries are explicitly required for this specific print statement, but it's typically used in conjunction with data loading libraries like scikit-learn or pandas. ```python print(iris.variables) ``` -------------------------------- ### Fetch UC Irvine Datasets by ID or Name Source: https://context7.com/uci-ml-repo/ucimlrepo/llms.txt Fetches a dataset from the UCI ML Repository using its ID or name. Returns a structured object with DataFrames for features, targets, IDs, and metadata. Supports accessing various data components and metadata via dot notation. ```python from ucimlrepo import fetch_ucirepo # Fetch dataset by ID heart_disease = fetch_ucirepo(id=45) # Or fetch by name (partial match supported) heart_disease = fetch_ucirepo(name='Heart Disease') # Access feature and target DataFrames X = heart_disease.data.features y = heart_disease.data.targets # Access the original combined DataFrame df = heart_disease.data.original # Get column headers headers = heart_disease.data.headers # Output: Index(['age', 'sex', 'cp', 'trestbps', ...], dtype='object') # Access metadata with dot notation print(heart_disease.metadata.uci_id) # 45 print(heart_disease.metadata.name) # 'Heart Disease' print(heart_disease.metadata.num_instances) # 303 print(heart_disease.metadata.num_features) # 13 print(heart_disease.metadata.area) # 'Life Science' print(heart_disease.metadata.tasks) # ['Classification'] # Access nested metadata print(heart_disease.metadata.additional_info.summary) print(heart_disease.metadata.intro_paper.title) # View variable information as a DataFrame print(heart_disease.variables) # name role type demographic description units missing_values # 0 age Feature Integer Age None None no # 1 sex Feature Categorical Sex None None no # 2 cp Feature Categorical None None None no # ... # Train a model from sklearn.linear_model import LogisticRegression model = LogisticRegression(max_iter=1000) model.fit(X, y.values.ravel()) ``` -------------------------------- ### Access Sepsis Dataset Headers in Python Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Retrieves and displays the column headers (feature names) for the Sepsis dataset. This is helpful for understanding the available features and for data manipulation. It assumes the 'sepsis' object has already been loaded. ```python sepsis.data.headers ``` -------------------------------- ### Access Sepsis Dataset Targets in Python Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Retrieves and displays the targets dataframe for the Sepsis dataset. This is crucial for training and evaluating supervised learning models. It assumes the 'sepsis' object has already been loaded. ```python sepsis.data.targets ``` -------------------------------- ### Access Sepsis Dataset Original Combined Data in Python Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Retrieves and displays the 'original' dataframe for the Sepsis dataset, which combines features, targets, and potentially other information. This provides a holistic view of the dataset. It assumes the 'sepsis' object has already been loaded. ```python sepsis.data.original ``` -------------------------------- ### Access Sepsis Dataset Variables Information in Python Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Retrieves and displays detailed information about each variable in the Sepsis dataset, including its name, role, type, and description. This is essential for data preprocessing and feature engineering. It assumes the 'sepsis' object has already been loaded. ```python sepsis.variables ``` -------------------------------- ### Access Sepsis Dataset Features in Python Source: https://github.com/uci-ml-repo/ucimlrepo/blob/main/src/demo.ipynb Retrieves and displays the features dataframe for the Sepsis dataset. This is useful for understanding the input variables for machine learning models. It assumes the 'sepsis' object has already been loaded. ```python sepsis.data.features ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.