yn = input("Would you like to install package dependencies? (y/n)")

if yn == "y":
    print("Installing dependencies")
    !pip3 install pandas
    !pip3 install numpy
    !pip3 install scikit-learn
else:
    print("Moving on")
Installing dependencies
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pandas in /home/dudeamabobby/.local/lib/python3.10/site-packages (2.1.0)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/dudeamabobby/.local/lib/python3.10/site-packages (from pandas) (2.8.2)
Requirement already satisfied: numpy>=1.22.4 in /home/dudeamabobby/.local/lib/python3.10/site-packages (from pandas) (1.25.2)
Requirement already satisfied: pytz>=2020.1 in /usr/lib/python3/dist-packages (from pandas) (2022.1)
Requirement already satisfied: tzdata>=2022.1 in /home/dudeamabobby/.local/lib/python3.10/site-packages (from pandas) (2023.3)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in /home/dudeamabobby/.local/lib/python3.10/site-packages (1.25.2)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: scikit-learn in /home/dudeamabobby/.local/lib/python3.10/site-packages (1.3.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/dudeamabobby/.local/lib/python3.10/site-packages (from scikit-learn) (3.2.0)
Requirement already satisfied: scipy>=1.5.0 in /usr/lib/python3/dist-packages (from scikit-learn) (1.8.0)
Requirement already satisfied: joblib>=1.1.1 in /home/dudeamabobby/.local/lib/python3.10/site-packages (from scikit-learn) (1.3.2)
Requirement already satisfied: numpy>=1.17.3 in /home/dudeamabobby/.local/lib/python3.10/site-packages (from scikit-learn) (1.25.2)
print("Importing packages")
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import StandardScaler
import pdb
import pickle  # Import pickle for model saving
Importing packages


/usr/lib/python3/dist-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.17.3 and <1.25.0 is required for this version of SciPy (detected version 1.25.2
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
print("Loading, pre-processing, and splitting data")

# Load the data
data_train = pd.read_csv('./train.csv')

# Fill missing values for Age with the mean
data_train['Age'].fillna(data_train['Age'].mean(), inplace=True)

# Encode 'Sex' column
data_train['Sex'] = data_train['Sex'].map({'male': 1, 'female': 0})

# Select features and target variable
X = data_train[['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare']]
y = data_train['Survived']


# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Loading, pre-processing, and splitting data
<bound method NDFrame.head of 331    0
733    0
382    0
704    0
813    0
      ..
106    1
270    0
860    0
435    1
102    0
Name: Survived, Length: 712, dtype: int64>
print("Training model")

# Initialize and train the logistic regression model
log_reg = LogisticRegression(solver='liblinear')
log_reg.fit(X_train, y_train)

pdb.set_trace()

print("Training completed")

save_path = "logistic_regression_model.pkl"
print("Saving model to: " + save_path)
# Save the model to a file using pickle
with open(save_path, 'wb') as model_file:
    pickle.dump(log_reg, model_file)

# Load the model back from the file
with open(save_path, 'rb') as model_file:
    loaded_model = pickle.load(model_file)

print("Finished saving trained model")

# pdb.set_trace()

# Make predictions on the test set using the loaded model

repeat = input("Would you like to create a character and see whether you would have survived the Titanic?")

if repeat.lower() == "y":
    userInput = [int(input("What class would your character have been when they lived? (1, 2, 3),")), 
                int(input("Is your character male (1) or female (0)? ")), 
                int(input("How old is your character?")),
                int(input("How many siblings does your character have aboard? ")),
                int(input("How many parents or children does your character have aboard? ")),
                int(input("How expensive was your characters ship ticket? "))]

    y_pred = loaded_model.predict_proba([userInput])

    print(y_pred)

Training model
--Return--
None
> /tmp/ipykernel_6993/1083434155.py(7)<module>()
      5 log_reg.fit(X_train, y_train)
      6 
----> 7 pdb.set_trace()
      8 
      9 print("Training completed")



     Pclass  Sex        Age  SibSp  Parch      Fare
331       1    1  45.500000      0      0   28.5000
733       2    1  23.000000      0      0   13.0000
382       3    1  32.000000      0      0    7.9250
704       3    1  26.000000      1      0    7.8542
813       3    0   6.000000      4      2   31.2750
..      ...  ...        ...    ...    ...       ...
106       3    0  21.000000      0      0    7.6500
270       1    1  29.699118      0      0   31.0000
860       3    1  41.000000      2      0   14.1083
435       1    0  14.000000      1      2  120.0000
102       1    1  21.000000      0      1   77.2875

[712 rows x 6 columns]
     Pclass  Sex        Age  SibSp  Parch      Fare
331       1    1  45.500000      0      0   28.5000
733       2    1  23.000000      0      0   13.0000
382       3    1  32.000000      0      0    7.9250
704       3    1  26.000000      1      0    7.8542
813       3    0   6.000000      4      2   31.2750
..      ...  ...        ...    ...    ...       ...
106       3    0  21.000000      0      0    7.6500
270       1    1  29.699118      0      0   31.0000
860       3    1  41.000000      2      0   14.1083
435       1    0  14.000000      1      2  120.0000
102       1    1  21.000000      0      1   77.2875

[712 rows x 6 columns]
     Pclass  Sex        Age  SibSp  Parch      Fare
331       1    1  45.500000      0      0   28.5000
733       2    1  23.000000      0      0   13.0000
382       3    1  32.000000      0      0    7.9250
704       3    1  26.000000      1      0    7.8542
813       3    0   6.000000      4      2   31.2750
..      ...  ...        ...    ...    ...       ...
106       3    0  21.000000      0      0    7.6500
270       1    1  29.699118      0      0   31.0000
860       3    1  41.000000      2      0   14.1083
435       1    0  14.000000      1      2  120.0000
102       1    1  21.000000      0      1   77.2875

[712 rows x 6 columns]
     Pclass  Sex        Age  SibSp  Parch      Fare
331       1    1  45.500000      0      0   28.5000
733       2    1  23.000000      0      0   13.0000
382       3    1  32.000000      0      0    7.9250
704       3    1  26.000000      1      0    7.8542
813       3    0   6.000000      4      2   31.2750
..      ...  ...        ...    ...    ...       ...
106       3    0  21.000000      0      0    7.6500
270       1    1  29.699118      0      0   31.0000
860       3    1  41.000000      2      0   14.1083
435       1    0  14.000000      1      2  120.0000
102       1    1  21.000000      0      1   77.2875

[712 rows x 6 columns]



---------------------------------------------------------------------------

BdbQuit                                   Traceback (most recent call last)

/tmp/ipykernel_6993/1083434155.py in <module>
      5 log_reg.fit(X_train, y_train)
      6 
----> 7 pdb.set_trace()
      8 
      9 print("Training completed")


/usr/lib/python3.10/bdb.py in trace_dispatch(self, frame, event, arg)
     92             return self.dispatch_call(frame, arg)
     93         if event == 'return':
---> 94             return self.dispatch_return(frame, arg)
     95         if event == 'exception':
     96             return self.dispatch_exception(frame, arg)


/usr/lib/python3.10/bdb.py in dispatch_return(self, frame, arg)
    154             finally:
    155                 self.frame_returning = None
--> 156             if self.quitting: raise BdbQuit
    157             # The user issued a 'next' or 'until' command.
    158             if self.stopframe is frame and self.stoplineno != -1:


BdbQuit: