Cheatography
https://cheatography.com
useful functions to use for building ML models
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Packages
from sklearn.model_selection import test_train_split |
from sklearn.metrics import confusion_matrix |
from sklearn.preprocessing import MinMaxScalar, StandardScalar |
Syntax
# Selecting and training the model
model =
model.fit(X_train, y_train)
# Using the model to predict
y_pred = model.predict(X_test)
|
|
|
Processing data
MinMaxScalar().fit_transform([[value] for value in data]) |
min-max-scaling (normalization) works well if predictor is roughly uniform Z score scaling (standardisation) works if there are outliers |
dummy_vars = pd.get_dummies(df.col) df = pd.concat([df, dummy_vars], axis=1) |
one hot encoding |
train, test = train_test_split(df, test_size=0.2) |
Evaluating model
confusion_matrix(y_test, y_pred) |
|