<jupyter_start><jupyter_text>Logistic Regression Section<jupyter_code>train = pd.read_csv('train_data.csv')
test = pd.read_csv('test_data.csv')

X_train = train.drop(['High Income'], axis=1)
y_train = train['High Income']

X_test = test.drop(['High Income'], axis=1)
y_test = test['High Income']<jupyter_output><empty_output><jupyter_text>Logistic Regression Coefficients<jupyter_code>logreg = LogisticRegression()
logreg.fit(X_train, y_train)

coef = logreg.coef_

print("Coefficients: " + str(logreg.coef_)) 
print("Intercept" + str(logreg.intercept_))<jupyter_output>Coefficients: [[0.25213684 0.52613559]]
Intercept[-16.3964274]<jupyter_text>Get Data Points for Desmos graphs<jupyter_code>train['linreg'] = train['Age']*0.25213684 + train['Years of Education']*0.52613559 - 16.3964274
train['logreg'] = 1 / (1 + np.exp(-train['linreg']))

mask_tr = train.applymap(type) != bool
d = {True: 1, False: 0}
train = train.where(mask_tr, train.replace(d))
def merge(list1, list2):   
    merged_list = [(list1[i], list2[i]) for i in range(0, len(list1))] 
    return merged_list 
train_Ytuple = list(train['High Income'])
train_Xtuple = list(train['linreg'])

train_tuples = merge(train_Xtuple, train_Ytuple)
test['linreg'] = test['Age']*0.25213684 + test['Years of Education']*0.52613559 - 16.3964274
test['logreg'] = 1 / (1 + np.exp(-test['linreg']))

mask_te = test.applymap(type) != bool
test = test.where(mask_te, test.replace(d))
test_Ytuple = list(test['High Income'])
test_Xtuple = list(test['linreg'])

test_tuples = merge(test_Xtuple, test_Ytuple)<jupyter_output><empty_output><jupyter_text>Model Performance Section<jupyter_code>adult = pd.read_csv("adult.csv")

mask = adult.applymap(type) == bool
d = {">50K": 1, "<=50K": 0}
adult = adult.where(mask, adult.replace(d))

data = adult[['age', 'education.num', 'income']]
data['income'] = data["income"].astype(str).astype(int)
X = data.drop(['income'], axis=1)
y = data['income']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 42)
logreg = LogisticRegression()
logreg.fit(X_train, y_train)

print("Train accuracy:" + str(logreg.score(X_train, y_train)))
print("Test accuracy:" + str(logreg.score(X_test, y_test)))
logreg = LogisticRegression()
cross_val_score(logreg, X_train, y_train, cv=5)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup