Skip to content

(07.26) Coding Study Classification

zelabean edited this page Jul 26, 2018 · 1 revision
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 26 14:37:29 2018

@author: bise
"""

from matplotlib import pyplot as plt
import numpy as np
from sklearn.datasets import load_iris
data = load_iris()
features = data.data
feature_names = data.feature_names
target = data.target
target_names = data.target_names
for t in range(3):
    if t == 0:
        c = 'r'
        marker = '>'
    elif t == 1:
        c = 'g'
        marker = 'o'
    elif t == 2:
        c = 'b'
        marker = 'x'
    plt.scatter(features[target == t,0],
                features[target == t,1],
                marker = marker,
                c = c)
    
labels = target_names[target]
plength = features[:,2]
is_setosa = (labels == 'setosa')
    
max_setosa = plength[is_setosa].max()
min_non_setosa = plength[~is_setosa].min()
    
features = features[~is_setosa]
labels = labels[~is_setosa]
is_virginica = (labels == 'virginica')

best_acc = -1.0
for fi in range(features.shape[1]):
    thresh = features[:,fi]
    for t in thresh:
        feature_i = features[:,fi]
        pred = (feature_i > t)
        acc = (pred == is_virginica).mean()
        rev_acc = (pred == ~is_virginica).mean()
        if rev_acc > acc:
            reverse = True
            acc = rev_acc
        else:
            reverse = False
            if acc > best_acc:
                best_acc = acc
                best_fi = fi
                best_t = t
                best_reverse = reverse
                
"""
선을 못긋겠음    
features = data.data
feature_names = data.feature_names
target = data.target
target_names = data.target_names

for t in range(3):
    if t == 0:
        c = 'r'
        marker = '>'
    elif t == 1:
        c = 'g'
        marker = 'o'
    elif t == 2:
        c = 'b'
        marker = 'x'
    plt.scatter(features[target == t,2],
                features[target == t,3],
                marker = marker,
                c = c)
"""
"""
def is_virginica_test(fi, t, reverse, example):
    test = example[fi] > t
    if reverse:
        test = not test
    return test
"""

Clone this wiki locally