### Install ppscore Source: https://pypi.org/project/ppscore Install the ppscore library using pip. Ensure you have Python 3.8 or above. ```bash pip install -U ppscore ``` -------------------------------- ### Create Sample Data with Pandas and NumPy Source: https://pypi.org/project/ppscore Generates a pandas DataFrame with synthetic data for demonstrating ppscore functionality. This includes creating 'x', 'error', and 'y' columns. ```python import pandas as pd import numpy as np import ppscore as pps df = pd.DataFrame() df["x"] = np.random.uniform(-2, 2, 1_000_000) df["error"] = np.random.uniform(-0.5, 0.5, 1_000_000) df["y"] = df["x"] * df["x"] + df["error"] ``` -------------------------------- ### Visualize PPS Matrix with Seaborn Heatmap Source: https://pypi.org/project/ppscore Generates a heatmap visualization of the PPS matrix using seaborn. The data needs to be pivoted into a matrix format before plotting. ```python import seaborn as sns matrix_df = pps.matrix(df)[['x', 'y', 'ppscore']].pivot(columns='x', index='y', values='ppscore') sns.heatmap(matrix_df, vmin=0, vmax=1, cmap="Blues", linewidths=0.5, annot=True) ``` -------------------------------- ### Calculate PPS for All Predictors Source: https://pypi.org/project/ppscore Calculates the PPS for all features in the DataFrame as predictors for a target feature ('y'). Returns a DataFrame of predictor scores. ```python pps.predictors(df, "y") ``` -------------------------------- ### Visualize PPS Predictors with Seaborn Source: https://pypi.org/project/ppscore Generates a bar plot of the PPS scores for predictors of 'y' using seaborn. Requires the 'predictors' function to be called first. ```python import seaborn as sns predictors_df = pps.predictors(df, y="y") sns.barplot(data=predictors_df, x="x", y="ppscore") ``` -------------------------------- ### Calculate PPS Matrix Source: https://pypi.org/project/ppscore Calculates the full Predictive Power Score (PPS) matrix for all columns in the DataFrame, showing the predictive power between every pair of features. ```python pps.matrix(df) ``` -------------------------------- ### ppscore.matrix Source: https://pypi.org/project/ppscore Calculates the Predictive Power Score (PPS) matrix for all pairwise column relationships within a DataFrame. Similar to `ppscore.predictors`, the output format and sorting can be controlled. ```APIDOC ## ppscore.matrix(df, output="df", sorted=False, **kwargs) ### Description Calculate the Predictive Power Score (PPS) matrix for all columns in the dataframe. ### Parameters #### Path Parameters * **df** (pandas.DataFrame) - The dataframe that contains the data #### Query Parameters * **output** (str) - potential values: "df", "list" - Control the type of the output. Either return a df or a list with all the PPS score dicts * **sorted** (bool) - Whether or not to sort the output dataframe/list by the ppscore * **kwargs** - Other key-word arguments that shall be forwarded to the pps.score method, e.g. **sample** , **cross_validation** , **random_seed** , **invalid_score** , **catch_errors** #### Returns * **pandas.DataFrame** or list of PPS dicts - Either returns a df or a list of all the PPS dicts. This can be influenced by the output argument ``` -------------------------------- ### ppscore.predictors Source: https://pypi.org/project/ppscore Calculates the Predictive Power Score (PPS) for all columns in a DataFrame against a specified target column (y). The output can be a DataFrame or a list of PPS score dictionaries, and can be sorted by score. ```APIDOC ## ppscore.predictors(df, y, output="df", sorted=True, **kwargs) ### Description Calculate the Predictive Power Score (PPS) for all columns in the dataframe against a target (y) column. ### Parameters #### Path Parameters * **df** (pandas.DataFrame) - The dataframe that contains the data * **y** (str) - Name of the column y which acts as the target #### Query Parameters * **output** (str) - potential values: "df", "list" - Control the type of the output. Either return a df or a list with all the PPS score dicts * **sorted** (bool) - Whether or not to sort the output dataframe/list by the ppscore * **kwargs** - Other key-word arguments that shall be forwarded to the pps.score method, e.g. **sample** , **cross_validation** , **random_seed** , **invalid_score** , **catch_errors** #### Returns * **pandas.DataFrame** or list of PPS dicts - Either returns a df or a list of all the PPS dicts. This can be influenced by the output argument ``` -------------------------------- ### Calculate PPS for a Single Predictor Source: https://pypi.org/project/ppscore Calculates the Predictive Power Score (PPS) of one feature ('x') predicting another ('y') within a pandas DataFrame. ```python pps.score(df, "x", "y") ``` -------------------------------- ### ppscore.score Source: https://pypi.org/project/ppscore Calculates the Predictive Power Score (PPS) for a single feature (x) predicting a target (y) within a pandas DataFrame. The PPS ranges from 0 (no predictive power) to 1 (perfect prediction) and is data-type agnostic. ```APIDOC ## ppscore.score(df, x, y, sample=5_000, cross_validation=4, random_seed=123, invalid_score=0, catch_errors=True) ### Description Calculate the Predictive Power Score (PPS) for "x predicts y". The score always ranges from 0 to 1 and is data-type agnostic. A score of 0 means that the column x cannot predict the column y better than a naive baseline model. A score of 1 means that the column x can perfectly predict the column y given the model. A score between 0 and 1 states the ratio of how much potential predictive power the model achieved compared to the baseline model. ### Parameters #### Path Parameters * **df** (pandas.DataFrame) - Dataframe that contains the columns x and y * **x** (str) - Name of the column x which acts as the feature * **y** (str) - Name of the column y which acts as the target #### Query Parameters * **sample** (int or `None`) - Number of rows for sampling. The sampling decreases the calculation time of the PPS. If `None` there will be no sampling. * **cross_validation** (int) - Number of iterations during cross-validation. This has the following implications: For example, if the number is 4, then it is possible to detect patterns when there are at least 4 times the same observation. If the limit is increased, the required minimum observations also increase. This is important, because this is the limit when sklearn will throw an error and the PPS cannot be calculated * **random_seed** (int or `None`) - Random seed for the parts of the calculation that require random numbers, e.g. shuffling or sampling. If the value is set, the results will be reproducible. If the value is `None` a new random number is drawn at the start of each calculation. * **invalid_score** (any) - The score that is returned when a calculation is not valid, e.g. because the data type was not supported. * **catch_errors** (bool) - If `True` all errors will be catched and reported as `unknown_error` which ensures convenience. If `False` errors will be raised. This is helpful for inspecting and debugging errors. #### Returns * **Dict** - A dict that contains multiple fields about the resulting PPS. The dict enables introspection into the calculations that have been performed under the hood ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.