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 #3 from LuposX/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
LuposX authored Sep 12, 2019
2 parents ab4e50f + e740388 commit 1707d44
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

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

## 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)

Expand All @@ -51,8 +56,6 @@ $ py boston_housing_pred.py -h
* svm
* neural network

* Add saved model can be loaded

* Upload pre-trained models

## Meta
Expand Down
48 changes: 41 additions & 7 deletions boston_housing_pred.py → boston-housing-0_1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1707d44

Please sign in to comment.