-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from sdevenes/issue_29/deployment
Issue 29/deployment
- Loading branch information
Showing
27 changed files
with
340 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include LICENSE README.rst buildout.cfg requirements.txt | ||
recursive-include doc conf.py *.rst *.ico *.png | ||
graft tests/inputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ nose | |
coverage | ||
coveralls | ||
black | ||
twine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[nb_trees_experiment] | ||
nb_trees = 1, 2 | ||
tree_depth = 10 | ||
|
||
[tree_depth_experiment] | ||
nb_trees = 10 | ||
tree_depth = 1, 2 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
import argparse | ||
import os.path | ||
from rr.download_data import download_data | ||
|
||
|
||
def main(): | ||
|
||
parser = argparse.ArgumentParser( | ||
description="M05 mini-project: Download dataset.zip online" | ||
) | ||
parser.add_argument("source", type=str, help="Data zip url") | ||
parser.add_argument("destination", type=str, help="Destination folder") | ||
args = parser.parse_args() | ||
|
||
download_destination = os.path.join(args.destination + "/dataset.zip") | ||
download_data.download_url(args.source, download_destination) | ||
download_data.unzip_file(download_destination, args.destination) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sys | ||
import argparse | ||
import configparser | ||
from rr.experiment import experiments, database | ||
import os.path | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="M05 mini-project: experiments") | ||
parser.add_argument("datapath", type=str, help="Dataset file in .csv") | ||
parser.add_argument("output", type=str, help="Destination folder for the results") | ||
parser.add_argument( | ||
"config", type=str, help="Filepath for experiments configuration file in .ini" | ||
) | ||
args = parser.parse_args() | ||
|
||
config = configparser.ConfigParser() | ||
config.read(args.config) | ||
|
||
print( | ||
"M05 mini-project on Human Activity Recognition with Random Forest classifier" | ||
) | ||
tabnum = 1 | ||
experiment_results = experiments.experiment_impact_nb_trees( | ||
tabnum, | ||
filepath=args.datapath, | ||
nb_trees=[int(n) for n in config["nb_trees_experiment"]["nb_trees"].split(",")], | ||
max_depth=int(config["nb_trees_experiment"]["tree_depth"]), | ||
plot_path=args.output, | ||
) | ||
|
||
tabnum += len(config["nb_trees_experiment"]["nb_trees"].split(",")) * len( | ||
database.PROTOCOLS | ||
) | ||
experiment_results += experiments.experiment_impact_tree_depth( | ||
tabnum, | ||
filepath=args.datapath, | ||
nb_trees=int(config["tree_depth_experiment"]["nb_trees"]), | ||
max_depths=[ | ||
int(d) for d in config["tree_depth_experiment"]["tree_depth"].split(",") | ||
], | ||
plot_path=args.output, | ||
) | ||
|
||
with open(os.path.join(args.output, "experiment_results.txt"), "w+") as fout: | ||
fout.write(experiment_results) | ||
print("Experiments done\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from sklearn.ensemble import RandomForestClassifier | ||
|
||
import logging | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
class Model: | ||
def __init__(self, nb_tree_per_forest=50, max_depth=10): | ||
"""Create a new ML model (Random forest classifier from scikitlearn) | ||
Args: | ||
nb_tree_per_forest (int): number of decision trees in the forest | ||
max_depth (int): max depth of the trees | ||
Returns: | ||
None | ||
Raises: | ||
None | ||
""" | ||
self.model = RandomForestClassifier( | ||
n_estimators=nb_tree_per_forest, max_depth=max_depth, random_state=0 | ||
) | ||
|
||
def train(self, X, y): | ||
"""Train the model using the given data | ||
Args: | ||
X (numpy.ndarray):A NxM 2D-array where each row corresponds to a sample and each column to a feature | ||
y (numpy.ndarray): A 1D-array of length N, where each element corresponds to a sample label | ||
Returns: | ||
None | ||
Raises: | ||
None | ||
""" | ||
self.model.fit(X, y) | ||
|
||
def predict(self, X): | ||
"""Make a prediction on the data using the trained model | ||
Args: | ||
X (numpy.ndarray):A NxM 2D-array where each row corresponds to a sample and each column to a feature | ||
Returns: | ||
numpy.ndarray: A 1D array (with a dtype of int) containing the predicted | ||
label for each sample | ||
Raises: | ||
None | ||
""" | ||
prediction = self.model.predict(X) | ||
|
||
return prediction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/usr/bin/env python | ||
import numpy as np | ||
import csv | ||
from sklearn.model_selection import train_test_split | ||
|
Oops, something went wrong.