コード例 #1
0
ファイル: SciKit.py プロジェクト: jareie/Connect4T
def CrossValidation(typeOfAutomata):
    datasets = DataUtil.GenerateKFoldSet(dataPath + trainPl, dataPath + testPl)
    results = []
    for sets in datasets:
        print("Making for new set")
        tm = GetLearningAutomata(typeOfAutomata)
        result = 0.0
        TrainX = []
        TrainY = []
        for i in sets[0]:
            TrainX.append(i[0])
            TrainY.append(i[1])

        TestX = []
        TestY = []
        for i in sets[1]:
            TestX.append(i[0])
            TestY.append(i[1])

        TrainX = np.array(TsUtil.ReshapeData(TrainX, False))
        TrainY = np.array(TrainY)

        TestX = np.array(TsUtil.ReshapeData(TestX, False))
        TestY = np.array(TestY)
        inbetweenResults = []

        tm.fit(TrainX, TrainY)
        #result = 100*(tm.predict(np.array(TsUtil.ReshapeData(TestX, False))) == np.array(TestY)).mean()
        result = tm.score(TestX, TestY) * 100
        inbetweenResults.append(result)
        print(" " + str(result))
        results.append(inbetweenResults)
    return results
コード例 #2
0
ファイル: Connect4.py プロジェクト: jareie/Connect4T
def CrossValidation():
    datasets = DataUtil.GenerateKFoldSet(dataPath + trainPl,dataPath + testPl)
    results = []
    for sets in datasets:
        print("Making Tsetlin Machine for new set")
        def GetMachine():
            if convolutional:
                return TM(clauses, T, s, (WindowX, WindowY), weighted_clauses=True, boost_true_positive_feedback=0)
            else:
                return TM(clauses, T, s, weighted_clauses=True, boost_true_positive_feedback=0)
        
        tm = GetMachine()
        result = 0.0
        TrainX = []
        TrainY = []
        for i in sets[0]:
            TrainX.append(i[0])
            TrainY.append(i[1])

        TestX = []
        TestY = []
        for i in sets[1]:
            TestX.append(i[0])
            TestY.append(i[1])
        
        inbetweenResults = []
        for i in range(epochs):
            tm.fit(np.array(TsUtil.ReshapeData(TrainX, convolutional)),np.array(TrainY),epochs=1,incremental=True)
            result = 100*(tm.predict(np.array(TsUtil.ReshapeData(TestX, convolutional))) == np.array(TestY)).mean()
            inbetweenResults.append(result)
            print(" " + str(result))
        results.append(inbetweenResults)
    return results