<jupyter_start><jupyter_text>GITHUB setup instructions are in a separate notebook it's published on the github repo  LOGISTIC REGRESSION MODEL FOR NBA ROOKIE PLAYERS  Load Packages<jupyter_code># Load the packages needed for Logistic Regression Modelling upfront
import pandas as pd
import numpy as np

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler

from sklearn.metrics import mean_squared_error as mse
from sklearn.metrics import mean_absolute_error as mae
from sklearn.metrics import roc_auc_score

from joblib import dump<jupyter_output><empty_output><jupyter_text>Load the data<jupyter_code># Load the training data set
train = pd.read_csv('/Users/jasle1/Desktop/MDSI/ADSI/AT_1/adsi_at1/data/raw/train.csv')
# Load the test data set
test = pd.read_csv('/Users/jasle1/Desktop/MDSI/ADSI/AT_1/adsi_at1/data/raw/test.csv')<jupyter_output><empty_output><jupyter_text>Explore the Data<jupyter_code># check rows and columns of the training set
train.shape
# check rows and columns of the test set
test.shape
train.head()
test.head()
train.info()
test.info()
train.describe()<jupyter_output><empty_output><jupyter_text>Transform the Data<jupyter_code># extract the target variable out as y = target
y_train = train.pop('TARGET_5Yrs')
y_train.shape
# Standardise the dataset - SKIP THIS FOR NOW, IT CAUSES PROBLEMS AT THE END
# scaler = StandardScaler()
# train = scaler.fit_transform(train)
# test = scaler.fit_transform(test)
# Split the training data into train and validation sets for evaluation
# set the validation set at 20% of the full training set
X_train, X_val, y_train, y_val = train_test_split(train, y_train, test_size=0.2, random_state = 42)<jupyter_output><empty_output><jupyter_text>Train Logistic Regression Model<jupyter_code># Build the logistic regression classifier
model = LogisticRegression(solver='liblinear',class_weight='balanced') 
# liblinear is using both L1 and L2 penalty
# The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data
# fit the model
model.fit(X_train, y_train)
# Make predictions on the validation dataset
val_pred = model.predict_proba(X_val)
val_pred
#pd.DataFrame(val_pred[:,1])<jupyter_output><empty_output><jupyter_text>Evaluate Model Performance<jupyter_code># Calculate auc scores for performance evaluation
auc_score = roc_auc_score(y_val, val_pred[:,1])

print(f'The Logistic regression ROC AUC score is {auc_score}')
# Make predictions on the test set now
test_pred = model.predict_proba(test)
test_pred
# pd.DataFrame(test_pred[:,1])<jupyter_output><empty_output><jupyter_text>Prepare the file for extracting final prediction output - for Kaggle submission<jupyter_code># Convert the datasets into pandas dataframe for easy merge with prediction file
test = pd.DataFrame(test)
test
# Convert the datasets into pandas dataframe for easy merge with prediction file
test_pred = pd.DataFrame(test_pred)
test_pred.head()
# it seems that the framework is giving out prediction for both yes and no
# Now, merge the test data set with predictions data
df = pd.concat([test, test_pred], axis=1)
df.head()
# Rename the '1' prediction column to align with Kaggle submission requirements
df_final = df.rename(columns={1: 'TARGET_5Yrs'})
df_final.head()
# Extract the ID and Prediction columns for Kaggle Submission
submission = df_final[['Id', 'TARGET_5Yrs']]
submission.head()
# save the submission file for kaggle upload
submission.to_csv('jasleen_logistic_reg_week1', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07967032967032966, 'fraction_numerical': 0.006593406593406593, 'mean_word_length': 6.746808510638298, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '627914', 'license': 'FTL', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1137, 'n_words': 365, 'path': 'notebooks/Kaur_Jasleen/Kaur_Jasleen-13368028-week1_LGR_unscaled.ipynb', 'repo_name': 'JKaur1992/adsi_at1', 'size': '3640'}