Reproducible Data Science


Reproducible Data Science

Corey
Welcome to the show. Today we’re exploring reproducible data science with machine learning: why it differs from ordinary software development, and how to preserve the path from an early idea to a model that’s ready for production. Maria, our guest has spent more than a dozen years in data science, beginning in data mining and moving through predictive analytics and machine learning.

Maria
Thanks, Corey. A key distinction is that modeling is much more like research than like conventional software development. Software engineering becomes especially important near the end, when we’re preparing something for production. Before that, a lot of the work is investigating, trying approaches, and learning from mistakes.

Corey
And those mistakes aren’t just clutter to sweep away. They can explain why a particular solution was chosen, and help someone else understand or continue the work. If all we keep is polished final code and results, we lose the story of how we got there.

Maria
Exactly. A typical development environment, such as an IDE, is very useful for building and maintaining the final product. It may have excellent debugging tools, but it doesn’t naturally make all the exploratory work visible. In a machine-learning project, seeing the unsuccessful attempts can be valuable evidence of how the analysis developed.

Corey
So what kind of environment makes that research process easier to capture? You’ve emphasized notebooks. What should listeners picture when you say that?

Maria
Think of a notebook as an interactive console with room for explanations. You write and run code, inspect the results, and put notes and reasoning alongside it. You can keep an earlier attempt, explain why it didn’t work as hoped, and then try a revised approach, so a reader sees more than just the final answer.

Corey
That sounds useful both for your own memory and for handing work to a colleague. And notebooks don’t have to live in just one place, right?

Maria
Right. You can run one locally, integrate notebook work into an IDE, or use a hosted notebook environment. Hosted options can make it easier to move a notebook between environments—for example, to continue working in a customer’s cloud with access to its data, without needing to share that data or cross unnecessary security boundaries.

Corey
But collaboration brings a practical problem: if several people edit the same notebook, their outputs and changes can conflict. How do you keep that manageable?

Maria
A notebook can be shared, but it helps to divide the work into components. One practical approach is for each person to maintain an individual notebook as part of the project, with the notebooks managed using Git. The team can then bring results together where appropriate, rather than having everyone continually edit one shared file.

Corey
So the individual notebooks preserve each person’s exploration, while Git keeps the project’s work under version control. Then, when the model is ready, the team changes how it works?

Maria
Yes. Once the final approach has been tested and it’s time to deploy, the workflow shifts toward conventional software development. You take the final versions, chosen parameters, and agreed data-preparation steps into a more production-oriented codebase, often using an IDE. You archive the notebooks rather than discard them, because they remain useful records of the research.

Corey
That separation also fits how larger organizations may be structured. A research-oriented modeling team and a team responsible for deployment can have distinct roles, while still being part of the same machine-learning lifecycle.

Maria
That’s the idea. The exploratory phase needs room for investigation; production work needs code that can be deployed, maintained, debugged, and updated. Treating them as different phases lets each environment support the work it’s best suited for.

Corey
Let’s turn that into a reproducible workflow. What are the first steps before someone starts experimenting?

Maria
Start by creating a project to hold the source code, including the notebook, and any in-memory data you choose to save between runs. Decide whether to preserve that data or clear it and begin fresh; there are different preferences, so it’s a project choice. Then set up Git for versioning and source control.

Corey
And a crucial next step is making sure the software environment doesn’t quietly change underneath the analysis. How does the workflow handle that?

Maria
In the R ecosystem described here, one approach is to use a snapshot of the package repository. CRAN contains the R packages, and Microsoft’s MRAN provided daily snapshots of CRAN. At the start of a project, you can select a snapshot date and keep using that state of the ecosystem, instead of having later dependency changes alter your results.

Corey
The date might be when the project begins, or a slightly earlier point if the ecosystem was more stable then. The important idea is to freeze the dependencies at a known state, so someone can recreate the same setup later.

Maria
Yes—and reproducibility depends on more than the software environment. The data needs to be frozen too. If both the data and the environment are preserved, the analysis has a much stronger basis for being replayed and checked.

Corey
How does that compare with Python?

Maria
In Python, virtual environments and tools such as Anaconda can help manage dependencies. There are several tools and choices involved, and the comparison with R isn’t entirely fair because Python’s dependency landscape can be more complex. The broader lesson is the same: record and control the environment your work depends on.

Corey
What about the notebook formats themselves? The conversation points out a difference between R Markdown in RStudio and Jupyter.

Maria
With RStudio and R Markdown, the notebook source is text, and the notebook gives you a preview of what you’re doing. That can make Git changes easier to inspect. Jupyter notebooks use JSON as their source format, with a layer between the work you see and that underlying file, so Git comparisons can be less straightforward. There are ways to address that, but it’s a difference worth knowing.

Corey
Once the analysis is underway, the notebook is where code, results, and reasoning live together. And when it’s time to share findings, you can export them rather than making everyone open the notebook itself.

Maria
Exactly. You might export a PDF or HTML version, for example, or prepare material for an academic journal. Then, when the work is ready for production, move the tested solution into the more traditional software-development workflow and keep the notebook archived for future reference.

Corey
Let’s make that concrete with the clustering example. The first k-means result looked poor, but instead of quietly changing the code and hiding that first attempt, the notebook kept it visible.

Maria
That matters because the initial data contained useful categorical information, while k-means prefers numerical input. The first visualization showed clusters with substantial overlap—so the result wasn’t a compelling way to model the data. The notebook made that limitation visible and documented the reasoning behind the next step.

Corey
The next attempt converted the categorical data into indicator columns, similar to one-hot coding. That made the data more suitable for the algorithm, and the visual pattern began to look more structured, even though the clusters still overlapped.

Maria
Then the analysis used an automated clustering technique, described as a k-means runs function, to explore the cluster arrangement further. The clusters gained some separation, though overlap remained. The point of the example isn’t to claim that every issue was solved; it’s that the notebook preserves each attempt and the evidence that informed the next one.

Corey
And the notebook can keep data preparation, code, and results together. Someone returning months or even years later can retrace the analysis rather than being handed only a final model and asked to guess how it was made.

Maria
That supports auditability and explainability. If a reviewer questions a conclusion or wants to check that the data and statistics were handled appropriately, you can replay parts of the notebook and follow the process from the starting data through the preparation steps to the conclusions. It also helps another person pick up the work if the original researcher is unavailable.

Corey
The demonstration also showed that the same kind of notebook work can move from a local R setup to a hosted environment. In the example, that was RStudio running in an Azure Machine Learning compute instance.

Maria
The hosted instance had JupyterLab, Jupyter, and RStudio available, so the researcher could work in RStudio through a browser. Because that setup wasn’t using SQL Server Machine Learning Services, it needed one additional step: installing the checkpoint package before using the snapshot approach. Otherwise, the setup was broadly similar, subject to the packages and libraries installed in each environment.

Corey
What benefits did the cloud setup add beyond simply having RStudio in a browser?

Maria
It could provide shared access to notebooks and to underlying data managed through Azure Machine Learning. And if the computation needs grow, the work can be sent to a larger compute cluster, including an R Spark cluster, without the researcher setting up all of that infrastructure locally. That can let data scientists focus more on the analysis instead of configuring IDEs, containers, or Kubernetes.

Corey
There was also a local example using SQL Server Machine Learning Services, which can be useful when data already lives in a relational database and the analysis needs to happen close to it. The larger lesson is that the notebook workflow can be adapted to different environments, while the data and dependency setup still need attention.

Maria
Right. Some proprietary Microsoft machine-learning capabilities, including those mentioned for SQL Server and Microsoft’s ML packages, can make the cloud setup more involved. But for the open-source packages in the example, the notebook work was essentially the same across the local and hosted RStudio environments.

Corey
Let’s recap the central workflow: create a project, use Git, control the dependency environment, and do the exploratory modeling in notebooks that preserve both the results and the reasoning.

Maria
Then share or export findings as needed, and when the solution is tested and ready for production, move the final code and agreed parameters into a more conventional software-development workflow. Keep the notebooks archived, because they’re the record that makes the journey easier to reproduce, review, and hand off.

Corey
That’s a helpful way to think about it: data science has a scientific phase where experiments and mistakes are part of the work, followed by a production phase where software engineering takes the lead. For more about Rafal’s courses, the episode mentioned projectbotticelli.com for live training and tecflix.com for self-paced video learning.

Maria
And the practical takeaway is not to erase the research just because the final model is ready. Capture the steps, preserve the data and environment as carefully as you can, and keep the notebook as a readable account of how you reached the result.

Corey
Thanks for joining us for this conversation on reproducible data science with machine learning. We’ve seen why notebooks fit exploration, how version control and snapshots help preserve work, and why production deployment calls for a different phase. Thanks for listening, and we’ll see you next time.

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