Skip to content

Commit

Permalink
just misc
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmshane committed Dec 2, 2024
1 parent fc98581 commit 1de1cf1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions theProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

SMALL_DATA = Path("small-test-dataset.txt")
BIG_DATA = Path("large-test-dataset.txt")
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)


class Data:
Expand All @@ -47,9 +47,8 @@ def loadTestData(self,testSet=SMALL_DATA): # SMALL_DATA or BIG_DATA
logging.info(f"Data Successfully Loaded into Matrix of Size {data.shape}")

def loadFeatureList(self,featureList):
featureList=np.array(featureList) - 1 #Label col removed -> shift left 1
self.featureList=featureList
logging.info(f"Data Successfully Loaded {featureList}!")
self.featureList = (np.array(featureList) - 1) #Label col removed -> shift left 1
logging.info(f"Feature List Successfully Loaded {featureList}!")

class Classifier: # Calculates distance between every point for NN
data = Data()
Expand All @@ -59,7 +58,7 @@ def train(self,data, kNN = 1):
self.data = data
self.kNN = kNN

def test(self,testIndex : int,output = True) -> int:
def test(self,testIndex : int) -> int:
distList = [] #Heap (Dist to testIndex, Index)
for R in range(len(self.data.features)):
if R == testIndex: continue
Expand All @@ -69,7 +68,7 @@ def test(self,testIndex : int,output = True) -> int:
_ ,index = heapq.heappop(distList)
counter[self.data.labels[index]] += 1
guess = counter.most_common(1)[0][0]
if output: logging.info(f"Index {testIndex} Classifier Test | Guess/Actual: {guess}/{self.data.labels[testIndex]}")
logging.debug(f"Index {testIndex} Classifier Test | Guess/Actual: {guess}/{self.data.labels[testIndex]}")
return guess


Expand Down Expand Up @@ -160,7 +159,7 @@ def backwardElimination(self)->list:
if self.featureList[i] not in currentFeatures: continue
currentFeatures.remove(self.featureList[i])
eval = self.evaluate()
logging.info(f"Evaluated {currentFeatures} at {eval} ")
logging.debug(f"Evaluated {currentFeatures} at {eval} ")

if eval > bestChildAccuracy[0]:
bestChildAccuracy = (eval, i)
Expand Down Expand Up @@ -243,7 +242,5 @@ def printFeatureChange(featureChanged,currentFeatures,accuracy,add=True):

feet = FeatureSearch(featureCount)
algPick = Printer.featureAlgPrompt(feet)

dadi.loadFeatureList(featureList)
classi.train(dadi)
vally.evaluate(dadi, classi, [3, 5, 7])

0 comments on commit 1de1cf1

Please sign in to comment.