-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeatures.py
78 lines (53 loc) · 1.78 KB
/
features.py
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
# -*- coding: utf-8 -*-
"""Features.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/18uLPiducb7uDtXEG5TvEnc2TVT-s20Ki
"""
!wget https://raw.githubusercontent.com/mdhabeebvulla/samples/master/datasetsiris.csv
import pandas as pd
import numpy as np
import seaborn as sns
df = pd.read_csv('datasetsiris.csv')
df.head()
df1 = df.iloc[:,1:6]
df1['Species'].unique()
df1['Species'] = df1['Species'].replace(['Iris-setosa', 'Iris-versicolor', 'Iris-virginica'],[0,1,2])
df1.head()
sns.heatmap(df1.iloc[:,0:5].corr().abs(),annot=True)
import matplotlib.pyplot as plt
X = df1.iloc[:,1:4]
y = df1.iloc[:,4]
from sklearn.feature_selection import SelectKBest, chi2
X.shape
X_new = SelectKBest(chi2,k='all').fit_transform(X, y)
X_new.shape
X_new
df2 = df1.iloc[0:100,:]
df2.shape
df2.head()
df2['Species'].unique()
import matplotlib.pyplot as plt
sns.FacetGrid(df2,hue='Species',size=10)\
.map(plt.scatter,'SepalLengthCm','SepalWidthCm')\
.add_legend()
pass
xfit = np.linspace(-1, 7.0)
plt.scatter(P.iloc[:, 0], P.iloc[:, 1], c=q, s=50, cmap='viridis')
plt.plot([0.6], [2.1], 'x', color='red', markeredgewidth=2, markersize=10)
for m, b in [(1, 0.65), (0.5, 1.6), (-0.2, 2.9)]:
plt.plot(xfit, m * xfit + b, '-k')
plt.xlim(4, 7.2);
from sklearn.svm import SVC # "Support vector classifier"
model = SVC(kernel='linear', C=1E10)
model.fit(P, q)
import matplotlib.pyplot as plt
import seaborn as sns
#plt.figure(figsize=(10, 8))# Plotting our two-features-space
sns.scatterplot(x=P.iloc[:, 0],y=P.iloc[:, 1],hue=q,s=50)
# Constructing a hyperplane using a formula.
w = model.coef_[0]
b = model.intercept_[0]
x_points = np.linspace(-1, 4)
y_points = -(w[0] / w[1]) * x_points - b / w[1]
plt.plot(x_points, y_points, c='r');