Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from LuposX/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
LuposX authored Sep 29, 2019
2 parents fe43bf7 + 6075d1f commit 73382f0
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 28 deletions.
1 change: 0 additions & 1 deletion PYPI/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ To see the help(for extra options) do:
$ python -m boston_housing_prediction -h
```

<!--_For more examples and usage, please refer to the [Wiki][wiki]._-->
<!--__For more examples and usage, please refer to the [Wiki][wiki]._-->

## 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
Expand Down
Binary file modified boston_housing_prediction/__pycache__/boston_main.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file modified boston_housing_prediction/__pycache__/misc_libary.cpython-36.pyc
Binary file not shown.
Binary file not shown.
15 changes: 9 additions & 6 deletions boston_housing_prediction/boston_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
40 changes: 35 additions & 5 deletions boston_housing_prediction/linear_regression_libary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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(" ")
Expand Down
35 changes: 34 additions & 1 deletion boston_housing_prediction/misc_libary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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
52 changes: 41 additions & 11 deletions boston_housing_prediction/polynomial_regression_libary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)

Expand All @@ -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(" ")
Expand Down
3 changes: 3 additions & 0 deletions pre_trained_models/linear_regression_housing_weights.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
weight_bias
0.9122710219927018
-0.7175949851060076
10 changes: 10 additions & 0 deletions pre_trained_models/polynomial_regression_housing_weights.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0.3577673944247428
0.7155347888494856
0.3385774036005275
-0.3423671694707663
-0.6847343389415326
0.3385774036005275
-0.36920267917045946
-0.7384053583409189
0.3719308583089693
0.05344934752623586
6 changes: 4 additions & 2 deletions testing_linear.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
50
0.03
100
4.5
7
3
-5
20
quit
2 changes: 1 addition & 1 deletion testing_polynomial.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
0.03
100
4.5
7
3
20
quit

0 comments on commit 73382f0

Please sign in to comment.