-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyPredict.py
41 lines (31 loc) · 1.13 KB
/
pyPredict.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
# LAB 37 - Natural Language Processing, PDF Sentiment Prediction
# Financial Sentiment Prediction
# Python Scripts for:
# - loading models and
# - performing text sentiment classification/regression pipelines
# Spacy & Text
import spacy
from spacy.lang.en import English
from spacy.lang.en.stop_words import STOP_WORDS
import string
# Data Manipulation
import numpy as np
import pandas as pd
# Scikit Learn
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression, LinearRegression
# Save/Load Models
import joblib
# Create our list of punctuation marks
punctuations = string.punctuation
# Create our list of stopwords
stop_words = spacy.lang.en.stop_words.STOP_WORDS
# Load English tokenizer, tagger, parser, NER and word vectors
parser = English()
def pipeline_classification(X):
classification_pipeline = joblib.load("models/pipe_logistic_regression.sav")
return classification_pipeline.predict(X)
def pipeline_regression(X):
regression_pipeline = joblib.load("models/pipe_linear_regression.sav")
return regression_pipeline.predict(X)