Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions BaseML/Classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
import joblib

class cls:
def __init__(self, algorithm='KNN', n_neighbors=5, n_estimators=100, ):
Expand Down Expand Up @@ -75,3 +76,11 @@ def load_dataset(self, path, test_size=0.2, dataset=''):
self.dataset_path = path
self.test_size = test_size
self.dataset=dataset

def save(self):
print("Saving model checkpoints...")
joblib.dump(self.model, '../checkpoint.pkl', compress=3)


def load(self, path):
joblib.load(path)
14 changes: 14 additions & 0 deletions BaseML/GaussianNB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pandas as pd
import numpy as np
import os
import joblib

from sklearn.metrics import accuracy_score, mean_squared_error
from sklearn.naive_bayes import GaussianNB as gauss
Expand All @@ -16,6 +17,7 @@ def __init__(self
self.test_size = ' '
self.test_set = ' '


def train(self, seed=0, data_type='csv'):
np.random.seed(seed)
if data_type == 'csv':
Expand All @@ -30,6 +32,8 @@ def train(self, seed=0, data_type='csv'):
'label': label[train_index:]
}
self.model.fit(train_data, train_label)
return self.model


def inference(self, mode='cls'):
pred = self.model.predict(self.test_set['data'])
Expand All @@ -40,6 +44,16 @@ def inference(self, mode='cls'):
loss = mean_squared_error(self.test_set['label'], pred)
print('Loss: {}'.format(loss))


def load_dataset(self, path, test_size=0.2):
self.dataset_path = path
self.test_size = test_size


def save(self):
print("Saving model checkpoints...")
joblib.dump(self.model, '../checkpoint.pkl', compress=3)


def load(self, path):
joblib.load(path)
10 changes: 10 additions & 0 deletions BaseML/Regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sklearn.metrics import accuracy_score, mean_squared_error, r2_score
from sklearn import linear_model
from sklearn.decomposition import PCA as pca_reduction
import joblib

class reg:
def __init__(self, algorithm='', n_components='mle'):
Expand Down Expand Up @@ -55,3 +56,12 @@ def load_dataset(self,path,test_size=0.2, dataset=''):
self.dataset_path = path
self.test_size = test_size
self.dataset = dataset


def save(self):
print("Saving model checkpoints...")
joblib.dump(self.model, '../checkpoint.pkl', compress=3)


def load(self, path):
joblib.load(path)