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
from sklearn import datasets | |
import numpy as np | |
from sklearn.cross_validation import train_test_split | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import Perceptron | |
from sklearn.metrics import accuracy_score | |
# Irisデータセットをロード | |
iris = datasets.load_iris() | |
# 3,4列目の特徴量を抽出 |
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 pandas as pd | |
df = pd.read_csv('https://archive.ics.uci.edu/ml/' | |
'machine-learning-databases/iris/iris.data', header=None) | |
import matplotlib.pyplot as plt | |
import numpy as np | |
y = df.iloc[0:100, 4].values | |
y = np.where(y == 'Iris-setosa', -1, 1) | |
X = df.iloc[0:100, [0, 2]].values |
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 | |
class Perceptron(object): | |
""" | |
eta: 学習率(0.0<eta<1.0) | |
n_iter: トレーニング回数 | |
""" | |
def __init__(self, eta=0.01, n_iter=10): | |
self.eta = eta | |
self.n_iter = n_iter |