Free JYnapse Knowledge Base · Cheat Sheet
The end-to-end workflow — frame the problem, split, preprocess, train, evaluate — with scikit-learn code and the metrics that tell you if it actually works.
| Predict a category | Classification |
| Predict a number | Regression |
| Group similar items | Clustering |
| Simplify / compress | Dim. reduction |
| What to recommend | Recommenders |
First two are supervised (you have labelled answers). Clustering is unsupervised. Know which before touching a model.
Never let test data influence training — that's leakage, and it fakes great scores.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42,
stratify=y) # keep class balance
Typical 80/20 or 70/30. random_state makes it reproducible. Keep the test set locked away until the very end.
from sklearn.preprocessing import StandardScaler, OneHotEncoder
# scale numbers, encode categories
StandardScaler().fit_transform(X_num)
OneHotEncoder(handle_unknown="ignore")
SimpleImputer).| Linear / Logistic | Fast baseline, interpretable |
| Decision Tree | Rules, easy to explain |
| Random Forest | Strong default, low fuss |
| Gradient Boosting | Often best on tabular (XGBoost/LightGBM) |
| KNN / SVM | Small, clean datasets |
| K-Means | Clustering |
For tabular business data, start with a Random Forest or gradient boosting — rarely the wrong call.
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=300,
random_state=42)
model.fit(X_train, y_train)
pred = model.predict(X_test)
proba = model.predict_proba(X_test)[:, 1]
Every scikit-learn estimator follows the same fit → predict pattern — swap models with one line.
| Accuracy | % correct — bad on imbalance |
| Precision | Of predicted-positive, how many right |
| Recall | Of actual-positive, how many caught |
| F1 | Balance of precision & recall |
| ROC-AUC | Ranking quality, 0.5 = random |
99% accuracy is meaningless if 99% of cases are one class. Use the confusion matrix + F1/recall for fraud, churn, disease.
| MAE | Avg absolute error — same units |
| RMSE | Penalises big misses |
| R² | % of variance explained |
| MAPE | Error as a % |
from sklearn.metrics import mean_absolute_error, r2_score
mean_absolute_error(y_test, pred)
r2_score(y_test, pred)
from sklearn.model_selection import cross_val_score
cross_val_score(model, X, y, cv=5).mean()
from sklearn.pipeline import make_pipeline
pipe = make_pipeline(StandardScaler(), model)
pipe.fit(X_train, y_train)
GridSearchCV / RandomizedSearchCV.joblib.dump(pipe, "model.pkl").JYnapse Knowledge Base · Free to read and print. Code uses scikit-learn. Available in English, Bahasa Melayu and 中文 on request.