You are on page 1of 3

1 /22/2020 LAB4.

ipynb - Colaboratory

Muhammad Salman
ee171057
EE-7B

from google.colab import files

uploaded=files.upload()

Choose Files pakcases.csv


pakcases.csv (application/vnd.ms-excel) - 3327 bytes, last modified: 11/22/2020 - 100% done
Saving pakcases.csv to pakcases (3).csv

import pandas as pd
import io
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

df = pd.read_csv(io.StringIO(uploaded['pakcases.csv'].decode('utf-8')))
print(df)

days cases
0 1 0
1 2 0
2 3 0
3 4 0
4 5 0
.. ... ...
323 324 361082
324 325 363380
325 326 365927
326 327 368665
327 328 371508

[328 rows x 2 columns]

r = np.corrcoef(x, y)
r

array([[1. , 0.94864826],
[0.94864826, 1. ]])

x = df.days.values.astype('float')
y = df.cases.values
plt.scatter(x,y)

https://colab.research.google.com/drive/1sF06nSIzND7Y6n3djMCZvs3Cq_0ZzIPd#scrollTo=WxYGcHeqsmlY&printMode=true 1/3
1 /22/2020 LAB4.ipynb - Colaboratory

<matplotlib.collections.PathCollection at 0x7f3b45143240>

def sigmoid(X, Beta_1, Beta_2):


""" This method performs the sigmoid function on param X and
Returns the outcome as a varible called y"""
y = 1 / (1 + np.exp(-Beta_1*(X-Beta_2)))
return y

x_norm = x/max(x) # Normalized to 0 and 1


y_norm = y/max(y)

popt, pcov = curve_fit(sigmoid, x_norm, y_norm)


beta_1,beta_2 = popt # (popt[0],popt[1])
beta_1,beta_2

(10.483386765820818, 0.572733909217535)

y_new = sigmoid(x_norm, beta_1, beta_2)


plt.plot(x, y_norm,'o', x, y_new)
plt.xlabel("Years")
plt.ylabel("GDP (10 Trillions)")
plt.show()

sum_of_diff["Sigmoid"] = np.linalg.norm(y_norm-y_new)**2

https://colab.research.google.com/drive/1sF06nSIzND7Y6n3djMCZvs3Cq_0ZzIPd#scrollTo=WxYGcHeqsmlY&printMode=true 2/3
1 /22/2020 LAB4.ipynb - Colaboratory

https://colab.research.google.com/drive/1sF06nSIzND7Y6n3djMCZvs3Cq_0ZzIPd#scrollTo=WxYGcHeqsmlY&printMode=true 3/3

You might also like