liveBook · Manning

Shipping cost

As explained in Starting Data Analytics with Generative AI and Python

A shipping cost is the monetary charge for transporting a product or package from a sender to a destination.

Shipping cost is the charge for transporting a product to its destination. In order data, `freight_value` represents that charge. A practical question is whether heavier or larger products tend to cost more to ship—and how much of the variation those attributes explain. section 3.4.2

To investigate, ask an AI assistant: “What is the relationship between product weight, dimensions, and shipping costs?” Then inspect and run the proposed Python workflow:

  • Join order items to products by `product_id`. Calculate volume as length × height × width, and keep freight value, weight, and volume; remove rows missing those values. section 3.4.2
  • Fit separate linear regressions for weight and volume, then a model using both. Plot the relationships with confidence intervals and compare prediction errors and R². section 3.4.2
Product Weight Model: MAE=6.89, MSE=156.77, RMSE=12.52, R2=0.37
Product Volume Model: MAE=7.41, MSE=163.70, RMSE=12.79, R2=0.34

The reported single-attribute results give the weight model MAE 6.89 and R² 0.37, versus volume MAE 7.41 and R² 0.34. Weight performs somewhat better here, but neither attribute explains every shipping charge. section 3.4.2

The combined model reports R² 0.399: weight and volume together account for about 40% of the observed variation in freight value. Treat that as a reason to investigate, not proof that these attributes alone determine a charge. Check the joined records, missing-value exclusions, plots, and unusually large errors before using the result for a business decision. section 3.4.2 section 4.6

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Works through data preparation, regression, plots, and model metrics, without establishing a complete explanation of shipping charges.
Examples
Compares weight-only and volume-only freight models, then fits a combined model to order-item and product records.
What it assumes
Starts with order-item and product data and demonstrates deriving volume and fitting regressions in Python.
What you can do after
Evaluate/understand how much weight and volume explain observed freight charges using model fit and error metrics.
How it connects
Connects shipping cost to product weight, product volume, linear regression, confidence intervals, prediction error, and R².

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.