Sklearn classifiers

# split data
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
    samples, labels, test_size=0.3, random_state=0)

# classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt

clf = RandomForestClassifier(random_state=0)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
plt.bar(range(len(features)), clf.feature_importances_, tick_label=features)

# Save / restore model
from sklearn.externals import joblib

filename = '/tmp/clf.pkl'
joblib.dump(clf, filename)
clf = joblib.load(filename)