Spaces:
Runtime error
Runtime error
Commit
•
56ebeed
1
Parent(s):
9785223
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
|
|
3 |
from sklearn.linear_model import LinearRegression, LogisticRegression
|
4 |
from sklearn.impute import SimpleImputer
|
5 |
from sklearn.preprocessing import LabelEncoder
|
|
|
6 |
|
7 |
# Streamlit başlığı
|
8 |
st.title("Data Corrector with AI")
|
@@ -35,7 +36,7 @@ if train_file and test_file:
|
|
35 |
is_null_train = train_df[train_df[column].isnull()]
|
36 |
|
37 |
if is_null_train.empty:
|
38 |
-
return train_df, test_df
|
39 |
|
40 |
if model_type == "numeric":
|
41 |
model = LinearRegression()
|
@@ -71,10 +72,16 @@ if train_file and test_file:
|
|
71 |
# Tahmin edilen değerlerle eksik değerleri doldurma
|
72 |
train_df.loc[train_df[column].isnull(), column] = predictions
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Aynı işlemi test verileri için yapma
|
75 |
X_test = test_df[test_df[column].isnull()].drop(columns=[column])
|
76 |
if X_test.empty:
|
77 |
-
return train_df, test_df
|
78 |
|
79 |
X_test = pd.get_dummies(X_test, drop_first=True)
|
80 |
X_test = X_test.reindex(columns=X_train.columns, fill_value=0)
|
@@ -86,12 +93,26 @@ if train_file and test_file:
|
|
86 |
|
87 |
test_df.loc[test_df[column].isnull(), column] = predictions
|
88 |
|
89 |
-
return train_df, test_df
|
|
|
|
|
90 |
|
91 |
for column in numeric_columns:
|
92 |
-
train_df, test_df = fill_missing_values(train_df, test_df, column, "numeric")
|
|
|
|
|
93 |
|
94 |
for column in categorical_columns:
|
95 |
-
train_df, test_df = fill_missing_values(train_df, test_df, column, "categorical")
|
|
|
|
|
96 |
|
97 |
st.write("Test Data with Predictions", test_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from sklearn.linear_model import LinearRegression, LogisticRegression
|
4 |
from sklearn.impute import SimpleImputer
|
5 |
from sklearn.preprocessing import LabelEncoder
|
6 |
+
from sklearn.metrics import r2_score, accuracy_score
|
7 |
|
8 |
# Streamlit başlığı
|
9 |
st.title("Data Corrector with AI")
|
|
|
36 |
is_null_train = train_df[train_df[column].isnull()]
|
37 |
|
38 |
if is_null_train.empty:
|
39 |
+
return train_df, test_df, None
|
40 |
|
41 |
if model_type == "numeric":
|
42 |
model = LinearRegression()
|
|
|
72 |
# Tahmin edilen değerlerle eksik değerleri doldurma
|
73 |
train_df.loc[train_df[column].isnull(), column] = predictions
|
74 |
|
75 |
+
# Model performansını değerlendirme
|
76 |
+
if model_type == "numeric":
|
77 |
+
performance = r2_score(y_train, model.predict(X_train))
|
78 |
+
else:
|
79 |
+
performance = accuracy_score(y_train, model.predict(X_train))
|
80 |
+
|
81 |
# Aynı işlemi test verileri için yapma
|
82 |
X_test = test_df[test_df[column].isnull()].drop(columns=[column])
|
83 |
if X_test.empty:
|
84 |
+
return train_df, test_df, performance
|
85 |
|
86 |
X_test = pd.get_dummies(X_test, drop_first=True)
|
87 |
X_test = X_test.reindex(columns=X_train.columns, fill_value=0)
|
|
|
93 |
|
94 |
test_df.loc[test_df[column].isnull(), column] = predictions
|
95 |
|
96 |
+
return train_df, test_df, performance
|
97 |
+
|
98 |
+
performances = []
|
99 |
|
100 |
for column in numeric_columns:
|
101 |
+
train_df, test_df, performance = fill_missing_values(train_df, test_df, column, "numeric")
|
102 |
+
if performance is not None:
|
103 |
+
performances.append((column, "numeric", performance))
|
104 |
|
105 |
for column in categorical_columns:
|
106 |
+
train_df, test_df, performance = fill_missing_values(train_df, test_df, column, "categorical")
|
107 |
+
if performance is not None:
|
108 |
+
performances.append((column, "categorical", performance))
|
109 |
|
110 |
st.write("Test Data with Predictions", test_df)
|
111 |
+
|
112 |
+
if performances:
|
113 |
+
st.write("Model Performance:")
|
114 |
+
for column, model_type, performance in performances:
|
115 |
+
if model_type == "numeric":
|
116 |
+
st.write(f"Column: {column}, Type: {model_type}, R^2 Score: {performance:.2f}")
|
117 |
+
else:
|
118 |
+
st.write(f"Column: {column}, Type: {model_type}, Accuracy Score: {performance:.2f}")
|