-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (63 loc) · 2.34 KB
/
main.py
File metadata and controls
88 lines (63 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pandas as pd
import matplotlib.pyplot as plt
# %matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
from sklearn.decomposition import PCA
import seaborn as sns
iris = pd.read_csv(r"D:\github\MachineLearning\data\iris.data",
header=None,
names=['petal length', 'petal width',
'sepal length', 'sepal width', 'species'])
iris.head()
iris.shape
iris.shape[0]
iris.shape[1]
x_min, x_max = iris['petal length'].min() - .5, iris['petal length'].max() + .5
y_min, y_max = iris['petal width'].min() - .5, iris['petal width'].max() + .5
colors = {'Iris-setosa': 'red', 'Iris-versicolor': 'blue', 'Iris-virginica': 'green'}
fig, ax = plt.subplots(figsize=(8, 6))
for key, group in iris.groupby(by='species'):
plt.scatter(group['petal length'], group['petal width'],
c=colors[key], label=key)
ax.legend()
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
ax.set_title("IRIS DATASET CATEGORIZED")
plt.show()
x_min, x_max = iris['sepal length'].min() - .5, iris['sepal length'].max() + .5
y_min, y_max = iris['sepal width'].min() - .5, iris['sepal width'].max() + .5
colors = {'Iris-setosa': 'red', 'Iris-versicolor': 'blue', 'Iris-virginica': 'green'}
fig, ax = plt.subplots(figsize=(8, 6))
for key, group in iris.groupby(by='species'):
plt.scatter(group['sepal length'], group['sepal width'],
c=colors[key], label=key)
ax.legend()
plt.xlabel('sepal length')
plt.ylabel('sepal width')
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
ax.set_title("IRIS DATASET CATEGORIZED")
plt.show()
fig, ax = plt.subplots(2, 2, figsize=(10, 6))
plt_position = 1
feature_x = 'petal width'
for feature_y in iris.columns[:4]:
plt.subplot(2, 2, plt_position)
for species, color in colors.items():
plt.scatter(iris.loc[iris['species'] == species, feature_x],
iris.loc[iris['species'] == species, feature_y],
label=species,
alpha=0.45, # transparency
color=color)
plt.xlabel(feature_x)
plt.ylabel(feature_y)
plt.legend()
plt_position += 1
plt.show()
pd.plotting.scatter_matrix(iris, figsize=(8, 8),
color=iris['species'].apply(lambda x: colors[x]));
plt.show()
sns.set()
sns.pairplot(iris, hue="species")