Skip to content

Description:

  • Machine learning in Python: classification, regression, clustering, dimensionality reduction and model selection.

Resources:

Source and license:

  • Some of these examples are adapted from the scikit-learn documentation (Getting Started and the Naive Bayes user guide) (https://scikit-learn.org/stable/), Copyright (c) 2007-2026 The scikit-learn developers, licensed under BSD-3-Clause. That code stays under its own license; see THIRD_PARTY_NOTICES.md.

Fit a RandomForestClassifier to some very basic data

from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(random_state=0)
X = [[ 1, 2, 3], # 2 samples, 3 features
[11, 12, 13]]
y = [0, 1] # classes of each sample
clf.fit(X, y)

Implements the Gaussian Naive Bayes algorithm for classification

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)
gnb = GaussianNB()
y_pred = gnb.fit(X_train, y_train).predict(X_test)
print("Number of mislabeled points out of a total %d points : %d"
% (X_test.shape[0], (y_test != y_pred).sum()))

ganymede is made by Eugo