import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
def hpp():
dataset = pd.read_csv('C:\\Users\\user\\Desktop\\dataset.csv')
dataset['Price'] = dataset['Price'].replace({',': ''},
regex=True).astype(float)
print(dataset)
X = dataset[['Area', 'BHK', 'Age']]
y = dataset['Price']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
random_state=42)
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
plt.scatter(y_test, y_pred)
plt.plot([min(y_test), max(y_test)], [min(y_test), max(y_test)], color='red',
linestyle='--')
plt.title("Actual vs Predicted House Prices")
plt.xlabel("Actual Prices")
plt.ylabel("Predicted Prices")
plt.show()
print("\nDetails of Houses with Predicted Prices:")
test_data = X_test.copy()
test_data['Predicted Price'] = y_pred
test_data['Actual Price'] = y_test
print(test_data)
plt.figure(figsize=(8, 5))
plt.scatter(dataset['Age'], dataset['Price'], color='purple', alpha=0.5)
plt.title('Price vs Age of House')
plt.xlabel('Age of House (years)')
plt.ylabel('Price')
plt.show()
plt.figure(figsize=(8, 5))
plt.boxplot([dataset[dataset['BHK'] == i]['Price'] for i in range(1,
dataset['BHK'].max() + 1)], tick_labels=range(1, dataset['BHK'].max() + 1))
plt.title('Price Variation by Number of Bedrooms (BHK)')
plt.xlabel('Number of Bedrooms (BHK)')
plt.ylabel('Price')
plt.show()
def lpp():
np.random.seed(101)
HouseDF = pd.DataFrame()
HouseDF['Income'] = np.random.randint(20000, 120000, size=100)
HouseDF['Credit_Score'] = np.random.randint(300, 850, size=100)
HouseDF['Loan_Score'] = (HouseDF['Income'] / 120000) * 0.5 +
(HouseDF['Credit_Score'] / 850) * 0.5
X_loan = HouseDF[['Income', 'Credit_Score']]
y_loan = HouseDF['Loan_Score']
X_train_loan, X_test_loan, y_train_loan, y_test_loan = train_test_split(X_loan,
y_loan, test_size=0.3, random_state=101)
lin_model = LinearRegression()
lin_model.fit(X_train_loan, y_train_loan)
def check_loan_eligibility():
try:
income = float(input("Enter your annual income in rupees: "))
credit_score = float(input("Enter your credit score (300-850): "))
except ValueError:
print("Invalid input. Please enter numeric values for income and credit
score.")
return
user_data = pd.DataFrame([[income, credit_score]], columns=['Income',
'Credit_Score'])
prediction = lin_model.predict(user_data)
print(f"\nYour predicted loan score is: {prediction[0]:.2f}")
if prediction >= 0.5:
print("Congratulations! You are eligible for the loan.")
else:
print("Sorry, you are not eligible for the loan at this time.")
check_loan_eligibility()
while True:
print("Enter 1 to check for House Price Prediction")
print("Enter 2 to check for Loan Eligibility Prediction")
print("Enter 3 to Exit")
a=int(input(print("Enter your choice: ")))
if a == 1:
print("You chose House Price Prediction")
hpp()
elif a == 2:
print("You chose Loan Eligibility Prediction")
lpp()
elif a == 3:
print("Exiting the program.")
break
else:
print("Invalid Choice. Please try again.")