This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from statsmodels.tsa.api import ExponentialSmoothing seasonal_decompose | |
| import statsmodels | |
| import pandas as pd | |
| import numpy as np | |
| import datetime | |
| from sklearn import metrics | |
| def preprocess(df): | |
| """ | |
| Preprocess the dataframe to required timeseries format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def rolling_forecast_es(df, df_test, p): | |
| """ | |
| Does rolling training and forecast for one week at a time | |
| """ | |
| df_test['preds'] = 0 | |
| for k in range(0, int(len(df_test)/p)): | |
| model = ExponentialSmoothing(np.asarray(df['Page.Loads'].iloc[:ix2 + (k)*p]),seasonal_periods=365, seasonal='add', trend='add') | |
| model_fit = model.fit() | |
| preds = model_fit.forecast(p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df_es = df_test.copy() | |
| df_es['preds'] = 0 | |
| p = len(df_test) | |
| model = ExponentialSmoothing(np.asarray(df_train['Page.Loads']),seasonal_periods=365, seasonal='add', trend='add') | |
| model_fit = model.fit() | |
| preds = model_fit.forecast(p) | |
| df_es['preds'] = preds |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head><meta charset="utf-8" /></head> | |
| <body> | |
| <div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script> | |
| <script type="text/javascript">/** | |
| * plotly.js v1.56.0 | |
| * Copyright 2012-2020, Plotly, Inc. | |
| * All rights reserved. | |
| * Licensed under the MIT license | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from simpletransformers.classification import ClassificationModel, ClassificationArgs | |
| model_args = ClassificationArgs() | |
| model_args.num_train_epochs = 4 | |
| model_args.reprocess_input_data = True | |
| model_args.save_best_model = True | |
| model_args.save_optimizer_and_scheduler = False | |
| model_args.overwrite_output_dir = True | |
| model_args.manual_seed = 4 | |
| model_args.use_multiprocessing = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_twitter_url(handle, max_results): | |
| mrf = "max_results={}".format(max_results) | |
| q = "query=from:{}".format(handle) | |
| url = "https://api.twitter.com/2/tweets/search/recent?{}&{}".format( | |
| mrf, q | |
| ) | |
| return url | |
| def process_yaml(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_KG(doc): | |
| text = [] | |
| for tok in doc: | |
| if tok.tag_ in ["NN","NNP","NNPS","NNS"]: | |
| text.append(tok.text) | |
| if tok.tag_ in ["VB","VBD","VBG","VBN","VBP","VBZ"]: | |
| text.append('<' + tok.text + '<') | |
| text = ('-').join(text) | |
| text_list = text.split('<') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def query(news_df, conf): | |
| try: | |
| conf = conf*(100) | |
| question = input() | |
| question_kg = get_KG(nlp(question)) | |
| query_param = [i for i,j in enumerate(question_kg) if j != ''] | |
| columns = ["subject", "links", "object"] | |
| col_dict = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"object": "patrolling island lack boats", | |
| "original-source": "Mumbai cops stop patrolling island due to lack of boats", | |
| "score": "100.0"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kg_df = news_df.copy() | |
| G=nx.from_pandas_edgelist(kg_df[kg_df['links']=="declared"], "subject", "object", | |
| edge_attr=True, create_using=nx.MultiDiGraph()) | |
| plt.figure(figsize=(7, 7)) | |
| pos = nx.spring_layout(G, k = 0.5) | |
| nx.draw(G, with_labels=True, node_color='skyblue', node_size=700, edge_cmap=plt.cm.Blues, pos = pos) | |
| plt.show() | |
| plt.savefig('links.jpg') |
OlderNewer