PyCharm Productivity Hacks

This post will describe some hacks to improve your productivity on Machine Learning projects. This post is scoped around Python development in the PyCharm IDE. 

  • Scientific Mode: This feature is only available on the Professional Version of PyCharm.
    • Code blocks: Using # %%  at the start of a code block, creates a cell, similar to a cell in Jupyter. You will then have access to a dedicated play button for that cell, allowing you to prototype commands quickly without having to run the entire code block. This adds value when you have a load function in your code, which will take up time to run
    • View variable: You are able to view a sample of the data you have just loaded, and are able to see a plot of that data. This feature is useful during the data exploration stage, as you are trying to build hypothesis.
    • In-line visualisation: You can see the results of cell commands such as seaborn or matplotlib, in line, just by running a cell. Not having to run the entire program, leading to productivity benefit
    • Method: Ctrl+Alt+M, Ctrl+Alt+P. Creates a function automatically for you, based on the code you have selected. Useful to organise repeating code into a function, after you have perfected it.
  • Data Visualisation: The following codeblocks will allow you to interrogate your data, as you begin to form hypothesis 
import seaborn as sns
from matplotlib import pyplot as plt
sns.countplot(x='Survived', hue='sex', data=dataframe)
plt.show()
  • Dataframe investigation:

    • Sampling: df.sample(10). It allows you to investigate the characteristics of a dataframe, without loading the entire dataframe
    • How many null values: df.isnull().sum()
  • Refactor: Select variable to rename, and choose refactor. It will only change the name within the scope of a function
  • Duplicate: Select the line to duplicate, and hit Ctrl + D
  • Tracklist of changes: Alt + Shift + C. Useful when you're code no longer works so that you can step back to a codebase that works, and try again. 
  • To-do list: Make to-do directly in-line the codebase, and have a central list. # todo note 1
  • Surround with: Select a particular text, and hit Ctrl + Alt + T. PyCharm will offer a list of options what functions you can auto-complete, and will author this for you. E.g. If-else
  • Debugging tool:
    • Click on a line # to add/remove breakpoints. The code will break execution at that point, and you can see the values of all the variables already in memory. We are then able to directly evaluate expression associated with these variables, directly in the debugger, for quick investigation
    • Can resume the code to run till the next breakpoint. You can stop debugging when you would like.
    • You can select "Step into my code", to allow the code to run after a breakpoint, in a instruction by instruction fashion, allowing you to evaluate where exactly the code is failing. This is similar to the function available in Excel. We can similarly click on evaluate expressions, to evaluate expressions associated with the variables already in memory


Comments

Popular posts from this blog

1.2 Structured Data: Information Driven Bars

2.2 Labeling: Triple barrier method

1.1 Structured Data: Standard Bars