<jupyter_start><jupyter_text>Logistic Reg<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.model_selection import cross_val_score
import numpy as np
from sklearn.metrics import classification_report

##testModel function will take as input the model name, X: feature and y: label
#We automated the testing model part because it will save us time when testing multiple models such as
#LogisticRegression + SGDClassifier + MultinomialNB + RandomForestClassifier

def testModel(model,X_train,X_test,y_train, y_test):    
    model = model()
    model.fit(X_train,y_train)
    modelName = type(model).__name__
    pred=model.predict(X_test)
    print(modelName)
    print(classification_report(y_test,model.predict(X_test)))
    score=np.mean(cross_val_score(model, X, y, cv=5))

    return model,{"model":modelName,"score":score}
from sklearn.linear_model import LogisticRegression
testModel(LogisticRegression,X_train,X_val,y_train,y_val)
#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression(penalty='l2',C=10,max_iter=400,solver='lbfgs',verbose=3)
model.fit(X_train,y_train)
pred=model.predict(X_val)
print(classification_report(y_val,model.predict(X_val)))
score=np.mean(cross_val_score(model, x, y, cv=5))
print(score)<jupyter_output>[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
{'fraction_non_alphanumeric': 0.09979353062629043, 'fraction_numerical': 0.01032346868547832, 'mean_word_length': 7.759036144578313, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '222444', 'license': 'Unlicense', 'n_tokens_mistral': 504, 'n_tokens_neox': 490, 'n_words': 104, 'path': '4-Model_Building/KNN_LOGISTIC_testing.ipynb', 'repo_name': 'belhajManel/News-Prediction-And-Classification-In-Arabic', 'size': '1453'}