[go: up one dir, main page]

0% found this document useful (0 votes)
4 views2 pages

ML Code

Uploaded by

karthikpadala365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

ML Code

Uploaded by

karthikpadala365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6/20/24, 10:43 AM Untitled8 - Jupyter Notebook

In [3]: import pandas as pd


import numpy as np
data=pd.read_csv('enjoysport.csv')

In [4]: data

Out[4]:
sky airtemp humidity wind water forcast enjoysport

0 sunny warm normal strong warm same yes

1 sunny warm high strong warm same yes

2 rainy cold high strong warm change no

3 sunny warm high strong cool change yes

In [5]: fea=np.array(data)[:,:-1]

In [6]: fea

Out[6]: array([['sunny', 'warm', 'normal', 'strong', 'warm', 'same'],


['sunny', 'warm', 'high', 'strong', 'warm', 'same'],
['rainy', 'cold', 'high', 'strong', 'warm', 'change'],
['sunny', 'warm', 'high', 'strong', 'cool', 'change']],
dtype=object)

In [7]: tar=np.array(data)[:,-1]

In [8]: tar

Out[8]: array(['yes', 'yes', 'no', 'yes'], dtype=object)

In [11]: for i,val in enumerate(tar):


if val=='yes':
hypothesis=fea[i].copy()
break

In [12]: hypothesis

Out[12]: array(['sunny', 'warm', 'normal', 'strong', 'warm', 'same'], dtype=object)

In [13]: for i,val in enumerate(fea):


if tar[i]=='yes':
for x in range(len(hypothesis)):
if val[x]!=hypothesis[x]:
hypothesis[x]='?'
print(hypothesis)

['sunny' 'warm' 'normal' 'strong' 'warm' 'same']


['sunny' 'warm' '?' 'strong' 'warm' 'same']
['sunny' 'warm' '?' 'strong' '?' '?']

In [ ]: ​

localhost:8888/notebooks/Untitled8.ipynb?kernel_name=python3 1/2
6/20/24, 10:43 AM Untitled8 - Jupyter Notebook

localhost:8888/notebooks/Untitled8.ipynb?kernel_name=python3 2/2

You might also like