Ask HN: I am a data analyst and my code is a mess
I have a spaghetti code problem. I am a data scientist/analyst, and my day to day is entirely in python/sci-kitlearn/pandas, data munging and running models. Right now my code is several hundred lines of data processing steps, filtering, lots and lots of joins and sql queries, pickle dumps and loads, print array.shape. I try to create as many functions as possible to help organize the code, and put different parts of the project into different scripts. I utilize ipython notebook on the cloud for the interactive portion of my analysis, and sublimetext2 for the fixed data processing scripts.
Long story short, I have a physics background and was never taught how to properly structure my workflow for this type of coding. Should I be creating more classes and objects?
Are there any resources out there on how to code and structure large machine learning projects like this? Or is it doomed to be spaghetti code?
11 comments
[ 4.0 ms ] story [ 31.5 ms ] threadThe goal is to find data that needs to be grouped, and group it. Find functions that only use that grouped data, and stick them in classes.
For example a query can be an object. I.E.: A database connection (in java)
Then you query specific pre-processing code can be added directly into the query. Which results in code like I don't know if this helps. But its a suggestion.P.S.: I've been spending my free nights the past 2 weeks trying to throw together a javascript based data processing engine in java. It should be mostly workable by the weekend. I could throw it on a ShowHN if you'd be interested.
For example mydata=dataobject(query, connectionstring()) mydata.query() # get data mydata.data # pandas data frame mydata.write_to_db() # write to db method
etc.
Sounds similar to what youre doing here, although I don't know Java...
- python probably has a lib like underscore (reduce map filter etc), could help
- check out the quake source code, any version, its huge and the entire thing is not only readable but possibley a work of art.
- have you tried lambdas? to some its more readable.. ex:
personally when i have too complex process i like to go more functional, ex: that allows me to focus on only on building one step and still have readable code.many game-devs prefer breaking their project into many tiny files with a specific purpose instead of spaghetti, ex:
its also a bit easier to nav around the project and make sense of it this way. you might want to check out rust or D or F or another lang also.Between builtins, itertools, and functools, you pretty much have it covered.
(Look here: https://en.wikipedia.org/wiki/Higher-order_function#General_... )
If it's your own opinion, then it's possible you're being unduly harsh on your own work. Perhaps you can publish it - or a suitable equivalent - on github and request people here for code reviews.
Compiled version: http://warewolf.io Source code from GitHub: https://github.com/Warewolf-ESB/Warewolf-ESB
From the FAQ: http://www.scleradb.com/doc/info/faq#i-am-an-analytics-consu... why-do-i-need-sclera > Specifically, Sclera separates the analytics logic from the processing and data access. The analytics logic is specified declaratively as SQL queries with Sclera’s analytics extensions. This is just a few lines of code, which can be changed easily. The analytics libraries, database systems and external data sources form their own modules and are separated from the analytics logic. The analytics queries are compiled by Sclera into optimized workflows that dynamically tie everything together.