forked from syedroshanzameer/udacity-capstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
44 lines (32 loc) · 1.56 KB
/
train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from sklearn.linear_model import LogisticRegression
import numpy as np
import pandas as pd
import argparse
import os
from sklearn.metrics import mean_squared_error
import joblib
from sklearn.model_selection import train_test_split
from azureml.core.run import Run
from azureml.data.dataset_factory import TabularDatasetFactory
run = Run.get_context()
def main():
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00519/heart_failure_clinical_records_dataset.csv'
data = TabularDatasetFactory.from_delimited_files(url)
x = data.to_pandas_dataframe()
y = x.pop("DEATH_EVENT")
x_train, x_test, y_train, y_test = train_test_split(x, y)
parser = argparse.ArgumentParser()
parser.add_argument('--C', type=float, default=1.0, help="Inverse of regularization strength. Smaller values cause stronger regularization")
parser.add_argument('--max_iter', type=int, default=100, help="Maximum number of iterations to converge")
parser.add_argument('--solver', type=str, default='lbfgs', help="chose the algorithm to train the model")
args = parser.parse_args()
run.log("Regularization Strength:", np.float(args.C))
run.log("Max iterations:", np.int(args.max_iter))
run.log("Algorithm: ", args.solver)
model = LogisticRegression(solver=args.solver, C=args.C, max_iter=args.max_iter).fit(x_train, y_train)
accuracy = model.score(x_test, y_test)
run.log("Accuracy", np.float(accuracy))
os.makedirs('outputs', exist_ok=True)
joblib.dump(model,'outputs/model.joblib')
if __name__ == '__main__':
main()