<jupyter_start><jupyter_text>Logistic Regression<jupyter_code># Response varaible should be a class label
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression,LinearRegression
from sklearn import metrics
from sklearn.metrics import classification_report
df=pd.read_csv("Housing_cut.csv")
df.head()
df.shape
X=df[['lotsize','bedrooms','bathrms','stories','garagepl']]
X.head()
Y=df['price']
degree=[0,1]
Y=pd.cut(Y,2,labels=degree)
k=np.extract(1,Y)
k.shape
#splitting into train and test
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)

#Build the regression model
lr=LogisticRegression()
#Train the model
lr.fit(X_train,Y_train)
#Apply the model
Y_pred=lr.predict(X_test)
print(Y_pred[1:5])
Y_pred=Y_pred.reshape(len(Y_pred),1)
print(Y_test)
#classification report
cm=metrics.confusion_matrix(Y_test,Y_pred)
print(cm)
a=metrics.accuracy_score(Y_test, Y_pred)
print(a*100)<jupyter_output>[[102   0]
 [  8   0]]
92.72727272727272
{'fraction_non_alphanumeric': 0.12441093308199812, 'fraction_numerical': 0.033930254476908575, 'mean_word_length': 8.654545454545454, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '151734', 'license': 'MIT', 'n_tokens_mistral': 431, 'n_tokens_neox': 411, 'n_words': 83, 'path': 'Sem4/DataAnalytics/DA Lab - students copy/Regression/LogisticR-Housing.ipynb', 'repo_name': 'nsudhanva/mca-code', 'size': '1061'}