Commit
·
b7d3682
1
Parent(s):
e6fb042
added model class
Browse files
model.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
from joblib import load
|
5 |
+
from sklearn.preprocessing import MinMaxScaler
|
6 |
+
from sklearn.ensemble import VotingClassifier
|
7 |
+
from xgboost import XGBClassifier
|
8 |
+
from sklearn.neighbors import KNeighborsClassifier
|
9 |
+
from sklearn.svm import SVC
|
10 |
+
|
11 |
+
class SmokerModel:
|
12 |
+
def __init__(self, model_path, scaler_path):
|
13 |
+
self.model = load(model_path)
|
14 |
+
self.scaler = load(scaler_path)
|
15 |
+
|
16 |
+
def scale(self, X):
|
17 |
+
"""
|
18 |
+
Apply the scaler used to train the model to the new data
|
19 |
+
|
20 |
+
INPUT
|
21 |
+
-----
|
22 |
+
X: the data to be scaled
|
23 |
+
|
24 |
+
OUTPUT
|
25 |
+
------
|
26 |
+
returns the scaled data
|
27 |
+
"""
|
28 |
+
|
29 |
+
new_data_scaled = self.scaler.transform(X)
|
30 |
+
|
31 |
+
return new_data_scaled
|
32 |
+
|
33 |
+
def predict(self, X):
|
34 |
+
"""
|
35 |
+
Make predictions using the loaded model.
|
36 |
+
|
37 |
+
INPUT
|
38 |
+
-----
|
39 |
+
X: the data to predict a label for
|
40 |
+
|
41 |
+
OUTPUT
|
42 |
+
------
|
43 |
+
predicted label
|
44 |
+
"""
|
45 |
+
|
46 |
+
# scale the data
|
47 |
+
X_scaled = self.scale(X)
|
48 |
+
|
49 |
+
# Now, use the scaled data to make predictions using the loaded model
|
50 |
+
predicted_label = self.model.predict(X_scaled)
|
51 |
+
|
52 |
+
return predicted_label
|