Last active
February 19, 2019 00:19
-
-
Save a-mitani/87b582420dac63b5f880f289f95b1f2e to your computer and use it in GitHub Desktop.
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
# -*- 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