Created
August 7, 2021 19:24
-
-
Save detrin/3ba71e6851200f4aac21edd7041859f6 to your computer and use it in GitHub Desktop.
Serve ML model with Flask REST API - 1
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
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data" | |
column_names = [ | |
"MPG", | |
"Cylinders", | |
"Displacement", | |
"Horsepower", | |
"Weight", | |
"Acceleration", | |
"Model Year", | |
"Origin", | |
] | |
raw_dataset = pd.read_csv( | |
url, | |
names=column_names, | |
na_values="?", | |
comment="\t", | |
sep=" ", | |
skipinitialspace=True, | |
) | |
dataset = raw_dataset.copy() | |
dataset = dataset.dropna().astype(np.float32) | |
dataset["Origin"] = dataset["Origin"].map({1: "USA", 2: "Europe", 3: "Japan"}) | |
dataset = pd.get_dummies(dataset, columns=["Origin"], prefix="", prefix_sep="") | |
train_dataset = dataset.sample(frac=0.8, random_state=0) | |
test_dataset = dataset.drop(train_dataset.index) | |
train_features = train_dataset.copy() | |
test_features = test_dataset.copy() | |
train_labels = train_features.pop("MPG") | |
test_labels = test_features.pop("MPG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment