linear regression
Tutorials
Linear Regression with Python | Connor Johnson

numpy.polyfit
np.polyfit(x,y,deg=1)

scipy.stats.linregress

scipy.optimize.curve_fit
from scipy import optimize
# Define a model function
def model_func(x, a0, a1):
return a0 + (a1*x)
param_opt, param_cov = optimize.curve_fit(model_func, x_data, y_data)
a0 = param_opt[0] # a0 is the intercept in y = a0 + a1*x
a1 = param_opt[1] # a1 is the slope in y = a0 + a1*x

examples
pandas pandas - tetsunosukenotebook

Statsmodels Examples
Linear Regression
Fitting models using R-style formulas
Examples
import pandas as pd
from statsmodels.formula.api import ols
df = pd.DataFrame(dict(x_column=x_data, y_column=y_data))
# Pass data and `formula` into ols(), use and `.fit()` the model to the data
model_fit = ols(formula="y_column ~ x_column", data=df).fit()
# Use .predict(df) to get y_model values, then over-plot y_data with y_model
y_model = model_fit.predict(df)
# Extract the a0, a1 values from model_fit.params
a0 = model_fit.params['Intercept']
a1 = model_fit.params['x_column']
uncertainty_in_intercept = model_fit.bse['Intercept']
uncertainty_in_slope = model_fit.bse['x_column]
Regression beteeen the Kushimoto-Uragami sea-level difference and Kuroshio-Path latitude (on Google Colab)

sklearn.linear_model.LinearRegression
Examples
from sklearn.linear_model import LinearRegression
# Initialize a general model
model = LinearRegression(fit_intercept=True)
# Load and shape the data
x_data = x_raw.reshape(len(y_raw),1)
y_data = y_raw.reshape(len(y_raw),1)
# Fit the model to the data
model_fit = model.fit(x_data, y_data)
# Extract the linear model parameters
intercept = model.intercept_[0]
slope = model.coef_[0,0]
# Extract the linear model parameters
intercept = model.intercept_[0]
slope = model.coef_[0,0]
MetPy Mondays `#182 - Linear Regression with Scikit-Learn - Basic Machine Learning : Unidata Developer's Blog
>This week we explore some machine learning basics on a new MetPyMonday!

sklearn.linear_model.Ridge
Tutorials
- Qiita
Paid tutorials
Machine Learning for Time Series Data in Python | DataCamp

Patsy: Describing statistical models in Python using symbolic formulas

See also