diff --git a/PYPI/setup.py b/PYPI/setup.py index 73fa2e4..e30b88d 100644 --- a/PYPI/setup.py +++ b/PYPI/setup.py @@ -22,7 +22,6 @@ long_description_content_type="text/markdown", # What is in our module/scripts - # py_modules=["misc_libary", "polynomial_regression_libary", "linear_regression_libary"], scripts=["boston_housing_prediction/__main__.py"], packages=["boston_housing_prediction"], entry_points = { diff --git a/README.md b/README.md index 05482a7..502f4ce 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,15 @@ To see the help(for extra options) do: $ python -m boston_housing_prediction -h ``` - + ## Release History +* 0.2.3 + * choosing alpha is now possible + * you can leave inputs empty and it will choose default values + * bugfixes like #25 and more + * uploaded pre-trained models that can be downloaded + * 0.2.2 * fix negative input for training of model #24 * fix negative output of predictions #24 diff --git a/boston_housing_prediction/__pycache__/boston_main.cpython-36.pyc b/boston_housing_prediction/__pycache__/boston_main.cpython-36.pyc index 575e177..bd1da4a 100644 Binary files a/boston_housing_prediction/__pycache__/boston_main.cpython-36.pyc and b/boston_housing_prediction/__pycache__/boston_main.cpython-36.pyc differ diff --git a/boston_housing_prediction/__pycache__/linear_regression_libary.cpython-36.pyc b/boston_housing_prediction/__pycache__/linear_regression_libary.cpython-36.pyc index b761cfb..e0eb4af 100644 Binary files a/boston_housing_prediction/__pycache__/linear_regression_libary.cpython-36.pyc and b/boston_housing_prediction/__pycache__/linear_regression_libary.cpython-36.pyc differ diff --git a/boston_housing_prediction/__pycache__/misc_libary.cpython-36.pyc b/boston_housing_prediction/__pycache__/misc_libary.cpython-36.pyc index c82cf53..ad21e0e 100644 Binary files a/boston_housing_prediction/__pycache__/misc_libary.cpython-36.pyc and b/boston_housing_prediction/__pycache__/misc_libary.cpython-36.pyc differ diff --git a/boston_housing_prediction/__pycache__/polynomial_regression_libary.cpython-36.pyc b/boston_housing_prediction/__pycache__/polynomial_regression_libary.cpython-36.pyc index f1d557c..fe2f2f2 100644 Binary files a/boston_housing_prediction/__pycache__/polynomial_regression_libary.cpython-36.pyc and b/boston_housing_prediction/__pycache__/polynomial_regression_libary.cpython-36.pyc differ diff --git a/boston_housing_prediction/boston_main.py b/boston_housing_prediction/boston_main.py index 7f07e5a..bb23d64 100644 --- a/boston_housing_prediction/boston_main.py +++ b/boston_housing_prediction/boston_main.py @@ -31,34 +31,37 @@ def main(): # 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)", - type=bool, default=False) + type=str, default="False") # implemented parser.add_argument("--v_loss", metavar="VISUALIZE_LOSS", help="Set it to True if you want to get a visualization of the loss.(default: %(default)s)", - type=bool, default=False) + type=str, default="False") # implemented parser.add_argument("--v_model", metavar="VISUALIZE_MODEL", help="Set it to True if you want to get a visualization of the model.(default: %(default)s)", - type=bool, default=False) + type=str, default="False") parser.add_argument("--fd", metavar="FEEDBACK", help="Set how much feedback you want.(Choices: %(choices)s)", type=str, choices=["full", "intermediate", "weak", "debug"], default="immediate") # implemented parser.add_argument("--save", metavar="SAVE_MODEL", help="Set it to True if you want to save the model after training.(default: %(default)s)", - type=bool, default=False) + type=str, default="False") parser.add_argument("--h_features", metavar="HELP_FEATURES", help="Set it to True if you want to print out the meaning of the features in the dataset.(default: %(default)s)", - type=bool, default=False) + type=str, default="False") parser.add_argument("--predict_on", help="Set it to False if you dont want to predict after training.(default: %(default)s)", - action='store_false') + type=str, default="True") # parse the arguments args = parser.parse_args() + # convert our arguments from strings into booleans + parse_bool_args(args) + # check if the dataset exist if not is_non_zero_file(): download_dataset() diff --git a/boston_housing_prediction/linear_regression_libary.py b/boston_housing_prediction/linear_regression_libary.py index b543ea1..bcb5aca 100644 --- a/boston_housing_prediction/linear_regression_libary.py +++ b/boston_housing_prediction/linear_regression_libary.py @@ -10,8 +10,8 @@ def __init__(self, df, args): self.bias = 1 # how man epoch we train - self.epochs = 30 - self.alpha = 0.3 + self.epochs = 40 + self.alpha = 0.03 self.train_loss_history = [] self.test_loss_history = [] self.x_train_loose = [] @@ -29,17 +29,44 @@ def __init__(self, df, args): # training our model def train(self) -> None: + # getting the learning rate for the model while True: try: - # get input for our model - epochs = input("Please type the numbers of epoch you want to train: ") + # getting the learning rate + alpha = input("Please type the value of learning rate you want to use: ") or self.alpha + + # if default epochs value print the value + if alpha == self.alpha: + print(str(self.alpha)) + + alpha = float(alpha) + if 0 < alpha < 1: + self.alpha = alpha + break print(" ") + print("Please input a number between 0 and 1 :)") + except ValueError: + print(" ") + print("Invalid Input!") + + # get epochs for our model + while True: + try: + # get epochs for our model + epochs = input("Please type the numbers of epoch you want to train: ") or self.epochs + + # if default epochs value print the value + if epochs == self.epochs: + print(str(self.epochs)) + epochs = int(epochs) if epochs > 0: self.epochs = epochs break + print(" ") print("Please don't input negative numbers :)") except ValueError: + print(" ") print("Invalid Input!") start_time = time.time() @@ -152,7 +179,8 @@ def predic(self, visualize_process, args_normalization) -> None: sys.exit(0) # exit the script sucessful break else: - rm_input = round(float(rm_input), 20) + + rm_input = round(float(rm_input or 5), 20) # or 5 is the default value # checks that no negative numbers get entered if rm_input < 0: @@ -170,11 +198,13 @@ def predic(self, visualize_process, args_normalization) -> None: # check if predicted output is negative if denorm_pred_target < 0: print("-----------------------------------------------------------------------------") + print("Your input of RM:", str(rm_input)) print("Warning: the input values doesn't correspond to a real house.") print("-----------------------------------------------------------------------------") print(" ") else: print("-----------------------------------------------------------------------------") + print("Your input of RM:", str(rm_input)) print("Is worth about: " + str(denorm_pred_target) + " in 10,000$(GER 10.000$).") print("-----------------------------------------------------------------------------") print(" ") diff --git a/boston_housing_prediction/misc_libary.py b/boston_housing_prediction/misc_libary.py index 07653bc..0f5a71d 100644 --- a/boston_housing_prediction/misc_libary.py +++ b/boston_housing_prediction/misc_libary.py @@ -206,7 +206,7 @@ def visualize(args, df_data, parameter_list: list) -> None: # get points for line X = [] Y = [] - for i in range(-10, 14): + for i in range(5, 20): X.append(i * 0.1) Y.append(weights_bias[0] * (i * 0.1) + weights_bias[1]) @@ -288,3 +288,36 @@ def v_model_poly(x_axis, y_axis, weights_bias, data_train, target_train): # hide the grid ax.grid(False) + + +# convert our arguments from strings into booleans +def parse_bool_args(args): + if args.predict_on == "False" or args.predict_on == "false" or args.predict_on == "false ": + args.predict_on = False + if args.predict_on == "True" or args.predict_on == "true" or args.predict_on == "true ": + args.predict_on = True + + if args.h_features == "False" or args.h_features == "false" or args.h_features == "false ": + args.h_features = False + if args.h_features == "True" or args.h_features == "true" or args.h_features == "true ": + args.h_features = True + + if args.save == "False" or args.save == "false" or args.save == "false ": + args.save = False + if args.save == "True" or args.save == "true" or args.save == "true ": + args.save = True + + if args.v_model == "False" or args.v_model == "false" or args.v_model == "false ": + args.v_model = False + if args.v_model == "True" or args.v_model == "true" or args.v_model == "true ": + args.v_model = True + + if args.v_loss == "False" or args.v_loss == "false" or args.v_loss == "false ": + args.v_loss = False + if args.v_loss == "True" or args.v_loss == "true" or args.v_loss == "true ": + args.v_loss = True + + if args.v_data == "False" or args.v_data == "false" or args.v_data == "false ": + args.v_data = False + if args.v_data == "True" or args.v_data == "true" or args.v_data == "true ": + args.v_data = True diff --git a/boston_housing_prediction/polynomial_regression_libary.py b/boston_housing_prediction/polynomial_regression_libary.py index 5d6cff2..422092c 100644 --- a/boston_housing_prediction/polynomial_regression_libary.py +++ b/boston_housing_prediction/polynomial_regression_libary.py @@ -34,18 +34,44 @@ def hypothesis(self, weights, f1, f2, f3, bias): # training our model def train(self) -> None: + # getting the learning rate for the model + while True: + try: + # getting the learning rate + alpha = input("Please type the value of learning rate you want to use: ") or self.alpha + + # if default epochs value print the value + if alpha == self.alpha: + print(str(self.alpha)) + + alpha = float(alpha) + if 0 < alpha < 1: + self.alpha = alpha + break + print(" ") + print("Please input a number between 0 and 1 :)") + except ValueError: + print(" ") + print("Invalid Input!") + # exits while loop when right inputs got inserted while True: try: # get input for our model - epochs = input("Please type the numbers of epoch you want to train: ") - print(" ") + epochs = input("Please type the numbers of epoch you want to train: ") or self.epochs + + # if default epochs value print the value + if epochs == self.epochs: + print(str(self.epochs)) + epochs = int(epochs) if epochs > 0: self.epochs = epochs break + print(" ") print("Please don't input negative numbers :)") except ValueError: + print(" ") print("Invalid Input!") start_time = time.time() # start timer. To later calculate time needed to train the model @@ -173,10 +199,11 @@ def predic(self, visualize_process, args_normalization) -> None: print("Type the Values in the following order: ") print("1.RM 2.LSTAT 3.PTRATIO") input_list = [] + default_values = [6.24, 12.94, 18.52] # those are the default values when field is left empty. default values corrospond to mean values of feature for i in range(0,3,1): # exits while loop when right inputs got inserted while True: - input_var = input() + input_var = input() or default_values[i] if input_var == "quit" or input_var == "Quit": if visualize_process.is_alive(): @@ -210,7 +237,7 @@ def predic(self, visualize_process, args_normalization) -> None: print(" ") # typecasting our inputs and rounding them - rm_input = round(float(input_list[0]), 4) + rm_input = round(float(input_list[0]), 4) # or 5 is the default value lstat_input = round(float(input_list[1]), 4) ptratio_input = round(float(input_list[2]), 4) @@ -225,21 +252,24 @@ def predic(self, visualize_process, args_normalization) -> None: # denormalization of output denorm_pred_target = round((self.pred_target * df_range[3]) + df_mean[3], 6) - print(" ") - print("The model predicted that a house with the values: ") - print("RM :" + str(rm_input)) - print("LSTAT :" + str(lstat_input)) - print("PTRATIO :" + str(ptratio_input)) - print(" ") - # check if predicted output is negative if denorm_pred_target < 0: + print(" ") print("-----------------------------------------------------------------------------") + print("The model predicted that a house with the values: ") + print("RM :" + str(rm_input)) + print("LSTAT :" + str(lstat_input)) + print("PTRATIO :" + str(ptratio_input)) print("Warning: the input values doesn't correspond to a real house.") print("-----------------------------------------------------------------------------") print(" ") else: + print(" ") print("-----------------------------------------------------------------------------") + print("The model predicted that a house with the values: ") + print("RM :" + str(rm_input)) + print("LSTAT :" + str(lstat_input)) + print("PTRATIO :" + str(ptratio_input)) print("Is worth about: " + str(denorm_pred_target) + " in 10,000$(GER 10.000$).") print("-----------------------------------------------------------------------------") print(" ") diff --git a/pre_trained_models/linear_regression_housing_weights.csv b/pre_trained_models/linear_regression_housing_weights.csv new file mode 100644 index 0000000..481b752 --- /dev/null +++ b/pre_trained_models/linear_regression_housing_weights.csv @@ -0,0 +1,3 @@ +weight_bias +0.9122710219927018 +-0.7175949851060076 diff --git a/pre_trained_models/polynomial_regression_housing_weights.txt b/pre_trained_models/polynomial_regression_housing_weights.txt new file mode 100644 index 0000000..955f52c --- /dev/null +++ b/pre_trained_models/polynomial_regression_housing_weights.txt @@ -0,0 +1,10 @@ +0.3577673944247428 +0.7155347888494856 +0.3385774036005275 +-0.3423671694707663 +-0.6847343389415326 +0.3385774036005275 +-0.36920267917045946 +-0.7384053583409189 +0.3719308583089693 +0.05344934752623586 diff --git a/testing_linear.txt b/testing_linear.txt index 6895185..2df9248 100644 --- a/testing_linear.txt +++ b/testing_linear.txt @@ -1,5 +1,7 @@ -50 +0.03 +100 +4.5 7 3 --5 +20 quit diff --git a/testing_polynomial.txt b/testing_polynomial.txt index f820e52..3626cf9 100644 --- a/testing_polynomial.txt +++ b/testing_polynomial.txt @@ -1,6 +1,6 @@ 0.03 100 +4.5 7 3 -20 quit