Getting Started

Quick tutorial: Using the stat386_final package

This short tutorial shows common workflows: reading the bundled data, processing it, training the Random Forest model, and plotting basic distributions.

Install

Install the package in editable mode (for development) or normally:

pip install -e .
# or
pip install .

Quickstart (Python)

Copy the following into a Python session or script.

from importlib.resources import files
from stat386_final import (
    read_data,
    process_data,
    prepare_data,
    rf_fit,
    print_genre_distribution,
    print_platform_distribution,
    __version__,
)

print('stat386_final version:', __version__)

# Load the bundled example dataset
sales = read_data("game_data.csv")
print(sales.shape)
print(list(sales.columns)[:10])

# Process and prepare for modeling
sales_combined = process_data(sales)
final_df = prepare_data(sales_combined)
print('Prepared dataset shape:', final_df.shape)

# Fit a Random Forest model to predict global sales
# (This will run a small grid search and print metrics)
# `rf_fit` returns a tuple `(best_model, scaler)` — keep the scaler
# to use when scaling new data for `predict()`.
best_model, scaler = rf_fit(final_df, 'Global_Sales')

# Quick plots (shows matplotlib windows in notebooks or interactive sessions)
print_genre_distribution(sales, 'Action', 'Global_Sales')
print_platform_distribution(sales, 'PS4', 'Global_Sales')

# Example: making predictions on new data (use the returned `scaler`)
# preds = predict(best_model, area='Global_Sales', new_data=new_X, scaler=scaler)

# Predict
new_data = final_df.drop(columns=["Global_Sales"]).iloc[:5]
preds = predict(best_model, area="Global_Sales", new_data=new_data, scaler=scaler)
print(preds)