-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMLP3
85 lines (59 loc) · 2.61 KB
/
MLP3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from google.colab import files
uploaded = files.upload()
veriler = pd.read_csv("HousingData.csv")
veriler.head()
veriler.isnull().sum()
veriler.dtypes
veriler.corr()
plt.figure(figsize=(12, 12))
heatmap = sns.heatmap(veriler.corr(), vmin=-1, vmax=1, annot=True)
heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':12}, pad=12);
### **EKSİK VERİLERİMİZ VAR**
### ** Simple İMPUTER YÖNTEMİ**
x = veriler.iloc[:, :13].values # İlk 13 özellik sütununu X olarak seç
y = veriler.iloc[:, 13].values # MEDV sütununu y olarak seç
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
imputer.fit(x[:, :13])
x[:, :13] = imputer.transform(x[:, :13])
np.isnan(np.sum(x)) #BOŞ VERİ VAR MI SORDUK YOK
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x, y, test_size=0.33, random_state=42)
from sklearn import linear_model
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
from sklearn.metrics import explained_variance_score, mean_absolute_error, mean_squared_error
from sklearn.metrics import median_absolute_error, r2_score
print("R-Kare: ", r2_score(y_test, y_pred))
print("MAE: ", mean_absolute_error(y_test, y_pred))
print("MSE: ", mean_squared_error(y_test, y_pred))
print("MedAE: ", median_absolute_error(y_test, y_pred))
print("EVS: ", explained_variance_score(y_test, y_pred))
### **K EN YAKIN KOMŞU**
from sklearn.impute import KNNImputer
x_knn = veriler.iloc[:,:13].values
y = veriler.iloc[:,13].values
imputer = KNNImputer(n_neighbors=2,weights="uniform")
imputer.fit_transform(x_knn)
(x_knn==x).all() # BOŞLUK YOKSA FALSE
print("NaN var mı: ", pd.DataFrame(x_knn).isnull().values.any())
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x_knn, y, test_size=0.33, random_state=42)
from sklearn import linear_model
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
from sklearn.metrics import explained_variance_score, mean_absolute_error, mean_squared_error
from sklearn.metrics import median_absolute_error, r2_score
print("R-Kare: ", r2_score(y_test, y_pred))
print("MAE: ", mean_absolute_error(y_test, y_pred))
print("MSE: ", mean_squared_error(y_test, y_pred))
print("MedAE: ", median_absolute_error(y_test, y_pred))
print("EVS: ", explained_variance_score(y_test, y_pred))