<jupyter_start><jupyter_text>Creating Logistic Regression for Pre-processed data<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn
seaborn.set()<jupyter_output><empty_output><jupyter_text>Reading Pre-processed data<jupyter_code>data_preprocessed=pd.read_csv("Absenteeism_preprocessed.csv")
data_preprocessed<jupyter_output><empty_output><jupyter_text>Creating Targers<jupyter_code>data_preprocessed['Absenteeism Time in Hours'].median()
targets=np.where(data_preprocessed['Absenteeism Time in Hours']>3,1,0)
targets
data_preprocessed['Exessive Absenteeism']=targets
data_preprocessed
data_preprocessed=data_preprocessed.drop(['Date'], axis=1)
data_preprocessed
#Checkpoint
data_with_targets=data_preprocessed.copy()
data_with_targets=data_with_targets.drop(['Absenteeism Time in Hours'], axis=1)
data_with_targets
data_with_targets.iloc[:,:14]#or data_with_targets.iloc[:,:-1]
unscaled_inputs=data_with_targets.iloc[:,:14]<jupyter_output><empty_output><jupyter_text>Standardizing Data<jupyter_code>from sklearn.preprocessing import StandardScaler
absenteesism_scaler=StandardScaler()
absenteesism_scaler.fit(unscaled_inputs)
scaled_inputs=absenteesism_scaler.transform(unscaled_inputs)
scaled_inputs
from sklearn.model_selection import train_test_split
train_test_split(scaled_inputs,targets)
x_train,x_test,y_train,y_test=train_test_split(scaled_inputs,targets, train_size=0.8,shuffle=True, random_state=20)
print(x_test.shape,y_test.shape)
print(x_train.shape,y_train.shape)<jupyter_output>((560L, 14L), (560L,))<jupyter_text>Logistic Regression with SkLearn<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn import metrics
reg=LogisticRegression()
reg.fit(x_train,y_train)
reg.score(x_train,y_train)<jupyter_output><empty_output><jupyter_text>Manual<jupyter_code>reg.predict(x_train)
predicted_outputs=reg.predict(x_train)
predicted_outputs==y_train
reg.score(x_test,y_test)#score with test data<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10174563591022444, 'fraction_numerical': 0.010972568578553617, 'mean_word_length': 16.0, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '372373', 'license': 'MIT', 'n_tokens_mistral': 772, 'n_tokens_neox': 729, 'n_words': 88, 'path': 'Absenteeism/Absenteeism_Logistic Regression.ipynb', 'repo_name': 'praneeth7894/Projects', 'size': '2005'}