themodernscientist

biophysicist, data scientist, mac-unix zealot, pythonista

git commit -m 'Update life'

You may have noticed some changes around here and on my Twitter account. I've relocated to my beloved New York City and am currently attending an immersive data science bootcamp at Metis. Through mid-September, I'll be honing my existing skills in Python, statistics, and analysis and developing an entirely new set in topics like machine learning, Javascript, SQL, and Hadoop.

An integral part of Metis's bootcamp is the completion of five self-designed data science projects that both emphasize and develop data science and machine learning skills. These projects use real world1 data, tight deadlines, and simulate many of the challenges encountered by data scientists. I started my third project last Monday and look forward to sharing a few of them here and on GitHub in the coming weeks.

pdLSR: Pandas-aware least squares regression

I have a new Python project I would like to share with the community. Actually, this project isn't so new. I developed an initial version about two years before completing my postdoctoral research, and it has undergone various revisions over the past three years. Having finally made time to give it the clean-up it needed,1 I am excited to share it on GitHub.

Overview

pdLSR is a library for performing least squares minimization. It attempts to seamlessly incorporate this task in a Pandas-focused workflow. Input data are expected in dataframes, and multiple regressions can be performed using functionality similar to Pandas groupby. Results are returned as grouped dataframes and include best-fit parameters, statistics, residuals, and more. The results can be easily visualized using seaborn.

pdLSR currently utilizes lmfit, a flexible and powerful library for least squares minimization, which in turn, makes use of scipy.optimize.leastsq. I began using lmfit because it is one of the few libraries that supports non-linear least squares regression, which is commonly used in the natural sciences. I also like the flexibility it offers for testing different modeling scenarios and the variety of assessment statistics it provides. However, I found myself writing many for loops to perform regressions on groups of data and aggregate the resulting output. Simplification of this task was my inspiration for writing pdLSR.

pdLSR is related to libraries such as statsmodels and scikit-learn that provide linear regression functions that operate on dataframes. However, these libraries don't directly support grouping operations on dataframes.

The aggregation of minimization output parameters that is performed by pdLSR has many similarities to the R library broom, which is written by David Robinson and with whom I had an excellent conversation about our two libraries. broom is more general in its ability to accept input from many minimizers, and I think expanding pdLSR in this fashion, for compatibility with statsmodels and scikit-learn for example, could be useful in the future.

Throwing the Book at Your Data

You may have noticed all has been quiet on the blog front from me lately. There are several reasons for this,1 but I can assure you it isn't for lack of things to write about. Today, I'm happy to share with you one of the projects that ...

Secure Password Use in Scripts

NOTE: If you're using passwords in shell scripts, see Daniel Jalkut's reply below about using OS X's built-in security command instead of his AppleScript library.

One of my goals for the new year1 is to be more security minded in my use of technology. This is ...

Encryption of BitTorrent Sync Peers

I'd like to follow up on a previous post covering BitTorrent Sync. In this post, I mentioned privacy is one of the advantages afforded by BitTorrent Sync over traditional cloud storage options, such as Dropbox. Like most cloud storage options, data are encrypted during transmission with BitTorrent Sync.1 ...