1. Home
  2. Explore
  3. Computer Science
  4. Reproducible Data Science

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Reproducible Data Science

Reproducible Data Science with Machine Learning

Data science as research

Data science and machine learning include software development, but much of the work happens before a production system exists. Early work is research-oriented: practitioners explore data, test hypotheses, try methods, and revise their approach. This process often involves many unsuccessful attempts.

Those attempts are valuable because they show how a result was reached. A clustering model that performs poorly, for example, can reveal a limitation in the data representation or the chosen algorithm. If only the final model is retained, later readers may see the result but not the reasoning that led to it.

This makes data science different from conventional application development, which often concentrates on building, testing, and maintaining a defined product. In data science, the problem and the appropriate solution may become clearer only through experimentation.

Reproducible data science preserves not only a final result, but also the data-processing steps, experiments, and reasoning that produced it.

A useful workflow therefore treats exploration and production engineering as related but distinct phases:

  • Research and modeling: explore data, test alternatives, record reasoning, and learn from failed approaches.

  • Production engineering: turn a selected, tested approach into maintainable software that can be deployed, monitored, debugged, and updated.

The transition to production often involves extracting the final method from exploratory work and implementing it in a more conventional software-development environment. In larger organizations, separate teams may handle modeling and deployment.


Notebooks as research environments

A notebook is an interactive computing environment that combines executable code with written explanations and results. It can be thought of as an interactive console that also lets the practitioner document the surrounding thought process.

A notebook can contain:

  • Code and its outputs

  • Explanations of what each step is intended to do

  • Early results, including unsuccessful ones

  • Revised code and comparisons between approaches

  • Data preparation steps and conclusions

This format makes a notebook especially suitable for exploratory work. Rather than presenting only the final successful version, a practitioner can preserve the sequence of experiments. Another person can then follow the work and understand why a particular approach was selected.

Notebooks can be hosted locally on a computer or provided through a cloud service. Cloud-hosted notebooks can make it easier to move work between environments, such as beginning locally and continuing in a customer’s cloud environment with access to that customer’s data. This can help avoid unnecessary movement or sharing of sensitive data.

Notebooks and conventional development environments

Integrated development environments (IDEs) are highly useful for debugging and maintaining software. However, they are generally organized around developing a final product. They may not make the exploratory history of a project as visible as a notebook does.

A notebook supports the research stage by making experiments and explanations part of the work itself. An IDE is often better suited to the later stage, when the method is established and must be maintained as production software.


Managing notebooks in collaborative work

Notebooks can be shared among team members, but shared editing requires care. If multiple people make changes to the same notebook, conflicting edits and outputs can make collaboration difficult.

A practical approach is to:

  1. Have each team member maintain a notebook for their own experiments.

  2. Keep those notebooks within the project’s version-controlled repository.

  3. Bring the team’s findings together in a separate notebook or other shared summary when needed.

This reduces conflicts while preserving each person’s exploratory work. It also helps distinguish individual experimentation from consolidated project results.

The approach described for exploratory work differs from the approach used after a solution is ready for production. At that point, notebooks are typically archived for reference, while the selected code, parameters, and data-preparation procedures are implemented or maintained in a more conventional software-development structure.


Version control and project organization

A reproducible project should collect the materials needed to understand and rerun the work. Depending on the project, these may include:

  • Source code, including notebook source

  • Data or saved intermediate data, where appropriate

  • The history of changes and experiments

  • Information about the software environment and its dependencies

The choice of whether to preserve intermediate or in-memory data depends on the project. Some workflows retain it between runs; others erase it and start from a clean state. The important point is to make this choice deliberately and document it when it affects the results.

Git is a widely used tool for tracking changes to source code and project files. It helps preserve project history, supports collaboration, and allows a team to inspect how work changed over time.

Notebook formats and version control

Different notebook systems store their content differently. In the R Markdown workflow described in the source, the notebook is represented as text, and the rendered notebook provides a preview of that text-based source. Text-based files are generally easier for version-control tools to compare and review.

Jupyter notebooks, by contrast, use a JSON-based file format. This can make changes less straightforward to inspect or merge, although the challenge can be managed with appropriate tools and practices. The broader principle is to understand how a notebook’s source is stored and how that format affects collaboration and change tracking.


Freezing the software environment

A project can fail to reproduce even when its code has not changed, because the packages or software libraries it depends on may have changed. To reduce this problem, a project can record or constrain the environment in which it was created.

In the R ecosystem described, one approach is to select a snapshot of package repositories at a particular date. The project then uses the package versions associated with that snapshot rather than automatically adopting later changes. The selected date might be the project’s start date or an earlier date chosen because the ecosystem was more stable at that time.

The snapshot functions as a record of the software world used for the analysis. It helps prevent subsequent changes in dependencies from silently altering results.

In Python, comparable goals can be pursued through virtual environments or tools such as Anaconda. These approaches isolate or manage project dependencies. The specific tools differ across ecosystems, but the reproducibility goal is the same:

  • Record which software and package versions were used.

  • Keep later dependency changes from unexpectedly altering an existing analysis.

  • Make it possible for another person to recreate the project’s environment.

Freezing the software environment is only one part of reproducibility. The data and the steps applied to it must also be available or otherwise controlled.


A reproducible workflow

A practical workflow can be organized into the following stages:

  1. Create a project. Establish a location for the notebook source, code, relevant data or intermediate files, and project history.

  2. Set up version control. Use Git to track changes and preserve the development history.

  3. Record the environment. Select or document the software and dependency versions, using a snapshot, virtual environment, or another suitable mechanism.

  4. Explore in a notebook. Conduct analysis and modeling while recording the code, outputs, explanations, and unsuccessful as well as successful approaches.

  5. Share or export findings. Produce an appropriate representation, such as a rendered notebook, HTML, or PDF, for readers who need to review the work.

  6. Prepare for production. Once the approach is tested and selected, archive the exploratory notebook and move the agreed code, parameters, and data-preparation steps into a maintainable production workflow.

The steps do not imply that notebooks are discarded permanently. They are retained as records of how the analysis was developed, even if they are no longer the main way the production system is run.


Reproducibility, auditability, and handover

A reproducible workflow makes it easier to answer questions such as:

  • How were the results obtained?

  • Which transformations were applied to the data?

  • Which methods were tried before the final approach was selected?

  • Were the same data and software environment used?

  • Can another person continue the work if the original practitioner is unavailable?

Including data preparation in the notebook is particularly useful. It can provide a traceable path from the initial data through analysis to conclusions. If someone questions a result or suspects an error, the relevant steps can be rerun and examined.

This supports several related goals:

  • Reproducibility: another person can rerun the documented work under the same relevant conditions.

  • Auditability: the sequence of operations can be inspected.

  • Explainability: the reasoning and choices behind a result are visible.

  • Handover: another practitioner can resume the project from its documented state.

Reproducibility depends on more than keeping a notebook. The data must be stable or appropriately recorded, and the software environment must also be controlled. Together, these make it possible to retrace the path from inputs to conclusions.


Example: improving a clustering analysis

A clustering example illustrates how a notebook can preserve the development of an analysis rather than show only its final form.

Initial attempt

A practitioner begins with data stored in a relational database and applies a standard kkk-means clustering method. The initial visualization shows substantial overlap between clusters. This suggests that the result is not useful in its current form.

Instead of replacing the initial code so that the poor result disappears, the notebook retains it. The record makes the problem visible and gives later readers context for the revisions.

Preparing categorical data

The initial clustering attempt is weak because much of the useful data is categorical, while kkk-means is generally more suited to numerical representations. The practitioner converts categorical variables into indicator columns, a technique similar to one-hot encoding in other data-science environments.

After this transformation, the clusters begin to show more structure. They still overlap, but the visualization suggests that the data is no longer represented as one undifferentiated mass.

Exploring further cluster configurations

The practitioner then uses a function that runs clustering repeatedly to explore alternative configurations. The resulting clusters show greater separation, although some overlap remains. A visualization based on principal components can help reveal variation in the data and the shape of the resulting groupings.

The notebook preserves all three stages:

  • The initial, poorly performing clustering

  • The improved representation of categorical data

  • The further exploration of cluster configurations

This sequence shows not just the final output, but the reasoning that led to it. It also allows another person to review the intermediate results and assess whether the changes were justified.


Moving work between local and cloud environments

Notebook-based work can often be transferred between compatible environments, especially when the project’s code, dependencies, and data access are managed carefully. A practitioner may begin locally and later continue in a cloud-hosted environment.

A cloud environment can offer:

  • Browser-based access to notebook tools

  • Shared access to notebooks and, where permitted, underlying data

  • Access to larger computing resources

  • The ability to run machine-learning jobs on a compute cluster

For example, a cloud-hosted environment may provide RStudio or Jupyter tools on a preconfigured compute instance. If a project grows beyond the capacity of a local computer, it may be possible to submit work to a larger cluster without rebuilding the entire environment locally.

Cloud platforms can reduce the setup burden associated with managing virtual machines, containers, or orchestration systems. This allows data scientists to concentrate more on analysis, although cloud tools still require attention to dependencies, data access, security, and compute configuration.

Local and cloud environments may differ in the packages and libraries available. Open-source workflows may transfer readily when dependencies are compatible. Proprietary or platform-specific machine-learning tools may require additional setup or may behave differently across environments.


Key principles

  • Treat modeling as research, not merely as a preliminary version of software development.

  • Preserve unsuccessful experiments when they help explain why the final approach was chosen.

  • Use notebooks to combine executable work with explanations and results.

  • Use version control to track project changes and coordinate contributions.

  • Record or freeze dependencies so that software changes do not silently alter an analysis.

  • Include data-preparation steps when they are necessary to trace results from input data to conclusions.

  • Archive notebooks as evidence of the exploratory process, even when production code is maintained elsewhere.

  • Move established methods into a software-engineering workflow when they are ready for deployment and ongoing maintenance.

The central idea is to preserve the full path from data and experiments to conclusions, then use a separate, maintainable approach for operating the selected solution in production.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent