<jupyter_start><jupyter_text>Accuracy :  0.7806122448979592Sensitivity :  0.7142857142857143Specificity :  0.7916666666666666f1score: 0.4819277108433735 array([[ 20,   8],       [ 35, 133]], dtype=int64)<jupyter_code>print("Accuracy :  0.8010204081632653, Sensitivity :  0.52, Specificity :  0.8972602739726028")
print("f1score: 0.5714285714285714, precision: 0.6341463414634146")



######################################


cr=pd.read_csv("C:/Users/geeta/Pythonstuff/CreditRisk.csv")
cr.head()
cr.LoanAmount=cr.LoanAmount.fillna(cr.LoanAmount.mean())
cr.Gender=cr.Gender.fillna("Male")
cr.Dependents=cr.Dependents.fillna(0)
cr.Self_Employed=cr.Self_Employed.fillna("Yes")
cr.Loan_Amount_Term=cr.Loan_Amount_Term.fillna(cr.Loan_Amount_Term.mean())
cr.Credit_History=cr.Credit_History.fillna(0)
cr=cr.dropna()
cr=cr.drop(["Loan_ID"], axis=1)
#Dependents,ApplicantIncome, CoapplicantIncome, LoanAmount, Credit_History
#cr=cr.drop(["Gender"], axis=1)
#cr=cr.drop(["Married"], axis=1)
#cr=cr.drop(["Education"], axis=1)
#cr=cr.drop(["Self_Employed"], axis=1)
#cr=cr.drop(["Loan_Amount_Term"], axis=1)
#cr=cr.drop(["Property_Area"], axis=1)

le=LabelEncoder()
cr[cr.select_dtypes(include=['object']).columns]=cr[cr.select_dtypes(include=['object']).columns].apply(le.fit_transform)
cr_train, cr_test= train_test_split(cr, test_size=0.2)
cr_train.Loan_Status.value_counts()
df1=cr_train[cr_train.Loan_Status==0 ]
df2=cr_train[cr_train.Loan_Status==1 ]
df2.head()
cr_train=pd.concat([cr_train, df1,df1], axis=0)

cr_x_train=cr_train.iloc[:, 0:11]
cr_y_train=cr_train.iloc[:, 11]

cr_x_test=cr_test.iloc[:,0:11]
cr_y_test=cr_test.iloc[:,11]

cr_y_test.head()
print(cr_x_train.shape)
print(cr_y_train.shape)
from sklearn.linear_model import LogisticRegression
logreg=LogisticRegression()
logreg.fit(cr_x_train, cr_y_train)
pred_value=logreg.predict(cr_x_test)

tab1=confusion_matrix(pred_value, cr_y_test)
tab1
accuracy=tab1.diagonal().sum()/tab1.sum() * 100
accuracy
total1=sum(sum(tab1))
accuracy1=(tab1[0,0]+tab1[1,1])/total1
print ('Accuracy : ', accuracy1)

sensitivity1 = tab1[0,0]/(tab1[0,0]+tab1[1,0])
print('Sensitivity : ', sensitivity1 )

specificity1 = tab1[1,1]/(tab1[0,1]+tab1[1,1])
print('Specificity : ', specificity1)

f1score=tab1[0,0]/(tab1[0,0]+(1/2)*(tab1[1,0]+tab1[0,1]))
print('f1score:',f1score)

precision=tab1[0,0]/(tab1[0,0]+tab1[0,1])
print('precision:', precision)
from sklearn.metrics import classification_report
print(classification_report(pred_value, cr_y_test))
import pickle
with open('cr_reg','wb') as f:
    pickle.dump(logreg, f)
with open('cr_reg', 'rb') as f:
    logreg_new=pickle.load(f)
pred_value=logreg_new.predict(cr_x_test)
tab1=confusion_matrix(pred_value, cr_y_test)
tab1
from scipy.stats import ttest_1samp
cr.ApplicantIncome.mean()
cr.head()
result=ttest_1samp(cr.ApplicantIncome, 5550)
if result[1]>0.05:
    print('value is greater than  0.05:', result[1],'we fail to reject the null hypo')
else:
    print('value is lesser than 0.05:', result[1],'we reject the null hypo')<jupyter_output>value is lesser than 0.05: 0.040840382319724956 we reject the null hypo<jupyter_text>ANOVA<jupyter_code>from scipy.stats import f_oneway
restaurant=pd.read_csv("C:/Users/geeta/Pythonstuff/restuarnt.csv")
restaurant
f_oneway(restaurant.PauBaji, restaurant.Vada, restaurant.samosa)
cr.head()
f_oneway(cr.Education[cr.Education==1],cr.ApplicantIncome)
cr.Education[cr.Education==1]

f_oneway(cr.ApplicantIncome[cr.Education==0],cr.ApplicantIncome[cr.Education==1])
result=ttest_1samp(cr.ApplicantIncome[cr.Education==0], cr.ApplicantIncome.mean())
result
result1=ttest_1samp(cr.ApplicantIncome[cr.Education==1], cr.ApplicantIncome.mean())
result1
f_oneway(cr.ApplicantIncome[cr.Gender==0],cr.ApplicantIncome[cr.Gender==1])
f_oneway(cr.ApplicantIncome[cr.Married==0],cr.ApplicantIncome[cr.Married==1])
crr=pd.read_csv("C:/Users/geeta/Pythonstuff/CreditRisk.csv")
abc=pd.crosstab(cr.Loan_Status, cr.Credit_History)
abc
from scipy.stats import chi2_contingency
chi2_contingency(abc)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17405298341173558, 'fraction_numerical': 0.07526615498885862, 'mean_word_length': 9.049751243781095, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '97340', 'license': 'Unlicense', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1693, 'n_words': 197, 'path': 'logreg_1_credrisk.ipynb', 'repo_name': 'lurkmon/credit_risk_analysis', 'size': '4039'}