diff --git a/.travis.yml b/.travis.yml index 65843fc..97730fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ install: - pip install -r requirements.txt # command to run tests script: - - python boston_housing_pred.py linear_regression < testing.txt + - python boston-housing-0_1_1.py linear_regression < testing.txt diff --git a/README.md b/README.md index 70ec709..00142f6 100644 --- a/README.md +++ b/README.md @@ -17,30 +17,35 @@ To install the `requirements` for the script do: ```sh $ pip install -r requirements.txt ``` -Download the script `boston_housing_pred.py`. +Download the script `boston-housing-0_1_1.py`. ## Usage example You can run the programm with: ```sh -$ py boston_housing_pred.py linear_regression +$ py boston-housing-0_1_1.py linear_regression ``` To see the help(for extra options) do: ```sh -$ py boston_housing_pred.py -h +$ py boston-housing-0_1_1.py -h ``` ## Release History +* 0.1.1 + * added functionality to load models without training + * plots are now outsourced and handled by a different kernel + * dataset gets automatically downloaded when missing + * v_data shows 4 different plots to describe the data(previously 2). + * 0.1.0 * The first proper release * Realese of readme (Thanks @dbader) - - + * 0.0.1 - * Work in progress + * Work in progress ## Roadmap (planned updates) @@ -51,8 +56,6 @@ $ py boston_housing_pred.py -h * svm * neural network -* Add saved model can be loaded - * Upload pre-trained models ## Meta diff --git a/boston_housing_pred.py b/boston-housing-0_1_1.py similarity index 92% rename from boston_housing_pred.py rename to boston-housing-0_1_1.py index 25f20b8..2a637a8 100644 --- a/boston_housing_pred.py +++ b/boston-housing-0_1_1.py @@ -3,6 +3,7 @@ Started: 08.09.2019 Lang: Phyton Description: Prediction of boston housing market with lienar - regression. +version: 0.1.1 Dataset: Housing Values in Suburbs of Boston @@ -26,6 +27,7 @@ import pandas as pd import seaborn as sns import urllib +import operator # TODO: fix train and test loss # TODO: add verify verify a single preictions @@ -62,6 +64,10 @@ def get_Data() -> object: checker_dataset_exist = False +# used to remove trailing whitespace from file +def chomped_lines(it): + return map(operator.methodcaller('rstrip', '\r\n'), it) + # visualize data def visualize_Data(df: object) -> None: """ @@ -163,17 +169,24 @@ def visualize(args, df_data, parameter_list: list) -> None: x_train_loose = parameter_list[7] # prints Mean loss of last epoch - print(" ") - print("Mean-train loss of last epoch: ", str(round(train_loss_history[-1], 6))) - print("Mean-test loss of last epoch: ", str(round(test_loss_history[-1], 6))) - print("Time needed for training: ", str(round(evaluation_time, 4)) + "s.") + if not args.infile: + print(" ") + print("Mean-train loss of last epoch: ", str(round(train_loss_history[-1], 6))) + print("Mean-test loss of last epoch: ", str(round(test_loss_history[-1], 6))) + print("Time needed for training: ", str(round(evaluation_time, 4)) + "s.") # communication is key - if args.fd == "intermediate" or args.fd == "full": + if (args.fd == "intermediate" or args.fd == "full") and not args.infile: print(" ") print("Value of W1 after training: ", w1) print("Value of Bias after training: ", bias) print(" ") + elif args.infile: + print(" ") + print("Value of W1: ", w1) + print("Value of Bias: ", bias) + print(" ") + if args.v_data: visualize_Data(df_data) @@ -375,7 +388,7 @@ def getter_viszualtion(self) -> list: type=str, choices=["linear_regression", "polynomial_regression"]) parser.add_argument("--infile", help="If file specified model will load weights from it." "Else it will normally train.(default: no file loaded)" - , metavar="FILE", type=argparse.FileType('r', encoding='UTF-8')) + , metavar="FILE", type=str) # type=argparse.FileType('r', encoding='UTF-8') # implemented parser.add_argument("--v_data", metavar="VISUALIZE_DATA", help="Set it to True if you want to get a visualization of the data.(default: %(default)s)", @@ -416,7 +429,28 @@ def getter_viszualtion(self) -> list: print("--------------------------------------") model = LinearRegression(preproc_data(df_data)) # create our model - model.train() # train our model + + if not args.infile: + model.train() # train our model + else: + try: + filename = str(args.infile) + file_list = [] + with open(filename, "r") as infile: + for line in chomped_lines(infile): + file_list.append(line) + except FileNotFoundError as e: + print("Errot file not found: ", str(e)) + if visualize_process.is_alive(): + visualize_process.terminate() + sys.exit(1) # exit the script sucessful + + try: + model.w1 = float(file_list[1]) + model.bias = float(file_list[2]) + except ValueError as e: + print(str(e)) + # if save parameter is true model gets saved if args.save: