<jupyter_start><jupyter_text>Splitting data<jupyter_code># split train and test
from sklearn.model_selection import train_test_split
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size = 0.2, random_state = 42, stratify = y)
X_train, X_test, y_train, y_test = train_test_split(X_train, y_train, test_size = 0.25, random_state = 42, stratify = y_train)<jupyter_output><empty_output><jupyter_text>Ridge Regression<jupyter_code>pipe1 = Pipeline([('scaler', StandardScaler()), 
                  ('Ridge', LogisticRegression(C= 0.1, random_state=0, verbose=3))])
gc.collect()
clf1 = pipe1.fit(X_train, y_train)  # fit the data
with open('Ridge1', 'wb') as files:
    pickle.dump(clf1, files)
Y_pred1 = clf1.predict(X_val)
YpredProb = clf1.predict_proba(X_val)
print("Accuracy:",metrics.accuracy_score(y_val, Y_pred1))
print("F1:", metrics.f1_score(y_val, Y_pred1, average="weighted"))
print("Matthew's Correlation Coefficient:", metrics.matthews_corrcoef(y_val, Y_pred1))
from sklearn import preprocessing
le = preprocessing.LabelEncoder()

le.fit(y_train)
y_val_le = le.transform(y_val)

print("ROC_AUC:", metrics.roc_auc_score(y_val_le, YpredProb, multi_class = 'ovr', average = 'macro'))<jupyter_output>/usr/local/lib/python3.7/dist-packages/sklearn/preprocessing/_label.py:98: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  y = column_or_1d(y, warn=True)
/usr/local/lib/python3.7/dist-packages/sklearn/preprocessing/_label.py:133: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  y = column_or_1d(y, warn=True)<jupyter_text>Logistic regression<jupyter_code>pipe2 = Pipeline([('scaler', StandardScaler()), 
                  ('Logistic', LogisticRegression(penalty="none", random_state=0, verbose=3))])
gc.collect()
clf2 = pipe2.fit(X_train, y_train)
with open('Logistic', 'wb') as files:
    pickle.dump(clf2, files)
Y_pred2 = clf2.predict(X_val)
YpredProb1 = clf2.predict_proba(X_val)
print("Accuracy:",metrics.accuracy_score(y_val, Y_pred2))
print("F1:", metrics.f1_score(y_val, Y_pred2, average="weighted"))
print("Matthew's Correlation Coefficient:", metrics.matthews_corrcoef(y_val, Y_pred2))
from sklearn import preprocessing
le = preprocessing.LabelEncoder()

le.fit(y_train)
y_val_le = le.transform(y_val)

print("ROC_AUC:", metrics.roc_auc_score(y_val_le, YpredProb1, multi_class = 'ovr', average = 'macro'))<jupyter_output>/usr/local/lib/python3.7/dist-packages/sklearn/preprocessing/_label.py:98: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  y = column_or_1d(y, warn=True)
/usr/local/lib/python3.7/dist-packages/sklearn/preprocessing/_label.py:133: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  y = column_or_1d(y, warn=True)<jupyter_text>Evaluation<jupyter_code>ScoresLOG = pd.DataFrame([["Ridge", 0.9536, 0.9509, 0.7883, 0.9333],["Logistic", 0.9535, 0.9508, 0.7877, 0.9312]], columns = ["model", "accuracy", "F1", "MCC", "ROC-AUC"])
ScoresLOG.to_csv("LogisticScores.csv", sep=";")
ScoresLOG
ScoresLOG = ScoresLOG.set_index('model')
ScoresLOG.plot.bar(ylim = (0.75, 1), title = 'Tree prediction score with Depth').legend(loc='center right')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14007342558599264, 'fraction_numerical': 0.03191188929680881, 'mean_word_length': 6.472573839662447, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '258553', 'license': 'MIT', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1297, 'n_words': 276, 'path': 'code/Logistic_regression.ipynb', 'repo_name': 'lauramenicacci/ML_project', 'size': '3541'}