text_plain_output_1.png
from nltk.corpus import stopwords

from nltk.stem import WordNetLemmatizer

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import classification_report, confusion_matrix, accuracy_score

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import MinMaxScaler

import pandas as pd

import re

df_train = pd.read_csv('/kaggle/input/nlp-getting-started/train.csv')
df_test = pd.read_csv('/kaggle/input/nlp-getting-started/test.csv')
df_sub = pd.read_csv('/kaggle/input/nlp-getting-started/sample_submission.csv')

def preprocessing(df):
    derlem = []
    for i in range(len(df.text)):
        text = re.sub('https?://\\S+', '', df.text[i])
        text = re.sub('http?://\\S+', '', text)
        text = re.sub('[^a-zA-Z]', ' ', text)
        text = re.sub('\\n', ' ', text)
        text = re.sub('\\s+', ' ', text).strip()
        text = text.lower()
        text = text.split()
        text = [WordNetLemmatizer().lemmatize(kelime) for kelime in text if not kelime in set(stopwords.words('english'))]
        text = ' '.join(text)
        derlem.append(text)
    df['clean_text'] = derlem
    return df

df_test = preprocessing(df_test)
df_train = preprocessing(df_train)

tfidf = TfidfVectorizer(min_df=0.0, max_df=1.0, use_idf=True)

X = tfidf.fit_transform(df_train.text).toarray()
y = df_train.target

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
lr = LogisticRegression(solver='liblinear')
lgr_classifier = Pipeline([('scale', scaler), ('lr', lr)])
lgr_classifier.fit(X_train, y_train)
lgr_prediction = lgr_classifier.predict(X_test)

accuracy_score(y_train, lgr_classifier.predict(X_train))

test_vector = tfidf.transform(df_test['clean_text']).toarray()
prediction = lgr_classifier.predict(test_vector)
prediction