aboutsummaryrefslogtreecommitdiff
path: root/src/cli.py
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-23 19:11:47 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-23 19:11:47 +0100
commit8902768c980aec4d2c0ae63cecfb5de24bb573f6 (patch)
tree6989d0b2a10e3b032a4e88ac1ae2c210f75b8f2c /src/cli.py
parentb21e6642c591962974212be2dbc965793df6bd06 (diff)
downloadft_linear_regression-8902768c980aec4d2c0ae63cecfb5de24bb573f6.tar.gz
ft_linear_regression-8902768c980aec4d2c0ae63cecfb5de24bb573f6.tar.bz2
ft_linear_regression-8902768c980aec4d2c0ae63cecfb5de24bb573f6.zip
Normalized x prediction to actualy predict something
Diffstat (limited to 'src/cli.py')
-rwxr-xr-x[-rw-r--r--]src/cli.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/cli.py b/src/cli.py
index ce759be..0c45e7a 100644..100755
--- a/src/cli.py
+++ b/src/cli.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3.7
+
import sys
import argparse
@@ -13,25 +15,25 @@ class CommandLineInterface:
prog="ft_linear_regression_cli",
description="CLI to interact with the ft_linear_regression project"
)
- subparsers = parser.add_subparsers(help="sub-command help", dest="subparser_name")
-
+ subparsers = parser.add_subparsers(dest="subparser_name")
parser_train = subparsers.add_parser("train", help="train the model")
parser_train.set_defaults(func=self._train)
- parser_train.add_argument("-a --alpha", type=float, default=1.0, dest="alpha", help="learning rate")
- parser_train.add_argument("-e --epoch", type=int, default=100, dest="epoch", help="number of iterations")
-
+ parser_train.add_argument("-a --alpha", type=float, default=1.0,
+ dest="alpha", help="learning rate")
+ parser_train.add_argument("-e --epoch", type=int, default=100,
+ dest="epoch", help="number of iterations")
parser_predict = subparsers.add_parser("predict", help="make a predict")
parser_predict.set_defaults(func=self._predict)
- parser_predict.add_argument("-x", type=int, help="mileage for which the prediction will be made")
-
+ parser_predict.add_argument("-x", type=int,
+ help="mileage for which the prediction will be made")
parser_cost = subparsers.add_parser("cost", help="print model cost")
parser_cost.set_defaults(func=self._cost)
-
parser_plot = subparsers.add_parser("plot", help="plot data and model")
parser_plot.set_defaults(func=self._plot)
- parser_plot.add_argument("-d --data", help="only plot data", action="store_true", dest="plot_data")
- parser_plot.add_argument("-m --model", help="only plot model", action="store_true", dest="plot_model")
-
+ parser_plot.add_argument("-d --data", help="only plot data",
+ action="store_true", dest="plot_data")
+ parser_plot.add_argument("-m --model", help="only plot model",
+ action="store_true", dest="plot_model")
self.args = parser.parse_args(sys.argv[1:])
def _train(self):
@@ -40,7 +42,7 @@ class CommandLineInterface:
def _predict(self):
if self.args.x is not None:
- print(self.model.hypothesis(self.args.x))
+ print(self.model.make_prediction(self.args.x))
else:
predict.predict_input(self.model)
@@ -54,6 +56,9 @@ class CommandLineInterface:
self.model.plot(self.args.plot_data, self.args.plot_model)
def exec_args(self):
+ if self.args.subparser_name is None:
+ print("{} --help for more information".format(sys.argv[0]))
+ return
self.args.func()