Skip to content

Instantly share code, notes, and snippets.

@a-mitani
Last active February 19, 2019 00:19
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 a-mitani/87b582420dac63b5f880f289f95b1f2e to your computer and use it in GitHub Desktop.
Save a-mitani/87b582420dac63b5f880f289f95b1f2e to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
from sklearn import tree
# 教師データをロード
df = pd.read_csv('xor_simple.csv');
data_array = df[['x', 'y']].values
class_array = df['class'].values
# 学習(決定木)
clf = tree.DecisionTreeClassifier()
clf = clf.fit(data_array, class_array)
#学習後に、2つのデータを与えてそれらを分類。
#与えられた教師データの特徴から考えると
# x=2.0, y=1.0 であれば、クラス「0」に分類されるはず。
# x=1.0, y= -0.5であれば、クラス「1」に分類されるはず。
result = clf.predict([[2., 1.], [1., -0.5]])
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment