Created
August 9, 2018 08:29
-
-
Save eomlocal/8ae5c4f328595d22948a79f51b760223 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
import tensorflow as tf | |
import matplotlib.pyplot as plt | |
import math | |
import numpy as np | |
from sklearn.datasets import load_iris | |
data=load_iris() | |
print(data) | |
print(data.keys()) | |
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], # sepal length | |
features[target == t, 1], # sepal width | |
marker = marker, | |
c = c) | |
plength=features[:,2] | |
labels=target_names[target] | |
is_setosa=(labels=='setosa') | |
max_setosa=plength[is_setosa].max() | |
min_non_setosa=plength[~is_setosa].min() | |
print('Maximun of setosa:{0}.'.format(max_setosa)) | |
print('Minimun of other:{0}.'.format(min_non_setosa)) | |
features=features[~is_setosa] | |
labels=labels[~is_setosa] | |
is_virginica=(labels == 'verginica') | |
best_acc=0.0 | |
for feature in range(features.shape[1]): | |
threshold=features[:,feature] | |
for t in threshold: | |
feature_i=features[:,feature] | |
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_t = t | |
best_reverse = reverse | |
print(best_t, best_reverse, best_acc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment