Emanuele Meazzo builds a linear regression in Power BI using a Python visual:
As a prerequisite, of course, you’ll need to have python installed in your machine, I recommend having an external IDE like Visual Studio Code to write your Python code as the PowerBI window offers zero assistance to coding.
You can follow this article in order to configure Python Correctly for PowerBI.
Step 2 is to add a Python Visual to the page, and let the magic happen.
Click through for the step-by-step instructions, including quite a bit of Python code and a few warnings and limitations.