- fix bug recursion on init
- fix bug linux path
- added regularization
This commit is contained in:
2024-05-02 14:27:57 +02:00
parent 3a4e07afc8
commit 3e9bcb87e9
3 changed files with 31 additions and 11 deletions

View File

@@ -3,8 +3,12 @@ from learning.supervised import LinearRegression, LogisticRegression, MultiLayer
from learning.ml import MLAlgorithm
from typing import Callable
DATASET = "datasets/"
REGRESSION = DATASET + "regression/"
CLASSIFICATION = DATASET + "classification/"
def auto_mpg() -> tuple[int, MLAlgorithm]:
ds = Dataset("datasets\\auto-mpg.csv", "MPG", TargetType.Regression)
ds = Dataset(REGRESSION + "auto-mpg.csv", "MPG", TargetType.Regression)
ds.numbers(["HP"])
ds.handle_na()
@@ -12,7 +16,7 @@ def auto_mpg() -> tuple[int, MLAlgorithm]:
return (1000, LinearRegression(ds, learning_rate=0.0001))
def automobile() -> tuple[int, MLAlgorithm]:
ds = Dataset("datasets\\regression\\automobile.csv", "symboling", TargetType.Regression)
ds = Dataset(REGRESSION + "automobile.csv", "symboling", TargetType.Regression)
attributes_to_modify = ["fuel-system", "engine-type", "drive-wheels", "body-style", "make", "engine-location", "aspiration", "fuel-type", "num-of-cylinders", "num-of-doors"]
ds.factorize(attributes_to_modify)
@@ -22,19 +26,19 @@ def automobile() -> tuple[int, MLAlgorithm]:
return (1000, LinearRegression(ds, learning_rate=0.004))
def power_plant() -> tuple[int, MLAlgorithm]:
ds = Dataset("datasets\\regression\\power-plant.csv", "energy-output", TargetType.Regression)
ds = Dataset(REGRESSION + "power-plant.csv", "energy-output", TargetType.Regression)
ds.normalize()
return (80, LinearRegression(ds, learning_rate=0.1))
def electrical_grid() -> tuple[int, MLAlgorithm]:
ds = Dataset("datasets\\classification\\electrical_grid.csv", "stabf", TargetType.Classification)
ds = Dataset(CLASSIFICATION + "electrical_grid.csv", "stabf", TargetType.Classification)
ds.factorize(["stabf"])
ds.normalize()
return (1000, LogisticRegression(ds, learning_rate=0.08))
def frogs() -> tuple[int, MLAlgorithm]:
ds = Dataset("datasets\\classification\\frogs.csv", "Species", TargetType.MultiClassification)
ds = Dataset(CLASSIFICATION + "frogs.csv", "Species", TargetType.MultiClassification)
ds.remove(["Family", "Genus", "RecordID"])
ds.factorize(["Species"])
return (1000, MultiLayerPerceptron(ds, learning_rate=0.08))
@@ -55,5 +59,5 @@ def learn_dataset(function:Callable[..., tuple[int, MLAlgorithm]], epochs:int=10
return ml
if __name__ == "__main__":
ml = learn_dataset(automobile)
ml = learn_dataset(electrical_grid)
print(ml.accuracy(ml.testset))