Every ML beginner hits the same wall: you know what you want to do, but you can't remember the exact syntax.
Is it fit_transform or transform? Which scaler do I use for outliers? How do I plot a confusion matrix again?
I got tired of Googling the same things, so I built a repo that has all of it in one place.
π github.com/Kavi274/python-ml-cheatsheets
What's Inside
9 cheat sheets covering the full ML workflow:
1. NumPy
Arrays, indexing, broadcasting, linear algebra β the foundation of everything.
python
a = np.array([[1, 2, 3], [4, 5, 6]])
a[a > 3] # [4, 5, 6]
a.reshape(3, 2)
np.dot(A, B) # matrix multiplication
2. Pandas
DataFrames, groupby, merge, datetime, string ops.
df.groupby("city").agg({"sales": "sum", "profit": "mean"})
df.isnull().sum()
pd.merge(df1, df2, on="id", how="left")
3. Scikit-learn
Every major model, pipelines, cross-validation, and hyperparameter tuning.
pipe = Pipeline([
("scaler", StandardScaler()),
("model", RandomForestClassifier())
])
pipe.fit(X_train, y_train)
4. Matplotlib & Seaborn
Every plot type with copy-paste code β histograms, heatmaps, ROC curves, feature importance.
sns.heatmap(df.corr(), annot=True, fmt=".2f", cmap="coolwarm")
5. Data Preprocessing
Missing values, scaling, encoding, class imbalance β the full cleaning pipeline.
num_pipeline = Pipeline([
("impute", SimpleImputer(strategy="median")),
("scale", StandardScaler())
])
6. Feature Engineering
Datetime features, target encoding, cyclical encoding, PCA, SHAP-based selection.
df["month_sin"] = np.sin(2 * np.pi * df["month"] / 12)
df["month_cos"] = np.cos(2 * np.pi * df["month"] / 12)
7. Model Evaluation
ROC, precision-recall curves, confusion matrix, optimal threshold, SHAP explainability, calibration.
fpr, tpr, _ = roc_curve(y_test, y_prob)
roc_auc = auc(fpr, tpr)
8. Deep Learning (Keras)
CNNs, RNNs, transfer learning, callbacks, tf.data pipelines.
base_model = keras.applications.EfficientNetB0(
include_top=False, weights="imagenet"
)
base_model.trainable = False
9. Statistics for ML
Distributions, hypothesis tests, A/B testing, Bayes' theorem.
stat, p = stats.ttest_ind(group1, group2, equal_var=False)
print(f"p={p:.4f} β {'Significant' if p < 0.05 else 'Not significant'}")
---
How to Use It
No setup. No notebooks to run. Every cheat sheet is plain Markdown β just open it on GitHub and hit Ctrl+F.
Clone it locally if you want it offline:
git clone https://github.com/Kavi274/python-ml-cheatsheets.git
---
What's Next
Planning to add:
- PyTorch
- XGBoost / LightGBM
- Time Series (Prophet, statsmodels)
- HuggingFace Transformers
PRs are welcome β if you know a topic well, add a cheat sheet!
---
If this saves you even one Google search, consider leaving a β on GitHub β it helps others find it.
π https://github.com/Kavi274/python-ml-cheatsheets
Top comments (0)