-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.py
More file actions
20 lines (16 loc) · 881 Bytes
/
model.py
File metadata and controls
20 lines (16 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from sklearn import linear_model
import pandas as pd
import matplotlib as plt
import seaborn as sns
import pymongo
CONNECTION_STRING = "mongodb+srv://admin:admin@cluster0-8vzpx.gcp.mongodb.net/test?retryWrites=true&w=majority"
client = pymongo.MongoClient(CONNECTION_STRING)
unemployment_data = client.get_database('unemployment_data')
sns.set(color_codes=True)
unemployment_rate = unemployment_data.get_collection('unemployment_rate')
df_unemployment_rate = pd.DataFrame(list(unemployment_rate.find()))
df_unemployment_rate['date'] = df_unemployment_rate['date'].astype('datetime64[ns]')
sns.relplot(x="date", y="unemployment", data=df_unemployment_rate)
ols = linear_model.LinearRegression()
model = ols.fit(df_unemployment_rate['date'].reshape(-1,1), df_unemployment_rate['unemployment'].reshape(-1,1))
print(model.predict(pd.DataFrame(data={'col1': ['2019-01-01']})[0:5]))