<jupyter_start><jupyter_text>Machine Algorithm for Predecting House Rates - Linear Regression<jupyter_code>## Importing Libraries for Data reading and Preprocessing
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
## Using Data set(CSV file) using Pandas Library

data = pd.read_csv('C:\\Users\\theja\\OneDrive\\Desktop\\Data_sets\\USA_Housing.csv')
data.head()
data.shape
data.describe()
data.info()
data.isna().sum()
data.corr()
## Ploting the Correlation Matrix
corrMatrix = data.corr()
sns.heatmap(corrMatrix, annot=True)
plt.show()
## spliting train_test_data set
X = data.iloc[:,:5]
print(X.head())
y = pd.DataFrame(data.iloc[:,-2])
print(y.head())
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import ShuffleSplit
X_train,X_test,y_train,y_test = train_test_split(X, y, test_size = 0.33, random_state = 42)
X_train.shape, X_test.shape, y_train.shape, y_test.shape, 
linear_model = LinearRegression()
linear_model.fit(X_train,y_train)
linear_model.intercept_
linear_model.coef_
y_pred = linear_model.predict(X_test)
y_pred = pd.DataFrame(y_pred, columns=['Y_pred'])
print(y_pred)
from sklearn.metrics import mean_squared_error
from math import sqrt
result = sqrt(mean_squared_error(y_pred,y_test))
print(result)
from sklearn.metrics import r2_score
r2_scores = r2_score(y_pred,y_test)
r2_scores<jupyter_output><empty_output><jupyter_text>Using Random_Forest<jupyter_code>from sklearn.ensemble import RandomForestRegressor
rand_model = RandomForestRegressor(random_state=101, n_estimators=150)
rand_model.fit(X_train,y_train)
rf_pred = rand_model.predict(X_test)
r2_score_rd = r2_score(rf_pred,y_test)
r2_score_rd<jupyter_output><empty_output><jupyter_text>Using XG Boost Regressor<jupyter_code>from xgboost import XGBRegressor
xg_boost = XGBRegressor(learning_rate=0.1, n_estimators=100, 
                    min_samples_split=2, min_samples_leaf=1, 
                    max_depth=3, subsample=1.0, random_state=101)

xg_boost.fit(X_train, y_train)
xg_boost_pred = xg_boost.predict(X_test)
r2_score_xg = r2_score(xg_boost_pred,y_test)
r2_score_xg<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10266847580280417, 'fraction_numerical': 0.016282225237449117, 'mean_word_length': 7.162361623616236, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '591460', 'license': 'Unlicense', 'n_tokens_mistral': 869, 'n_tokens_neox': 822, 'n_words': 150, 'path': 'Linear-Regression.ipynb', 'repo_name': 'Thejaswarreddy/ML_Algorithm_House_rent', 'size': '2211'}