<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import warnings
import unicodedata
df = pd.read_csv('/content/drive/MyDrive/youtube project/youtubeRD-csv.csv',error_bad_lines=False)
df
df.isnull().sum()
df['Type'].value_counts()
df['Type'].unique()
from sklearn.model_selection import train_test_split

X = df['Title']  
y = df['Type']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
from sklearn.feature_extraction.text import CountVectorizer
count_vect = CountVectorizer()

X_train_counts = count_vect.fit_transform(X_train)
X_train_counts.shape
from sklearn.feature_extraction.text import TfidfTransformer
tfidf_transformer = TfidfTransformer()

X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
X_train_tfidf.shape
from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer()

X_train_tfidf = vectorizer.fit_transform(X_train) 
X_train_tfidf.shape
 y_test.shape, X_test.shape,X_train.shape,y_train.shape<jupyter_output><empty_output><jupyter_text>**linearsvc**<jupyter_code>from sklearn.svm import LinearSVC
clf = LinearSVC()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline
text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf', LinearSVC()),
])
text_clf.fit(X_train, y_train) 
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[121  46]
 [ 45 148]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.73      0.72      0.73       167
সামঞ্জস্যপূর্ণ       0.76      0.77      0.76       193

      accuracy                           0.75       360
     macro avg       0.75      0.75      0.75       360
  weighted avg       0.75      0.75      0.75       360

0.7472222222222222<jupyter_text>**KNN**<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
clf = KNeighborsClassifier()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf', KNeighborsClassifier()),
])
text_clf.fit(X_train, y_train) 
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[ 34 133]
 [ 10 183]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.77      0.20      0.32       167
সামঞ্জস্যপূর্ণ       0.58      0.95      0.72       193

      accuracy                           0.60       360
     macro avg       0.68      0.58      0.52       360
  weighted avg       0.67      0.60      0.53       360

0.6027777777777777<jupyter_text>**SVC**<jupyter_code>from sklearn.svm import SVC
clf = SVC()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf', SVC()),
])
text_clf.fit(X_train, y_train)
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[126  41]
 [ 30 163]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.81      0.75      0.78       167
সামঞ্জস্যপূর্ণ       0.80      0.84      0.82       193

      accuracy                           0.80       360
     macro avg       0.80      0.80      0.80       360
  weighted avg       0.80      0.80      0.80       360

0.8027777777777778<jupyter_text>**Logisticreg**<jupyter_code>from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf', LogisticRegression()),
])
text_clf.fit(X_train, y_train)
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[128  39]
 [ 39 154]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.77      0.77      0.77       167
সামঞ্জস্যপূর্ণ       0.80      0.80      0.80       193

      accuracy                           0.78       360
     macro avg       0.78      0.78      0.78       360
  weighted avg       0.78      0.78      0.78       360

0.7833333333333333<jupyter_text>**Random** **forest**<jupyter_code>from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf',RandomForestClassifier()),
])
text_clf.fit(X_train, y_train)
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[132  35]
 [ 49 144]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.73      0.79      0.76       167
সামঞ্জস্যপূর্ণ       0.80      0.75      0.77       193

      accuracy                           0.77       360
     macro avg       0.77      0.77      0.77       360
  weighted avg       0.77      0.77      0.77       360

0.7666666666666667<jupyter_text>**decison** **tree**<jupyter_code>from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf',DecisionTreeClassifier()),
])
text_clf.fit(X_train, y_train)
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[134  33]
 [ 63 130]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.68      0.80      0.74       167
সামঞ্জস্যপূর্ণ       0.80      0.67      0.73       193

      accuracy                           0.73       360
     macro avg       0.74      0.74      0.73       360
  weighted avg       0.74      0.73      0.73       360

0.7333333333333333<jupyter_text>**sgd**<jupyter_code>from sklearn.linear_model import SGDClassifier
clf = SGDClassifier()
clf.fit(X_train_tfidf,y_train)

from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf',SGDClassifier()),
])
text_clf.fit(X_train, y_train)
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[121  46]
 [ 50 143]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.71      0.72      0.72       167
সামঞ্জস্যপূর্ণ       0.76      0.74      0.75       193

      accuracy                           0.73       360
     macro avg       0.73      0.73      0.73       360
  weighted avg       0.73      0.73      0.73       360

0.7333333333333333<jupyter_text>**naivebayes**<jupyter_code>from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
clf.fit(X_train_tfidf,y_train)
from sklearn.pipeline import Pipeline

text_clf = Pipeline([('tfidf', TfidfVectorizer()),
                     ('clf',MultinomialNB()),
])
text_clf.fit(X_train, y_train)
predictions = text_clf.predict(X_test)
from sklearn import metrics
cf_matrix=metrics.confusion_matrix(y_test,predictions)
print(cf_matrix)
plt.figure(figsize=(10,6))  
sns.heatmap(cf_matrix, annot=True )
print(metrics.classification_report(y_test,predictions))
print(metrics.accuracy_score(y_test,predictions))<jupyter_output>[[132  35]
 [ 53 140]]
                precision    recall  f1-score   support

     অতিরঞ্জিত       0.71      0.79      0.75       167
সামঞ্জস্যপূর্ণ       0.80      0.73      0.76       193

      accuracy                           0.76       360
     macro avg       0.76      0.76      0.76       360
  weighted avg       0.76      0.76      0.76       360

0.7555555555555555
{'fraction_non_alphanumeric': 0.10540482342807925, 'fraction_numerical': 0.0737510766580534, 'mean_word_length': 2.8898659966499163, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '493412', 'license': 'Apache-2.0', 'n_tokens_mistral': 3878, 'n_tokens_neox': 3518, 'n_words': 577, 'path': 'YouTube-Exaggerated-Bangla-Titles-Categorization(8 ML Models).ipynb', 'repo_name': 'islam-mirajul/YouTube-Exaggerated-Bangla-Titles-Categorization', 'size': '9288'}