Created
January 7, 2018 08:03
-
-
Save koushikmln/e7b21c6521315dacc4ddc6879b492c0e to your computer and use it in GitHub Desktop.
ML Example Using SKLearn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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