Fix bugs
This commit is contained in:
28
src/app.py
28
src/app.py
@@ -1,9 +1,8 @@
|
||||
from learning.data import Dataset
|
||||
from learning.supervised import LinearRegression
|
||||
from learning.ml import MLAlgorithm
|
||||
from plot import Plot
|
||||
from learning.ml import MLRegression
|
||||
|
||||
def auto_mpg() -> MLAlgorithm:
|
||||
def auto_mpg() -> MLRegression:
|
||||
df = Dataset("datasets\\auto-mpg.csv", "MPG")
|
||||
|
||||
df.to_numbers(["HP"])
|
||||
@@ -12,29 +11,22 @@ def auto_mpg() -> MLAlgorithm:
|
||||
|
||||
return LinearRegression(df, learning_rate=0.0001)
|
||||
|
||||
def automobile() -> MLAlgorithm:
|
||||
def automobile() -> MLRegression:
|
||||
df = Dataset("datasets\\regression\\automobile.csv", "symboling")
|
||||
|
||||
attributes_to_modify = ["fuel-system", "engine-type", "drive-wheels", "body-style", "make", "engine-location", "aspiration", "fuel-type", "num-of-cylinders", "num-of-doors"]
|
||||
df.factorize(attributes_to_modify)
|
||||
df.to_numbers()
|
||||
df.to_numbers(["normalized-losses", "bore", "stroke", "horsepower", "peak-rpm", "price"])
|
||||
df.handle_na()
|
||||
df.regularize(excepts=attributes_to_modify)
|
||||
|
||||
return LinearRegression(df, learning_rate=0.001)
|
||||
|
||||
|
||||
|
||||
|
||||
epoch = 50000
|
||||
skip = 1000
|
||||
lr = automobile()
|
||||
|
||||
train, test = lr.learn(epoch)
|
||||
|
||||
plot = Plot("Error", "Time", "Mean Error")
|
||||
plot.line("training", "red", data=train[skip:])
|
||||
plot.line("test", "blue", data=test[skip:])
|
||||
epoch = 15000
|
||||
ml = automobile()
|
||||
ml.learn(epoch)
|
||||
ml.plot()
|
||||
|
||||
"""
|
||||
for _ in range(0, epoch):
|
||||
@@ -45,7 +37,3 @@ for _ in range(0, epoch):
|
||||
plot.update("test", test_err)
|
||||
plot.update_limits()
|
||||
"""
|
||||
|
||||
plot.wait()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user