<jupyter_start><jupyter_text>**Importing the requirements**<jupyter_code>import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report,confusion_matrix,accuracy_score<jupyter_output><empty_output><jupyter_text>**Addning the data**<jupyter_code>url = 'https://raw.githubusercontent.com/AlbusDracoSam/NLP/main/Stock%20price%20NLP/Data.csv'
df = pd.read_csv(url,encoding = "ISO-8859-1")<jupyter_output><empty_output><jupyter_text>**Selecting the data**<jupyter_code>train = df[df['Date'] < '20150101']
test = df[df['Date'] > '20141231']<jupyter_output><empty_output><jupyter_text>**Feature engineering**<jupyter_code>data = train.iloc[:,2:27]
data.replace('[^a-zA-Z]'," ",regex=True,inplace=True)

list1 = [i for i in range(25)]
new_Index=[str(i) for i in list1]
data.columns= new_Index
data.head(5)<jupyter_output><empty_output><jupyter_text>**Converting to Lower**<jupyter_code>for index in new_Index:
    data[index] = data[index].str.lower()
data.head(1)<jupyter_output><empty_output><jupyter_text>**Convert each row to paragraph**<jupyter_code>headlines = []
for row in range(0,len(data.index)):
    headlines.append(' '.join(str(x) for x in data.iloc[row,0:25]))
print(headlines[0])<jupyter_output>a  hindrance to operations   extracts from the leaked reports scorecard hughes  instant hit buoys blues jack gets his skates on at ice cold alex chaos as maracana builds up for united depleted leicester prevail as elliott spoils everton s party hungry spurs sense rich pickings gunners so wide of an easy target derby raise a glass to strupar s debut double southgate strikes  leeds pay the penalty hammers hand robson a youthful lesson saints party like it s      wear wolves have turned into lambs stump mike catches testy gough s taunt langer escapes to hit     flintoff injury piles on woe for england hunters threaten jospin with new battle of the somme kohl s successor drawn into scandal the difference between men and women sara denver  nurse turned solicitor diana s landmine crusade put tories in a panic yeltsin s resignation caught opposition flat footed russian roulette sold out recovering a title<jupyter_text>**Implementing BOW**<jupyter_code>countvector=CountVectorizer(ngram_range=(2,2))
traindataset=countvector.fit_transform(headlines)<jupyter_output><empty_output><jupyter_text>**Implementing Randrom forest classifier**<jupyter_code>randomclassifier=RandomForestClassifier(n_estimators=200,criterion='entropy')
randomclassifier.fit(traindataset,train['Label'])<jupyter_output><empty_output><jupyter_text>**Predicting for Test data**<jupyter_code>test_transform= []
for row in range(0,len(test.index)):
    test_transform.append(' '.join(str(x) for x in test.iloc[row,2:27]))
test_dataset = countvector.transform(test_transform)
predictions = randomclassifier.predict(test_dataset)<jupyter_output><empty_output><jupyter_text>**Accuracy**<jupyter_code>matrix=confusion_matrix(test['Label'],predictions)
print(matrix)
score=accuracy_score(test['Label'],predictions)
print(score)
report=classification_report(test['Label'],predictions)
print(report)<jupyter_output>[[138  48]
 [ 15 177]]
0.8333333333333334
              precision    recall  f1-score   support

           0       0.90      0.74      0.81       186
           1       0.79      0.92      0.85       192

    accuracy                           0.83       378
   macro avg       0.84      0.83      0.83       378
weighted avg       0.84      0.83      0.83       378
{'fraction_non_alphanumeric': 0.10137216465975916, 'fraction_numerical': 0.03696443573228787, 'mean_word_length': 5.459312839059675, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '64294', 'license': 'MIT', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1160, 'n_words': 283, 'path': 'Stock Price Prediction/Stock price NLP.ipynb', 'repo_name': 'adityaverma121/Hacktoberfest-2022', 'size': '3571'}