Skip to content

Instantly share code, notes, and snippets.

@mikesparr
Created January 5, 2021 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesparr/f4acfac770e5a3491dee5a3076115326 to your computer and use it in GitHub Desktop.
Save mikesparr/f4acfac770e5a3491dee5a3076115326 to your computer and use it in GitHub Desktop.
AI Demo (model training)
# creating a function automatically (model training)
# 1. assemble some data with known answers (aka 'class' or 'label')
data = [[pizza,good],[spinach,bad],[cake,good]]
# 2. choose a portion of records for testing accuracy later
train = [[pizza,good],[spinach,bad]]
test = [[cake,good]] # if input cake, expect 'good'
# 3. extract the features for training set you think matter
# [type, smell, spice, temp, sweetness, color, class]
cleandata = [
[4, 20, 1, 135, 55, 2, 1], // pizza
[2, 12, 1, 89, 30, 4, 0], // spinach
]
# 4. separate out the known answers from the inputs (aka features)
train_x = [[4,20,1,135,55,2],[2,12,1,89,30,4]] # features
train_y = [[1],[0]] # class or labels
# 5. choose which type of function to create (trial/error)
myclassifier = SomeAlgorithmFromSomeFramework(line_type) # ignore
# 6. train your 'model' (function)
myclassifier.fit(train_x, train_y) # see goal seek example below
# 7. test accuracy
# a. extract features from test data you set aside
# b. pass in test data features and get prediction
# c. compare prediction to known value to see if it's right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment