<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.multiclass import OneVsRestClassifier
from sklearn.model_selection import train_test_split
size=[0.1,0.2,0.3,0.4]
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics import accuracy_score
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import GradientBoostingClassifier
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import CuDNNLSTM, Dense, Dropout, LSTM
from tensorflow.keras.optimizers import Adam
from google.colab import drive
drive.mount("/content/gdrive")
from google.colab import files
uploaded = files.upload()
import numpy as np
df=pd.read_csv("/content/drive/MyDrive/Dataset/acm_datasetFinalUsed.csv")
df.columns =['heading', 'text', 'link','output']
df['text'].replace('', np.nan, inplace=True)

df.dropna(subset=['text'], inplace=True)
df['output'].replace('', np.nan, inplace=True)

df.dropna(subset=['output'], inplace=True)

df['link'].replace('', np.nan, inplace=True)

df.dropna(subset=['link'], inplace=True)
df = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
df=df.drop(['heading','link'], axis = 1)
df = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
df

for m in size:
      x_train, x_test = train_test_split(df, test_size=m)

      y_train=x_train['output']

      y_test=x_test['output']
      
      from sklearn.feature_extraction.text import TfidfVectorizer
      vectorizer=TfidfVectorizer()

      x_train=vectorizer.fit_transform(x_train['text'].astype(str))
 
      x_test=vectorizer.transform(x_test['text'].astype(str))

      
      x_test = x_test.toarray()
      x_train = x_train.toarray()
      #LR---------------------------------------
      lr = LogisticRegression()

      ovr=OneVsRestClassifier(lr)
      ovr.fit(x_train,y_train)
      y_pred=ovr.predict(x_test)
      accuracy=[]
      accuracy.append(accuracy_score(y_test, y_pred))
      #print(accuracy_score(y_test, y_pred))
      #gnb----------------------------------
      clf = GaussianNB()
      ovr=OneVsRestClassifier(clf)
      ovr.fit(x_train,y_train)
      y_pred=ovr.predict(x_test)
      accuracy.append(accuracy_score(y_test, y_pred))
      #print(accuracy_score(y_test, y_pred))
      #KNN---------------------------------------------------
      clf = KNeighborsClassifier(n_neighbors=5)
      ovr=OneVsRestClassifier(clf)
      ovr.fit(x_train,y_train)
      y_pred=ovr.predict(x_test)
      accuracy.append(accuracy_score(y_test, y_pred))
      #print(accuracy_score(y_test, y_pred))
      #RandomForest----------------------------------------------
      clf = RandomForestClassifier(max_depth=100, random_state=0)
      ovr=OneVsRestClassifier(clf)
      ovr.fit(x_train,y_train)
      y_pred=ovr.predict(x_test)
      accuracy.append(accuracy_score(y_test, y_pred))
      #print(accuracy_score(y_test, y_pred))
      #svm--------------------------------------------------------------
      from sklearn import svm
      clf = svm.SVC()
      from sklearn.tree import DecisionTreeClassifier
      d=DecisionTreeClassifier()
      d.fit(x_train,y_train)
      y_pred=d.predict(x_test)
      accuracy.append(accuracy_score(y_test, y_pred))
      #GradientBoostingClassifier------------------------------------------
      gbc=GradientBoostingClassifier()
      gbc.fit(x_train,y_train)
      y_pred=gbc.predict(x_test)
      accuracy.append(accuracy_score(y_test, y_pred))
      #print(accuracy_score(y_test,y_pred))
      ovr=OneVsRestClassifier(clf)
      ovr.fit(x_train,y_train)
      y_pred=ovr.predict(x_test)
      accuracy.append(accuracy_score(y_test, y_pred))

      # creating the dataset
      data = dict()
      #print("accuracy with "+ m*100+"% test data")
      algo=["Logistic Regression"," GaussianNB","KNN","Random Forest","decision tree","SVM","GradientBoostingClassifier"]
      for i in range(7):
        data[algo[i]]=accuracy[i]
      print("Accuracy with ", str(m*100),"% test data ",data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17838603114676735, 'fraction_numerical': 0.005427088249174139, 'mean_word_length': 3.226321036889332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '553626', 'license': 'MIT', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1434, 'n_words': 230, 'path': 'ML.ipynb', 'repo_name': 'mehakagg1313/Sachet-Samachar', 'size': '4238'}