<jupyter_start><jupyter_text>LDA with 1 Components (need to reduce from 2 to 1 to perform LDA)<jupyter_code>#Normalizing the features
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)

#Applying LDA
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
ldaObj = LDA(n_components=1)
X_train = ldaObj.fit_transform(X_train,y_train)
X_test = ldaObj.transform(X_test)
components_variance = ldaObj.explained_variance_ratio_

#Fitting Logistic Regression to Training Set
from sklearn.linear_model import LogisticRegression
classifierObj = LogisticRegression(random_state=0)
classifierObj.fit(X_train, y_train)

#Making predictions on the Test Set
y_pred = classifierObj.predict(X_test)

#Evaluating the predictions using a Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

from matplotlib.colors import ListedColormap
plt.scatter(X_test,y_test*0, c=y_pred, cmap = ListedColormap(('red', 'blue')))
plt.title('Logistic Regression (Test set)')
plt.xlabel('LDA')
plt.show()


cm
#Model Accuracy
print("Model Accuracy LDA 1 Components=", classifierObj.score(X_test,y_test))
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset = pd.read_csv('Master_File_Housing_Data_LogisticReg2.csv')

df= dataset.dropna(how='any', subset=['CONSTRUCTIONTYPE'])
df['BELOWGROUNDAREA'].fillna(0,inplace=True)

X = df.iloc[:,2:-2].values
y = df.iloc[:,14].values

from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values=np.nan, strategy='mean') 
imputer.fit(X[:,[1,3,5,6,7,8,10]])
X[:,[1,3,5,6,7,8,10]]= imputer.transform(X[:,[1,3,5,6,7,8,10]])

#print(X[0])
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder = LabelEncoder()
X[:, 0] = labelencoder.fit_transform(X[:, 0])
X[:, 9] = labelencoder.fit_transform(X[:, 9])

from sklearn.preprocessing import OneHotEncoder
onehotencoder = OneHotEncoder(categorical_features = [0,9])
data = onehotencoder.fit_transform(X).toarray()
#print(data[0])
NewData = data[:,[0,1,2,3,4,5,6,8,9,10,11,12,14,15,16,17,18,19,20,21,22,23,24,25]]

X_sig = NewData[:,[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,19,21,22,23]]
print(X_sig[0])

import statsmodels.api as sm

#Splitting the data into Training Set and Test Set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_sig,y,test_size=0.3,random_state=0)

#Applying LDA
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
ldaObj = LDA(n_components=None)
X_train = ldaObj.fit_transform(X_train,y_train)
X_test = ldaObj.transform(X_test)
components_variance = ldaObj.explained_variance_ratio_

#Fitting Logistic Regression to Training Set
from sklearn.linear_model import LogisticRegression
classifierObj = LogisticRegression(random_state=0)
classifierObj.fit(X_train, y_train)

#Making predictions on the Test Set
y_pred = classifierObj.predict(X_test)

#Evaluating the predictions using a Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

from matplotlib.colors import ListedColormap
plt.scatter(X_test,y_test*0, c=y_pred, cmap = ListedColormap(('red', 'blue')))
plt.title('Logistic Regression (Test set)')
plt.xlabel('LDA')
plt.show()
#Model Accuracy
print("Model Accuracy LDA None Components=", classifierObj.score(X_test,y_test))<jupyter_output>Model Accuracy LDA None Components= 0.6008206330597889
{'fraction_non_alphanumeric': 0.11935208866155157, 'fraction_numerical': 0.03949985791418016, 'mean_word_length': 8.361702127659575, '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': '256442', 'license': 'MIT', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1305, 'n_words': 267, 'path': 'LDA_LogisticReg.ipynb', 'repo_name': 'youavang/Minneapolis-Housing-Sale-Study', 'size': '3519'}