forked from bigjunnn/cedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSci_Thai.py
62 lines (50 loc) · 2.12 KB
/
Sci_Thai.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pandas as pd
from sklearn import preprocessing
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
class Sci_Thai:
def __init__(self, data_path):
self.df = pd.read_csv(data_path)
# Convert categorical to numerical values
le = preprocessing.LabelEncoder()
self.df['Food'] = le.fit_transform(self.df['Food'])
self.df['Gender'] = le.fit_transform(self.df['Gender'])
# Setting of the target column and predictors
target_column = ['Fullness']
predictors = ['Gender', 'Weight', 'Height', 'BMI Index', 'Food']
# Create training and data sets
X = self.df[predictors].values
y = self.df[target_column].values
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.20, random_state=10)
self.lr = LinearRegression()
self.lr.fit(X_train, y_train)
def predict(self, curr_values):
return self.lr.predict(curr_values)
def add_user_data(self, gender, height, weight, food, fullness):
curr_bmi = weight/pow(height, 2)
curr_data = pd.DataFrame({
"Gender" : [gender],
"Height" : [height],
"Weight" : [weight],
"BMI Index" : [curr_bmi],
"Food" : [food],
"Fullness" :[fullness]
})
self.df = self.df.append(curr_data)
print(self.df.tail(3))
def retrain(self):
# Convert categorical to numerical values
le = preprocessing.LabelEncoder()
self.df['Food'] = le.fit_transform(self.df['Food'])
self.df['Gender'] = le.fit_transform(self.df['Gender'])
# Setting of the target column and predictors
target_column = ['Fullness']
predictors = ['Gender', 'Weight', 'Height', 'BMI Index', 'Food']
# Create training and data sets
X = self.df[predictors].values
y = self.df[target_column].values
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.20, random_state=10)
self.lr = LinearRegression()
self.lr.fit(X_train, y_train)