Professional Documents
Culture Documents
Bio-Signal Analysis For Smoking
Bio-Signal Analysis For Smoking
In [10]: df.drop(columns=["ID","oral"])
df.head()
Out[10]: ID gender age height(cm) weight(kg) waist(cm) eyesight(left) eyesight(right) hearing(left) hearing(rig
5 rows × 27 columns
Checking the shape of a dataframe and datatypes of all columns along with calculating the statistical
data.
In [7]: df.shape
(55692, 27)
Out[7]:
In [8]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 55692 entries, 0 to 55691
Data columns (total 27 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ID 55692 non-null int64
1 gender 55692 non-null object
2 age 55692 non-null int64
3 height(cm) 55692 non-null int64
4 weight(kg) 55692 non-null int64
5 waist(cm) 55692 non-null float64
6 eyesight(left) 55692 non-null float64
7 eyesight(right) 55692 non-null float64
8 hearing(left) 55692 non-null float64
9 hearing(right) 55692 non-null float64
10 systolic 55692 non-null float64
11 relaxation 55692 non-null float64
12 fasting blood sugar 55692 non-null float64
13 Cholesterol 55692 non-null float64
14 triglyceride 55692 non-null float64
15 HDL 55692 non-null float64
16 LDL 55692 non-null float64
17 hemoglobin 55692 non-null float64
18 Urine protein 55692 non-null float64
19 serum creatinine 55692 non-null float64
20 AST 55692 non-null float64
21 ALT 55692 non-null float64
22 Gtp 55692 non-null float64
23 oral 55692 non-null object
24 dental caries 55692 non-null int64
25 tartar 55692 non-null object
26 smoking 55692 non-null int64
dtypes: float64(18), int64(6), object(3)
memory usage: 11.5+ MB
In [10]: df.describe()
8 rows × 24 columns
In [11]: df.isnull().sum()
ID 0
Out[11]:
gender 0
age 0
height(cm) 0
weight(kg) 0
waist(cm) 0
eyesight(left) 0
eyesight(right) 0
hearing(left) 0
hearing(right) 0
systolic 0
relaxation 0
fasting blood sugar 0
Cholesterol 0
triglyceride 0
HDL 0
LDL 0
hemoglobin 0
Urine protein 0
serum creatinine 0
AST 0
ALT 0
Gtp 0
oral 0
dental caries 0
tartar 0
smoking 0
dtype: int64
In [12]: sns.barplot(x=df["gender"],y=df["smoking"])
plt.show()
In [14]: plt.figure(figsize=(10,5))
df["smoking"].value_counts().plot.pie(autopct='%0.2f')
<Axes: ylabel='smoking'>
Out[14]:
In [15]: plt.figure(figsize=(9,6))
sns.histplot(x=df["age"],hue=df["smoking"])
plt.show()
Representation of columns using boxplot to detect outliers. Here outliers represent natural variations in
the population, and they should be left as is in the dataset. These are called true outliers. Therefore for
this dataset we will not remove outliers.
Data Cleaning
In [41]: from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
df["smoking"]=le.fit_transform(df["smoking"])
df["gender"]=le.fit_transform(df["gender"])
df["tartar"]=le.fit_transform(df["tartar"])
df["dental caries"]=le.fit_transform(df["dental caries"])
In [15]: df["smoking"].unique()
Logistic Regression
In [20]: x=df[["gender","height(cm)","Gtp","hemoglobin","triglyceride","age","weight(kg)","wai
y=df["smoking"]
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x, y, test_size=0.2, random_state= 42)
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train=sc.fit_transform(x_train)
x_test=sc.transform(x_test)
from sklearn.linear_model import LogisticRegression
lr=LogisticRegression()
lr.fit(x_train,y_train)
y_pred=lr.predict(x_test)
from sklearn.metrics import accuracy_score,classification_report
accuracy_score(y_test,y_pred)
print(classification_report(y_test,y_pred))
Decision Tree
In [21]: from sklearn.tree import DecisionTreeClassifier
dt= DecisionTreeClassifier()
dt.fit(x_train,y_train)
y_pred=dt.predict(x_test)
print(classification_report(y_test,y_pred))
C:\Users\kisha\Anaconda\lib\site-packages\sklearn\ensemble\_base.py:166: FutureWarnin
g: `base_estimator` was renamed to `estimator` in version 1.2 and will be removed in
1.4.
warnings.warn(
precision recall f1-score support
Bagging Algorithm-ExtraTrees
In [33]: from sklearn.ensemble import ExtraTreesClassifier
et=ExtraTreesClassifier(n_estimators=1000,random_state=42)
et.fit(x_train,y_train)
y_pred=et.predict(x_test)
print(classification_report(y_test,y_pred))
In [ ]: