Spaces:
Sleeping
Sleeping
Create model_training.py
Browse files- utils/model_training.py +16 -0
utils/model_training.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn.model_selection import train_test_split
|
| 2 |
+
from sklearn.linear_model import LogisticRegression
|
| 3 |
+
from sklearn.preprocessing import LabelEncoder
|
| 4 |
+
|
| 5 |
+
def encode_categorical(df):
|
| 6 |
+
label_encoder = LabelEncoder()
|
| 7 |
+
for col in df.columns:
|
| 8 |
+
if df[col].dtype == 'object':
|
| 9 |
+
df[col] = label_encoder.fit_transform(df[col])
|
| 10 |
+
return df
|
| 11 |
+
|
| 12 |
+
def train_and_evaluate(X_train, X_test, y_train, y_test):
|
| 13 |
+
model = LogisticRegression()
|
| 14 |
+
model.fit(X_train, y_train)
|
| 15 |
+
predictions = model.predict(X_test)
|
| 16 |
+
return predictions
|