Skip to content

Instantly share code, notes, and snippets.

@koushikmln
Created January 7, 2018 08:03
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 koushikmln/e7b21c6521315dacc4ddc6879b492c0e to your computer and use it in GitHub Desktop.
Save koushikmln/e7b21c6521315dacc4ddc6879b492c0e to your computer and use it in GitHub Desktop.
ML Example Using SKLearn
weight texture label
150 bumpy orange
170 bumpy orange
155 bumpy orange
180 bumpy orange
182 bumpy orange
130 smooth apple
140 smooth apple
120 smooth apple
115 smooth apple
100 smooth apple
import numpy as np
import pandas as pd
import sklearn
from sklearn import tree
df = pd.read_csv("/data/input.csv")
texture_map = {"bumpy":0, "smooth":1}
df["texture"] = df["texture"].map(lambda x: texture_map[x])
label_map = {"orange":0, "apple":1}
df["label"] = df["label"].map(lambda x: label_map[x])
print(df.head())
clf = tree.DecisionTreeClassifier()
input_X = df[["weight", "texture"]]
input_y = df["label"].values
clf.fit(input_X, input_y)
print(clf.predict([[160,0]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment