-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmood.py
64 lines (48 loc) · 1.34 KB
/
mood.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
63
64
# -*- coding: utf-8 -*-
"""mood.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Hxzpgfa4RVIeEND5dudHOR7KFh2J4W0y
"""
import pandas as pd
import joblib
import numpy as np
import pickle
df = pd.read_csv('/mnt/d/Hashcode/Hashcode_2022/data/25.csv')
y=pd.read_csv('/mnt/d/Hashcode/Hashcode_2022/data/25.csv')
# df.head
# df.columns
df.drop(['date','mood'],axis=1,inplace=True)
y.drop(['date','step_count','calories_burned', 'hours_of_sleep',
'bool_of_active', 'weight_kg'],axis=1, inplace=True)
# y.head
def fun(x):
if x==500:
return 1
else:
return 0
df['bool_of_active']=df['bool_of_active'].apply(fun)
def fun2(x):
if x==100:
return 1
elif x==200:
return 2
else:
return 3
y['mood']=y['mood'].apply(fun2)
# df.shape
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import RepeatedKFold
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split
model = XGBClassifier()
X_train, X_test, y_train, y_test = train_test_split(
df, y, stratify=y, train_size = 0.3 ,random_state=1121218 , shuffle = True
)
model.fit(X_train, y_train)
from sklearn.metrics import accuracy_score
y_pred=model.predict(X_test)
acc=accuracy_score(y_test,y_pred)
print(acc)
joblib.dump(model,'model')
print("dumped!")