Notes
Notes - notes.io |
Y = pd.read_csv('~/Desktop/Project/wingst3-nov21d1-machinelearning/Bank_Data_Test.csv')
X['job'] = X['job'].fillna('unknown')
X['education'] =X['education'].fillna('unknown')
X['default'].value_counts()
default_mode = X['default'].mode()[0]
default_mode
X['default'] = X['default'].fillna(default_mode)
balance_avg = round(X['balance'].mean(),0)
balance_avg
X['balance'] = X['balance'].fillna(balance_avg)
X.dropna(subset=['duration'],inplace=True)
X.isnull().sum()
age_m = round(X[X['marital']=='married']['age'].mean(),2)
age_d = round(X[X['marital']=='divorced']['age'].mean(),2)
age_s = round(X[X['marital']=='single']['age'].mean(),2)
def impute(cols):
age = cols[0]
marital = cols[1]
if pd.isnull(age):
if marital == 'married':
return age_m
elif marital == 'divorced':
return age_d
elif marital == 'single':
return age_s
else:
return age
X['age'] = X[['age','marital']].apply(impute,axis=1)
X.select_dtypes(include=['object'])
dict_job={}
count=0
for i in X.job.unique():
dict_job[i] = count
count+=1
dict_marital={}
count=0
for i in X.marital.unique():
dict_marital[i] = count
count+=1
dict_education={}
count=0
for i in X.education.unique():
dict_education[i] = count
count+=1
dict_default={}
count=0
for i in X.default.unique():
dict_default[i] = count
count+=1
dict_housing={}
count=0
for i in X.housing.unique():
dict_housing[i] = count
count+=1
dict_loan={}
count=0
for i in X.loan.unique():
dict_loan[i] = count
count+=1
dict_contact={}
count=0
for i in X.contact.unique():
dict_contact[i] = count
count+=1
dict_month={}
count=0
for i in X.month.unique():
dict_month[i] = count
count+=1
dict_poutcome={}
count=0
for i in X.poutcome.unique():
dict_poutcome[i] = count
count+=1
dict_y={}
count=0
for i in X.y.unique():
dict_y[i] = count
count+=1
X['job'] = X['job'].map(dict_job)
X['marital'] = X['marital'].map(dict_marital)
X['education'] = X['education'].map(dict_education)
X['default'] = X['default'].map(dict_default)
X['housing'] = X['housing'].map(dict_housing)
X['loan'] = X['loan'].map(dict_loan)
X['month'] = X['month'].map(dict_month)
X['contact'] = X['contact'].map(dict_contact)
X['poutcome'] = X['poutcome'].map(dict_poutcome)
X['y'] = X['y'].map(dict_y)
X.select_dtypes(include=['object'])
dict_job={}
count=0
for i in Y.job.unique():
dict_job[i] = count
count+=1
dict_marital={}
count=0
for i in Y.marital.unique():
dict_marital[i] = count
count+=1
dict_education={}
count=0
for i in Y.education.unique():
dict_education[i] = count
count+=1
dict_default={}
count=0
for i in Y.default.unique():
dict_default[i] = count
count+=1
dict_housing={}
count=0
for i in Y.housing.unique():
dict_housing[i] = count
count+=1
dict_loan={}
count=0
for i in Y.loan.unique():
dict_loan[i] = count
count+=1
dict_contact={}
count=0
for i in Y.contact.unique():
dict_contact[i] = count
count+=1
dict_month={}
count=0
for i in Y.month.unique():
dict_month[i] = count
count+=1
dict_poutcome={}
count=0
for i in Y.poutcome.unique():
dict_poutcome[i] = count
count+=1
Y['job'] = Y['job'].map(dict_job)
Y['marital'] = Y['marital'].map(dict_marital)
Y['education'] = Y['education'].map(dict_education)
Y['default'] = Y['default'].map(dict_default)
Y['housing'] = Y['housing'].map(dict_housing)
Y['loan'] = Y['loan'].map(dict_loan)
Y['contact'] = Y['contact'].map(dict_contact)
Y['month'] = Y['month'].map(dict_month)
Y['poutcome'] = Y['poutcome'].map(dict_poutcome)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X = scaler.fit_transform(X)
Y = scaler.fit_transform(Y)
from sklearn.model_selection import train_test_split
#y = X['y']
#X = X.drop(columns=['y'])
X_train, X_test, Y_train, Y_test = train_test_split(X,y,test_size=0.2)
from sklearn.linear_model import LogisticRegression
search_log_reg = LogisticRegression()
search_log_reg.fit(X_train,Y_train)
y_pred1 = search_log_reg.predict(X_test)
from sklearn.metrics import accuracy_score,f1_score
accuracy_score(y_pred1,Y_test)
#f1_score(y_pred1,Y_test)
Logistic_Output = search_log_reg.predict(Y)
Decision_Output
test_data = pd.DataFrame()
test_data['y'] =Logistic_Output
test_data.to_csv('Logistic_Predictions.csv',index=False)
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
