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

6/22/23, 7:41 PM Untitled1.

ipynb - Colaboratory

# Roll No: 55
Experi ment No: 3

import numpy as np
import matplotlib.pyplot as plt
import random

numberoffaces: [1, 2, 3, 4, 5, 6]

dice=[x for x in range (1,5)]


print (random.randint(1,3))
print (random.randint (1,3))

3
1

a=int(input ("enter the number"))


dice=[x for x in range(1,7)]
print("number of faces :",dice)

enter the number4


number of faces : [1, 2, 3, 4, 5, 6]

Colab paid products - Cancel contracts here

check 2s completed at 7:39 PM

https://colab.research.google.com/drive/1kyunlO-tYDg2aJVaQxeNfpR-7YYD8ysH#scrollTo=OklDJ2CbbxjO&printMode=true 1/1
Roll No: 55 Experiment No: 4 SLRegression.ipynb - Colaboratory

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random

data = pd.read_csv('/content/1. Simple linear regression.csv')

data.head()

SAT GPA

0 1714 2.40

1 1664 2.52

2 1760 2.54

3 1685 2.74

4 1693 2.83

data.describe()

SAT GPA

count 84.000000 84.000000

mean 1845.273810 3.330238

std 104.530661 0.271617

min 1634.000000 2.400000

25% 1772.000000 3.190000

50% 1846.000000 3.380000

75% 1934.000000 3.502500

max 2050.000000 3.810000

x = data['SAT']
y = data['GPA']

plt.scatter(x, y)

plt.xlabel("SAT" , fontsize='12')
plt.ylabel("GPA" , fontsize='12')

Text(0, 0.5, 'GPA')

plt.scatter(x, y)
yhat = 0.2750+0.0017*x
fig = plt.plot(x,yhat,lw=4,color='red',label='regressionline')
upper = 0.2750+0.409+0.0017*x
fig = plt.plot(x,upper,lw=4,color='green',label='upperline')
lower = 0.2750-0.409+0.0017*x

1/2
fig = plt.plot(x,lower,lw=4,color='orange',label='lowerline')
plt.show()

C l b id d t C l t t h
check 0s completed at 11:53 AM

2/2
6/22/23,
Roll 4:49
No: PM
55 Expariment No: 5

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random
import statsmodels.api as sm
import seaborn as sns
sns.set()

data = pd.read_csv('/content/2. Multiple linear regression.csv')

data.head()

SAT GPA Rand 1,2,3

0 1714 2.40 1

1 1664 2.52 3

2 1760 2.54 3

3 1685 2.74 3

4 1693 2.83 2

data.describe()

SAT GPA Rand 1,2,3

count 84.000000 84.000000 84.000000

mean 1845.273810 3.330238 2.059524

std 104.530661 0.271617 0.855192

min 1634.000000 2.400000 1.000000

25% 1772.000000 3.190000 1.000000

50% 1846.000000 3.380000 2.000000

75% 1934.000000 3.502500 3.000000

max 2050.000000 3.810000 3.000000

y = data['GPA']
x1 = data[['SAT', 'Rand 1,2,3']]

x = sm.add_constant(x1)

results = sm.OLS(y,x).fit()
results.summary()

OLS Regression Results


Dep. Variable: GPA R-squared: 0.407
Model: OLS Adj. R-squared: 0.392
Method: Least Squares F-statistic: 27.76
Date: Wed, 21 Jun 2023 Prob (F-statistic): 6.58e-10
Time: 08:18:25 Log-Likelihood: 12.720
No. Observations: 84 AIC: -19.44
Df Residuals: 81 BIC: -12.15
Df Model: 2
Covariance Type: nonrobust
coef std err t P>|t| [0.025 0.975]
const 0.2960 0.417 0.710 0.480 -0.533 1.125
SAT 0.0017 0.000 7.432 0.000 0.001 0.002
Rand 1,2,3 -0.0083 0.027 -0.304 0.762 -0.062 0.046
Omnibus: 12.992 Durbin-Watson: 0.948
Prob(Omnibus): 0.002 Jarque-Bera (JB): 16.364
Skew: -0.731 Prob(JB): 0.000280
Kurtosis: 4.594 Cond. No. 3.33e+04

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 3.33e+04. This might indicate that there are
strong multicollinearity or other numerical problems.

https://colab.research.google.com/drive/1kC3G6ssnRYtpOU39gbNii3eJJsKQAh4m#printMode=true 1/2
6/22/23, 7:24 PM naive_bayesian.ipynb - Colaboratory

Roll No:No:
Roll 55 53 Expariment No:6

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random
%matplotlib inline

df = pd.read_csv('/content/win.data.csv')
df.head(10)

Malic Alcalinity Total Nonflavano


Class Alcohol Ash Magnesium Flavanoids
acid of ash phenols pheno

0 1 14.23 1.71 2.43 15.6 127 2.80 3.06 0

1 1 13.20 1.78 2.14 11.2 100 2.65 2.76 0

2 1 13.16 2.36 2.67 18.6 101 2.80 3.24 0

3 1 14.37 1.95 2.50 16.8 113 3.85 3.49 0

4 1 13.24 2.59 2.87 21.0 118 2.80 2.69 0

5 1 14.20 1.76 2.45 15.2 112 3.27 3.39 0

6 1 14.39 1.87 2.45 14.6 96 2.50 2.52 0

7 1 14.06 2.15 2.61 17.6 121 2.60 2.51 0

8 1 14.83 1.64 2.17 14.0 97 2.80 2.98 0

df.iloc[:,1:].describe()

Malic Alcalinity Total Nonflavanoid Color


Alcohol Ash Magnesium Flavanoids Proanthocyanins
acid of ash phenols phenols intensity

count 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 178.000000 1

mean 13.000618 2.336348 2.366517 19.494944 99.741573 2.295112 2.029270 0.361854 1.590899 5.058090

std 0.811827 1.117146 0.274344 3.339564 14.282484 0.625851 0.998859 0.124453 0.572359 2.318286

min 11.030000 0.740000 1.360000 10.600000 70.000000 0.980000 0.340000 0.130000 0.410000 1.280000

25% 12.362500 1.602500 2.210000 17.200000 88.000000 1.742500 1.205000 0.270000 1.250000 3.220000

50% 13.050000 1.865000 2.360000 19.500000 98.000000 2.355000 2.135000 0.340000 1.555000 4.690000

75% 13.677500 3.082500 2.557500 21.500000 107.000000 2.800000 2.875000 0.437500 1.950000 6.200000

for c in df.columns[1:]:
df.boxplot(c,by='Class',figsize=(7,4),fontsize=14)
plt.title("{}\n".format(4),fontsize=16)
plt.xlabel("Win Class",fontsize=16)

https://colab.research.google.com/drive/1dkOy-wLSzc9Ir2q80GfGFTYZ1wsDX1Ly#printMode=true 1/2
6/22/23, 7:24 PM naive_bayesian.ipynb - Colaboratory

https://colab.research.google.com/drive/1dkOy-wLSzc9Ir2q80GfGFTYZ1wsDX1Ly#printMode=true 2/2
7. logistic linear regression
Roll No: 55

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random
import seaborn as sns
%matplotlib inline

train=pd.read_csv('/titanic_train.csv')
train.head()

PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket F

Braund,
A/5
0 1 0 3 Mr. Owen male 22.0 1 0 7.2
21171
Harris

Cumings,
Mrs. John
Bradley
1 2 1 1 female 38.0 1 0 PC 17599 71.2
(Florence
Briggs
Th...

t = train.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 PassengerId 891 non-null int64
1 Survived 891 non-null int64
2 Pclass 891 non-null int64
3 Name 891 non-null object
4 Sex 891 non-null object
5 Age 714 non-null float64
6 SibSp 891 non-null int64
7 Parch 891 non-null int64
8 Ticket 891 non-null object
9 Fare 891 non-null float64
10 Cabin 204 non-null object
11 Embarked 889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.7+ KB

d = train.describe()
d

PassengerId Survived Pclass Age SibSp Parch Fare

count 891.000000 891.000000 891.000000 714.000000 891.000000 891.000000 891.000000

mean 446.000000 0.383838 2.308642 29.699118 0.523008 0.381594 32.204208

std 257.353842 0.486592 0.836071 14.526497 1.102743 0.806057 49.693429

min 1.000000 0.000000 1.000000 0.420000 0.000000 0.000000 0.000000

25% 223.500000 0.000000 2.000000 20.125000 0.000000 0.000000 7.910400

50% 446.000000 0.000000 3.000000 28.000000 0.000000 0.000000 14.454200

75% 668.500000 1.000000 3.000000 38.000000 1.000000 0.000000 31.000000

max 891.000000 1.000000 3.000000 80.000000 8.000000 6.000000 512.329200

sns.set_theme(style="whitegrid")
sns.countplot(data=train, x="Pclass", hue="Survived")

https://colab.research.google.com/drive/14ygyKPkF4r30_0ItyWbDq49Ajt_rl6SP#scrollTo=y1PvLZqxq3Fa&printMode=true 1/2
<Axes: xlabel='Pclass', ylabel='count'>

sns.barplot(data=train, x="Survived", y="Age" , hue="Sex")

<Axes: xlabel='Survived', ylabel='Age'>

Colab paid products - Cancel contracts here

check 1s completed at 4:09 PM

https://colab.research.google.com/drive/14ygyKPkF4r30_0ItyWbDq49Ajt_rl6SP#scrollTo=y1PvLZqxq3Fa&printMode=true 2/2
6/22/23, 7:27 PM BayesianNetwork.ipynb - Colaboratory
Roll No: 55 Experiment No: 8

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random
import seaborn as sns
%matplotlib inline
from sklearn.model_selection import train_test_split

disease=pd.read_csv('/content/heart.csv')
disease.head()

age sex cp trestbps chol fbs restecg thalach exang oldpeak slope ca thal target

0 52 1 0 125 212 0 1 168 0 1.0 2 2 3 0

1 53 1 0 140 203 1 0 155 1 3.1 0 0 3 0

2 70 1 0 145 174 0 1 125 1 2.6 0 0 3 0

3 61 1 0 148 203 0 1 161 0 0.0 2 1 3 0

4 62 0 0 138 294 1 1 106 0 1.9 1 3 2 0

i=disease.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1025 entries, 0 to 1024
Data columns (total 14 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 age 1025 non-null int64
1 sex 1025 non-null int64
2 cp 1025 non-null int64
3 trestbps 1025 non-null int64
4 chol 1025 non-null int64
5 fbs 1025 non-null int64
6 restecg 1025 non-null int64
7 thalach 1025 non-null int64
8 exang 1025 non-null int64
9 oldpeak 1025 non-null float64
10 slope 1025 non-null int64
11 ca 1025 non-null int64
12 thal 1025 non-null int64
13 target 1025 non-null int64
dtypes: float64(1), int64(13)
memory usage: 112.2 KB

d=disease.describe()
d

age sex cp trestbps chol fbs

count 1025.000000 1025.000000 1025.000000 1025.000000 1025.00000 1025.000000 102

mean 54.434146 0.695610 0.942439 131.611707 246.00000 0.149268

std 9.072290 0.460373 1.029641 17.516718 51.59251 0.356527

min 29.000000 0.000000 0.000000 94.000000 126.00000 0.000000

25% 48.000000 0.000000 0.000000 120.000000 211.00000 0.000000

50% 56.000000 1.000000 1.000000 130.000000 240.00000 0.000000

75% 61.000000 1.000000 2.000000 140.000000 275.00000 0.000000

max 77.000000 1.000000 3.000000 200.000000 564.00000 1.000000

disease_train, disease_test = train_test_split(disease, test_size=0.2, random_state=100)


print(disease_train.shape, disease_test.shape)

(820, 14) (205, 14)

https://colab.research.google.com/drive/1NAULNc0bfJT-diKW29wMAO_hG5FthhJr#printMode=true 1/2

You might also like