Nothing Special   »   [go: up one dir, main page]

Covid-19 Prediction - Jupyter Notebook

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

In 

[45]:

#we are importing the all required libraries which are useful for yhe model

In [46]:

import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

In [47]:

#Adding the dataset to the model

In [48]:

df = pd.read_excel("C:\MINI PROJECT\covid19-symptoms-dataset (2).xlsx")

In [49]:

#Scaning the data

In [50]:

df.head()

Out[50]:

Dry Cough High Fever Sore Throat Difficulty in breathing Infected with Covid19

0 0 2 3 0 No

1 15 15 20 16 Yes

2 4 5 0 0 No

3 4 7 9 10 No

4 0 0 1 0 No

In [51]:

#Declaring the x and y values and dividing them what to scan and assigning yes:1 and no:0
In [52]:

x=df.iloc[:,:-1]
y=df.iloc[:,-1]
y = y.map({'Yes':1,'No':0})
print(x.head())
print(y.head())

Dry Cough High Fever Sore Throat Difficulty in breathing

0 0 2 3 0

1 15 15 20 16

2 4 5 0 0

3 4 7 9 10

4 0 0 1 0

0 0

1 1

2 0

3 0

4 0

Name: Infected with Covid19, dtype: int64

In [53]:

#importing split function and dividing the data for tarining and printing

In [54]:

from sklearn.model_selection import train_test_split


x_train,x_test,y_train,y_test = train_test_split(x,y)
print(x_train,y_train)

Dry Cough High Fever Sore Throat Difficulty in breathing

54 0 0 0 0

79 11 15 18 20

2 4 5 0 0

53 8 0 1 0

56 17 13 0 0

.. ... ... ... ...

39 14 20 16 0

0 0 2 3 0

96 9 10 11 12

6 16 17 18 16

19 7 18 12 17

[75 rows x 4 columns] 54 0

79 0

2 0

53 0

56 1

..

39 1

0 0

96 1

6 1

19 1

Name: Infected with Covid19, Length: 75, dtype: int64

In [55]:

#declaration of model

In [56]:

from sklearn.linear_model import LinearRegression


regressor = LinearRegression()
regressor.fit(x_train,y_train)

Out[56]:

LinearRegression()

In [57]:

#logic for trainiing data and output

In [58]:

y_pred = regressor.predict(x_train)
from IPython.display import display_html
y_pred=regressor.predict(x_train)
df1_styler = pd.DataFrame(y_train).style.set_table_attributes("style='display:inline'")
df2_styler = pd.DataFrame(y_pred,columns=['Predicted Outcome']).style.set_table_attributes(
display_html(df1_styler._repr_html_()+"      "+df2_styler._re

25 1 12 0.511324

14 0 13 0.183770

78 1 14 1.154846

1 1 15 0.886637

35 0 16 0.289346

52 0 17 0.259418

13 1 18 0.958570

48 0 19 0.404296

92 0 20 0.915762

77 1 21 0.993649

44 1 22 1.154846

75 1 23 0.598243

63 0 24 0.184106

In [59]:

# logic for testing data and priniting output


In [60]:

y_pred_test=regressor.predict(x_test)
df1_styler = pd.DataFrame(y_test).style.set_table_attributes("style='display:inline'")
df2_styler = pd.DataFrame(y_pred_test,columns=['Predicted Outcome']).style.set_table_attrib
display_html(df1_styler._repr_html_()+"      "+df2_styler._re

  Infected with Covid19


      
  Predicted Outcome

81 1 0 0.294705

51 0 1 0.196855

3 0 2 0.404988

70 1 3 0.864655

87 0 4 0.859742

46 0 5 0.138162

30 1 6 0.513538

33 0 7 0.252217

65 1 8 0.603228

73 0 9 0.146350

29 1 10 0.401604

9 1 11 0.958509

47 1 12 0.637389

83 0 13 0.594645

17 1 14 0.886341

37 1 15 0.648458

40 0 16 0.219208

34 1 17 0.806891

68 0 18 0.226930

67 1 19 0.606536

94 0 20 0.146350

31 0 21 0.381979

91 1 22 0.864655

95 1 23 0.372296

61 0 24 0.353026

In [61]:

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, stratify=y, rand


In [62]:

#importing logistic Regression

In [63]:

model = LogisticRegression()

In [64]:

model.fit(x_train, y_train)

Out[64]:

LogisticRegression()

In [65]:

#measuring the accuracy of training model with 80% of data

In [66]:

x_train_prediction = model.predict(x_train)
training_data_accuracy = accuracy_score(x_train_prediction, y_train)

In [67]:

#printing the accuracy

In [68]:

print('Accuracy score of the training data : ', training_data_accuracy)

Accuracy score of the training data : 0.8875

In [69]:

#measuring the accuracy of testing model with 20% of data

In [70]:

x_test_prediction = model.predict(x_test)
test_data_accuracy = accuracy_score(x_test_prediction, y_test)

In [71]:

#printing the accuracy

In [72]:

print('Accuracy score of the training data : ', training_data_accuracy)

Accuracy score of the training data : 0.8875

You might also like