|
import matplotlib.pyplot as plt |
|
import numpy as np |
|
import pandas as pd |
|
from joblib import load |
|
from sklearn.preprocessing import MinMaxScaler |
|
from sklearn.ensemble import VotingClassifier |
|
from xgboost import XGBClassifier |
|
from sklearn.neighbors import KNeighborsClassifier |
|
from sklearn.svm import SVC |
|
|
|
class SmokerModel: |
|
def __init__(self, model_path, scaler_path): |
|
self.model = load(model_path) |
|
self.scaler = load(scaler_path) |
|
|
|
def scale(self, X): |
|
""" |
|
Apply the scaler used to train the model to the new data |
|
|
|
INPUT |
|
----- |
|
X: the data to be scaled |
|
|
|
OUTPUT |
|
------ |
|
returns the scaled data |
|
""" |
|
|
|
new_data_scaled = self.scaler.transform(X) |
|
|
|
return new_data_scaled |
|
|
|
def predict(self, X): |
|
""" |
|
Make predictions using the loaded model. |
|
|
|
INPUT |
|
----- |
|
X: the data to predict a label for |
|
|
|
OUTPUT |
|
------ |
|
predicted label |
|
""" |
|
|
|
|
|
X_scaled = self.scale(X) |
|
|
|
|
|
predicted_label = self.model.predict(X_scaled) |
|
|
|
return predicted_label |