Repository navigation
Expand file tree
/
Copy pathAssignment3-Exercise1.py
More file actions
68 lines (53 loc) · 1.61 KB
/
Copy pathAssignment3-Exercise1.py
File metadata and controls
68 lines (53 loc) · 1.61 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
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 21 14:28:18 2019
#Maryam Assaedi
#Mst. Mahfuja Akter
#Mahpara Hyder Chowdhury
"""
import pandas as pd
import seaborn as sns
#a
df=pd.read_csv('winequality-red.csv', sep=';')
print(df.head())
#b
#range from 3 till 8
sns.distplot(df['quality'],kde=False);
#c
#replace quality with labels
df.quality.replace([3,4,5,6,7,8], ['low','low','medium','medium','high','high'], inplace=True)
df.rename(columns={'quality':'quality bin'}, inplace=True)
#d
highLowQuality = df[df['quality bin']!='medium']
#e
sns.pairplot(highLowQuality, hue="quality bin")
#g
import numpy as np
import matplotlib.pyplot as plt
from sklearn.feature_selection import SelectPercentile, f_classif
X = highLowQuality.drop('quality bin',axis=1).values
y = highLowQuality['quality bin'].values
plt.figure(1)
plt.clf()
X_indices = np.arange(X.shape[-1])
selector = SelectPercentile(f_classif)
selector.fit(X, y)
scores = -np.log10(selector.pvalues_)
scores /= scores.max()
plt.bar(X_indices, scores)
plt.title("Comparing feature selection")
plt.xlabel('Feature number')
plt.show()
#g
filtered=pd.DataFrame()
filtered['volatile acidity']=highLowQuality['volatile acidity']
filtered['citric acid']=highLowQuality['citric acid']
filtered['pH']=highLowQuality['pH']
filtered['sulphates']=highLowQuality['sulphates']
filtered['alcohol']=highLowQuality['alcohol']
filtered['quality bin']=highLowQuality['quality bin']
#h
g = sns.PairGrid(filtered, hue = 'quality bin')
g = g.map_upper(plt.scatter)
g=g.map_lower( sns.regplot,scatter=False)
g=g.map_diag(sns.kdeplot)