Skip to content

Instantly share code, notes, and snippets.

@gprzy
Last active March 7, 2023 04:45
Show Gist options
  • Save gprzy/bd945ab72d2e991b7e15ae4a36356677 to your computer and use it in GitHub Desktop.
Save gprzy/bd945ab72d2e991b7e15ae4a36356677 to your computer and use it in GitHub Desktop.
A Decision Tree learns how to write my name
import string; import numpy as np; from functools import reduce
from sklearn.preprocessing import MinMaxScaler; from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(np.reshape(list(range(1,27)),(-1,1)),
list(string.ascii_lowercase))
scaler = MinMaxScaler(feature_range=(1,26))
X_train = [-0.76,-1,-0.96,-0.32,-0.68,-0.84,-0.56,-0.72,
-0.84,-0.48,-0.32,-0.68,-0.36,-0.2,-0.84,-0.4,
-0.32,0,-0.04,-0.24,-0.44,-0.92,-0.6,-0.68]
X_test = scaler.fit_transform(np.reshape(X_train, (-1,1)))
pred = clf.predict(X_test)
name = reduce(lambda x, y: x+y, np.insert(pred, [7,15], ' ')).title()
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment