# -*- coding: utf-8 -*-
"""
Created on Wed Sep 25 13:57:48 2019

@author: students
"""

import numpy as np
import pandas as pd
data=pd.DataFrame(data=pd.read_csv('Book2.csv'))

concepts=np.array(data.iloc[:,0:-1])
target=np.array(data.iloc[:,-1])

def learn(concepts,target):
    specific_h=concepts[0].copy()
    general_h=[["?" for i in range(len(specific_h))]for i in range(len(specific_h))]
    
    for i,h in enumerate(concepts):
        if target[i]=="yes":
            for x in range(len(specific_h)):
                if h[x]!=specific_h[x]:
                    specific_h[x]='?'
                    general_h[x][x]='?'
                    
        if target[i]=="no":
            for x in range(len(specific_h)):
                if h[x]!=specific_h[x]:
                    general_h[x][x]=specific_h[x]
                else:
                    general_h[x][x]='?'
                    
    indices=[i for i,val in enumerate(general_h)if val==['?','?','?','?','?','?']]
    for i in indices:
        general_h.remove(['?','?','?','?','?','?'])
    return specific_h,general_h

s_final,g_final=learn(concepts,target)
print("final s:",s_final,sep="\n")
print("final g:",g_final,sep="\n")
