Upload enunch_159.py
Browse files- enunch_159.py +51 -0
enunch_159.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""enunch.159
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1hjXMe2PUvW0yL5RwWXem47vZgBENHq-6
|
8 |
+
"""
|
9 |
+
|
10 |
+
import warnings
|
11 |
+
warnings.filterwarnings('ignore')
|
12 |
+
|
13 |
+
import pandas as pd
|
14 |
+
import numpy as np
|
15 |
+
import matplotlib.pyplot as plt
|
16 |
+
import seaborn as sns
|
17 |
+
from sklearn.model_selection import train_test_split
|
18 |
+
from sklearn.linear_model import LinearRegression
|
19 |
+
from sklearn.metrics import mean_squared_error, r2_score
|
20 |
+
|
21 |
+
file_path = '/content/House Price India.csv'
|
22 |
+
df = pd.read_csv(file_path)
|
23 |
+
|
24 |
+
df.head()
|
25 |
+
|
26 |
+
df.isnull().sum()
|
27 |
+
|
28 |
+
df['Date'] = pd.to_datetime(df['Date'], origin='1899-12-30', unit='D')
|
29 |
+
|
30 |
+
df.describe()
|
31 |
+
|
32 |
+
numeric_df = df.select_dtypes(include=[np.number])
|
33 |
+
plt.figure(figsize=(15, 10))
|
34 |
+
sns.heatmap(numeric_df.corr(), annot=True, cmap='coolwarm')
|
35 |
+
plt.title('Correlation Heatmap')
|
36 |
+
plt.show()
|
37 |
+
|
38 |
+
X = numeric_df.drop(columns=['Price'])
|
39 |
+
y = numeric_df['Price']
|
40 |
+
|
41 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
42 |
+
|
43 |
+
model = LinearRegression()
|
44 |
+
model.fit(X_train, y_train)
|
45 |
+
|
46 |
+
y_pred = model.predict(X_test)
|
47 |
+
|
48 |
+
mse = mean_squared_error(y_test, y_pred)
|
49 |
+
r2 = r2_score(y_test, y_pred)
|
50 |
+
print(f'Mean Squared Error: {mse}')
|
51 |
+
print(f'R-squared: {r2}')
|