Skip to content

Scikit Learn

Alex Albenstetter edited this page Jun 5, 2023 · 5 revisions

Very good resources

Scikit Learn ML Cheatsheet

Algorithm Selection

General

Genrally one can apply this step-by-step approach for machine learning in scikit-learn:

  1. Import the model you want to use e.g. from sklearn.tree import DecisionTreeClassifier
  2. Make an instance of the Model clf = DecisionTreeClassifier(max_depth = 2, random_state = 0)
  3. Train the model on the data clf.fit(X_train, Y_train)
  4. Predict labels of unseen (test) data clf.predict(X_test)

Classification

Decision Tree Classifier

Import

from sklearn import tree
from sklearn.tree import DecisionTreeClassifier

Random Forest Classifier

Import

from sklearn.ensemble import RandomForestClassifier

Support Vector Classifier

Import

from sklearn.svm import SVC

Preprocessing

Import

from sklearn.preprocessing import StandardSclaer, LabelEncoder
from sklearn.model_selection import train_test_split