﻿

# ml2

Dec 3rd, 2020
418
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. import numpy as np
3. import pandas as pd
5. concepts = np.array(data.iloc[:,0:-1])
6. print(concepts)
7. target = np.array(data.iloc[:,-1])
8. print(target)
9.
10.
11. def learn(concepts, target):
12.     specific_h = concepts[0].copy()
13.     print("initialization of specific_h and general_h")
14.     print(specific_h)
15.     general_h = [["?" for i in range(len(specific_h))] for i in range(len(specific_h))]
16.     print(general_h)
17.     for i, h in enumerate(concepts):
18.         if target[i] == "yes":
19.             for x in range(len(specific_h)):
20.                 if h[x]!= specific_h[x]:
21.                     specific_h[x] ='?'
22.                     general_h[x][x] ='?'
23.                 print(specific_h)
24.         print(specific_h)
25.         if target[i] == "no":
26.             for x in range(len(specific_h)):
27.                 if h[x]!= specific_h[x]:
28.                     general_h[x][x] = specific_h[x]
29.                 else:
30.                     general_h[x][x] = '?'
31.         print(" steps of Candidate Elimination Algorithm",i+1)
32.         print(specific_h)
33.         print(general_h)
34.     indices = [i for i, val in enumerate(general_h) if val == ['?', '?', '?', '?', '?', '?']]
35.     for i in indices:
36.         general_h.remove(['?', '?', '?', '?', '?', '?'])
37.     return specific_h, general_h
38. s_final, g_final = learn(concepts, target)
39. print("Final Specific_h:", s_final, sep="\n")
40. print("Final General_h:", g_final, sep="\n")
41.
42.
RAW Paste Data