<jupyter_start><jupyter_text>Reading Data<jupyter_code>test=pd.read_csv(r"C:\Users\hp\Desktop\Data Science\test_QaJU1Mh.csv")
train=pd.read_csv(r"C:\Users\hp\Desktop\Data Science\train_jRxnrHD.csv")<jupyter_output><empty_output><jupyter_text>Filling Missing Values<jupyter_code>test['application_underwriting_score'].fillna(test['application_underwriting_score'].mean(), inplace=True)
test['Count_3-6_months_late'].fillna(0, inplace=True)
test['Count_6-12_months_late'].fillna(0, inplace=True)
test['Count_more_than_12_months_late'].fillna(0, inplace=True)
#test.isnull().sum()
train['application_underwriting_score'].fillna(train['application_underwriting_score'].mean(), inplace=True)
train['Count_3-6_months_late'].fillna(0, inplace=True)
train['Count_6-12_months_late'].fillna(0, inplace=True)
train['Count_more_than_12_months_late'].fillna(0, inplace=True)
#train.isnull().sum()<jupyter_output><empty_output><jupyter_text>Outlier Removal<jupyter_code>train.loc[train['age_in_days']>34000,'age_in_days']=np.mean(train['age_in_days'])
#train['age_in_days'].plot.box()
test.loc[test['age_in_days']>34000,'age_in_days']=np.mean(test['age_in_days'])
#test['age_in_days'].plot.box()

train['no_of_premiums_paid']=np.sqrt(train['no_of_premiums_paid'])

test['no_of_premiums_paid']=np.log(test['no_of_premiums_paid'])
train['premium']=np.power(train['premium'],1/2)


train['Income']=np.log(train['Income'])
test['Income']=np.log(test['Income'])
train['application_underwriting_score']=np.sqrt(train['application_underwriting_score'])
test['application_underwriting_score']=np.sqrt(test['application_underwriting_score'])
#train.loc[train['Count_more_than_12_months_late']>8,'Count_more_than_12_months_late']=np.mean(train['Count_more_than_12_months_late'])

#train['Count_more_than_12_months_late'].plot.box()

#test.loc[test['Count_3-6_months_late']>8,'Count_3-6_months_late']=np.mean(test['Count_3-6_months_late'])
#test['Count_3-6_months_late'].plot.box()

#train.loc[train['premium']>20000,'premium']=np.mean(train['premium'])
#test.loc[test['application_underwriting_score']<98.20,'application_underwriting_score']=np.mean(test['application_underwriting_score'])
#train.loc[train['application_underwriting_score']<98.20,'application_underwriting_score']=np.mean(train['application_underwriting_score'])
#test.loc[test['Income']>1,'Income']=np.mean(test['Income'])
#train.loc[train['Income']>0.4,'Income']=np.mean(train['Income'])<jupyter_output><empty_output><jupyter_text>Linear Regression model<jupyter_code>#making train data set

train_set=train[0:55899]
#making test data set

test_set=train[55900:]
train.head()<jupyter_output><empty_output><jupyter_text>Dropping train set data<jupyter_code>#train_set=train_set.drop('perc_premium_paid_by_cash_credit',axis=1)
#train_set=train_set.drop('sourcing_channel',axis=1)
train_set=train_set.drop('target',axis=1)
train_set=train_set.drop('id',axis=1)
#train_set=train_set.drop('no_of_premiums_paid',axis=1)
train_set=train_set.drop('Count_3-6_months_late',axis=1)
train_set=train_set.drop('Count_6-12_months_late',axis=1)
train_set=train_set.drop('Count_more_than_12_months_late',axis=1)<jupyter_output><empty_output><jupyter_text>Dropping test set data<jupyter_code>#test_set=test_set.drop('perc_premium_paid_by_cash_credit',axis=1)
#test_set=test_set.drop('sourcing_channel',axis=1)
test_set=test_set.drop('target',axis=1)
test_set=test_set.drop('id',axis=1)
#test_set=test_set.drop('no_of_premiums_paid',axis=1)
test_set=test_set.drop('Count_3-6_months_late',axis=1)
test_set=test_set.drop('Count_6-12_months_late',axis=1)
test_set=test_set.drop('Count_more_than_12_months_late',axis=1)
x_train=train_set.drop('premium',axis=1)
y_train=train_set['premium']
x_test=test_set.drop('premium',axis=1)
true_p=test_set['premium']<jupyter_output><empty_output><jupyter_text>Implementing Linear Regression to find premium<jupyter_code>from sklearn.linear_model import LinearRegression
lreg=LinearRegression()
x_train=pd.get_dummies(x_train)
x_test=pd.get_dummies(x_test)
lreg.fit(x_train,y_train)
pred=lreg.predict(x_test)<jupyter_output><empty_output><jupyter_text>Performance of lreg model<jupyter_code>lreg.score(x_test,true_p)
lreg.score(x_train,y_train)
rmse_test=np.sqrt(np.mean(np.power((np.array(true_p)-np.array(pred)),2)))
rmse_train=np.sqrt(np.mean(np.power((np.array(y_train)-np.array(lreg.predict(x_train))),2)))
print(rmse_test)
print(rmse_train)


x_train.shape<jupyter_output><empty_output><jupyter_text>Prediction on actual Test Data<jupyter_code>test_run=test.copy()
#test_run=test_run.drop('perc_premium_paid_by_cash_credit', axis=1)
#test_run=test_run.drop('sourcing_channel', axis=1)
test_run=test_run.drop('id', axis=1)
#test_run=test_run.drop('no_of_premiums_paid',axis=1)
test_run=test_run.drop('Count_3-6_months_late',axis=1)
test_run=test_run.drop('Count_6-12_months_late',axis=1)
test_run=test_run.drop('Count_more_than_12_months_late',axis=1)
test_run=pd.get_dummies(test_run)
prediction=lreg.predict(test_run)
test['premium']=prediction

test['premium']=np.power(test['premium'],1/3)
#test['premium']=np.power(test['premium'],1/2)
#test.loc[test['premium']>10300,'premium']=np.mean(test['premium'])
#test.loc[test['premium']<7300,'premium']=np.mean(test['premium'])<jupyter_output><empty_output><jupyter_text>Logistic Regression Model<jupyter_code>#making train data set

train1_set=train[0:47911]
#making test data set

test1_set=train[47912:]
train.head()<jupyter_output><empty_output><jupyter_text>Dropping train set data<jupyter_code>train1_set=train1_set.drop('id',axis=1)
train1_set=train1_set.drop('sourcing_channel',axis=1)
#train1_set=train1_set.drop('perc_premium_paid_by_cash_credit',axis=1)
#train1_set=train1_set.drop('application_underwriting_score',axis=1)<jupyter_output><empty_output><jupyter_text>Dropping test set data<jupyter_code>test1_set=test1_set.drop('id',axis=1)
test1_set=test1_set.drop('sourcing_channel',axis=1)
#test1_set=test1_set.drop('perc_premium_paid_by_cash_credit',axis=1)
#test1_set=test1_set.drop('application_underwriting_score',axis=1)

xx_train=train1_set.drop('target',axis=1)
yy_train=train1_set['target']
xx_test=test1_set.drop('target',axis=1)
true_p1=test1_set['target']
xx_train=pd.get_dummies(xx_train)
xx_test=pd.get_dummies(xx_test)<jupyter_output><empty_output><jupyter_text>Implementation of Logistic Regression to find target<jupyter_code>from sklearn.linear_model import LogisticRegression
logreg= LogisticRegression()
#Resolving future warning
logreg = LogisticRegression(solver='lbfgs')

#logreg = LogisticRegression(class_weight = 'balanced')
logreg.fit(xx_train, yy_train)
pred1=logreg.predict(xx_test)
print(pred1)<jupyter_output>[1 1 1 ... 1 1 1]<jupyter_text>Performance of logreg model<jupyter_code>logreg.score(xx_train, yy_train)
logreg.score(xx_test, true_p1)<jupyter_output><empty_output><jupyter_text>Prediction on actual test<jupyter_code>test_run1=test.copy()
#test_run1=test_run1.drop('application_underwriting_score', axis=1)
test_run1=test_run1.drop('id', axis=1)
test_run1=test_run1.drop('sourcing_channel', axis=1)
#test_run1=test_run1.drop('perc_premium_paid_by_cash_credit',axis=1)
test_run1=pd.get_dummies(test_run1)
prediction1=logreg.predict(test_run1)
prediction1<jupyter_output><empty_output><jupyter_text>Creating Submission file<jupyter_code>sub=pd.read_csv(r"C:\Users\hp\Desktop\Data Science\my_subs.csv")
sub=sub.drop('target', axis=1)
sub['target']=prediction1
df = pd.DataFrame(sub) 
# saving the dataframe 
df.to_csv(r'C:\Users\hp\Desktop\Data Science\my_subs.csv', index=False) 
sub.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16020569620253164, 'fraction_numerical': 0.027953586497890294, 'mean_word_length': 16.973933649289098, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 72, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '662611', 'license': 'MIT', 'n_tokens_mistral': 3224, 'n_tokens_neox': 3078, 'n_words': 215, 'path': 'ML Models/Linear Regression Model.ipynb', 'repo_name': 'anna4j/Data-Science-Hackathon', 'size': '7584'}